BE_VOILIER/NicolasYarno/Mytimer.c

61 lines
1.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "stm32f10x.h"
void MyTimer_Base_Init (TIM_TypeDef * Timer , unsigned short ValARR , unsigned short ValPSC ){
Timer->ARR = ValARR;
Timer->PSC = ValPSC;
};
/*
TIM2_CH1
PWM mode 2 by writing OC1M=111 in the TIMx_CCMR1
he PWM mode can be selected independently on each channel (one PWM per OCx
output) by writing 110 (PWM mode 1) or 111 (PWM mode 2) in the OCxM bits in the
TIMx_CCMRx register. You must enable the corresponding preload register by setting the
OCxPE bit in the TIMx_CCMRx register, and eventually the auto-reload preload register (in
upcounting or center-aligned modes) by setting the ARPE bit in the TIMx_CR1 register
110: PWM mode 1 - In upcounting, channel 1 is active as long as TIMx_CNT<TIMx_CCR1
else inactive. In downcounting, channel 1 is inactive (OC1REF=0) as long as
TIMx_CNT>TIMx_CCR1 else active (OC1REF=1).
void MyTimer_PWM( TIM_TypeDef * Timer, char Channel){
Timer->CCMR1
};
*/
void (*pFnc) (void);
void MyTimer_ActiveIT (TIM_TypeDef * Timer , char prio, void (*IT_function)(void)){
Timer->DIER |= TIM_DIER_UIE;
IRQn_Type IRQn;
if (Timer == TIM2) IRQn = TIM2_IRQn;
else if (Timer == TIM3) IRQn = TIM3_IRQn;
else if (Timer == TIM4) IRQn = TIM4_IRQn;
NVIC_EnableIRQ(IRQn);
NVIC_SetPriority(IRQn, prio);
pFnc = IT_function;
};
void TIM2_IRQHandler(void){
if (pFnc != 0){
(*pFnc) (); /* appel indirect de la fonction */
}
TIM2->SR &= ~TIM_SR_UIF;
};
void TIM3_IRQHandler(void){
TIM3->SR &= ~TIM_SR_UIF;
};
void TIM4_IRQHandler(void){
TIM4->SR &= ~TIM_SR_UIF;
};