CELIS/HARDWARE/TIMER/timer.c

69 lines
2.4 KiB
C
Raw Normal View History

#include "SEN_DCUMessage.h"
#include "timer.h"
#include "led.h"
#include "SecTimer.h"
//////////////////////////////////////////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
//ALIENTEKս<4B><D5BD>STM32<33><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><>ʱ<EFBFBD><CAB1> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
//<2F>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>:2012/9/3
//<2F><EFBFBD><E6B1BE>V1.0
//<2F><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
//Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2009-2019
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
//ͨ<>ö<EFBFBD>ʱ<EFBFBD><CAB1>3<EFBFBD>жϳ<D0B6>ʼ<EFBFBD><CABC>
//<2F><><EFBFBD><EFBFBD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><EFBFBD><EFBFBD>Tout=<3D><>500*7200<30><30>/72=500 000us
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʱʱ<CAB1><CAB1>
void TIM3_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //ʱ<><CAB1>ʹ<EFBFBD><CAB9>
//<2F><>ʱ<EFBFBD><CAB1>TIM3<4D><33>ʼ<EFBFBD><CABC>
TIM_TimeBaseStructure.TIM_Period = arr; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>װ<EFBFBD><D7B0><EFBFBD><EFBFBD><EEB6AF><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>װ<EFBFBD>ؼĴ<D8BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ֵ
TIM_TimeBaseStructure.TIM_Prescaler =psc; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪTIMxʱ<78><CAB1>Ƶ<EFBFBD>ʳ<EFBFBD><CAB3><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4>Ƶֵ
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD>ӷָ<D3B7>:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM<49><4D><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD>ģʽ
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>TIMx<4D><78>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE ); //ʹ<><CAB9>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>TIM3<4D>ж<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>NVIC<49><43><EFBFBD><EFBFBD>
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3<4D>ж<EFBFBD>
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>0<EFBFBD><30>
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3<EFBFBD><33>
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ<51><CDA8><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
NVIC_Init(&NVIC_InitStructure); //<2F><>ʼ<EFBFBD><CABC>NVIC<49>Ĵ<EFBFBD><C4B4><EFBFBD>
TIM_Cmd(TIM3, ENABLE); //ʹ<><CAB9>TIMx
}
//<2F><>ʱ<EFBFBD><CAB1>3<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
extern int8_t WULING_DCDCSendBms2(void);
void TIM3_IRQHandler(void) //TIM3<4D>ж<EFBFBD>
{
if(TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //<2F><><EFBFBD><EFBFBD>TIM3<4D><33><EFBFBD><EFBFBD><EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
// Loop_Send.CanData();
TimSend();
TIM_ClearITPendingBit(TIM3, TIM_IT_Update ); //<2F><><EFBFBD><EFBFBD>TIMx<4D><78><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־
}
}