diff --git a/ProjetsKEIL/Drivers/timerdriver.c b/ProjetsKEIL/Drivers/timerdriver.c index ee3c198..0dd11ca 100644 --- a/ProjetsKEIL/Drivers/timerdriver.c +++ b/ProjetsKEIL/Drivers/timerdriver.c @@ -1,5 +1,4 @@ #include "timerdriver.h" -#include "gpiodriver.h" void (* pFnc) (void); /* déclaration d’un pointeur de fonction */ @@ -53,6 +52,32 @@ void MyTimer_PWM_Init(MyPWM_Struct_TypeDef * PWM) PWM->Timer->CCER |= (1<<4*(PWM->channel-1)); //enable capture/compare registers } +MyGPIO_Struct_TypeDef GPIOFromPWM(MyPWM_Struct_TypeDef PWM) +{ + //use of C99 compound literal for return statement, may not work on C90. + if(PWM.Timer == TIM2) + { + //PA0 -> TIM2,CH1... iteration + return (MyGPIO_Struct_TypeDef){GPIOA,PWM.channel-1,AltOut_Ppull}; + } + else if(PWM.Timer == TIM3) + { + if(PWM.channel > 2) { + return (MyGPIO_Struct_TypeDef){GPIOB,PWM.channel-3,AltOut_Ppull}; //PB0 -> TIM3,CH3;PB1 -> TIM3,CH4 + } + else { + return (MyGPIO_Struct_TypeDef){GPIOA,PWM.channel+5,AltOut_Ppull}; //PA6 -> TIM3,CH1;PA7 -> TIM3,CH2 + } + } + else if(PWM.Timer == TIM4) + { + return (MyGPIO_Struct_TypeDef){GPIOB,PWM.channel+5,AltOut_Ppull}; //PB6 -> TIM4,CH1... iteration + } + else { //TIM1 case + return (MyGPIO_Struct_TypeDef){GPIOA,PWM.channel+7,AltOut_Ppull};//PA8 -> TIM1,CH1... iteration + } +} + int TimerX2Int(TIM_TypeDef * TimerX) { if(TimerX == TIM1) diff --git a/ProjetsKEIL/Drivers/timerdriver.h b/ProjetsKEIL/Drivers/timerdriver.h index ccbcc95..261309c 100644 --- a/ProjetsKEIL/Drivers/timerdriver.h +++ b/ProjetsKEIL/Drivers/timerdriver.h @@ -1,6 +1,7 @@ #ifndef TIMERDRIVER_H #define TIMERDRIVER_H #include "stm32f10x.h" +#include "gpiodriver.h" #define CEN 0x0 #define UIE 0x0 @@ -28,6 +29,7 @@ uint8_t TimerIT2UInt(TIM_TypeDef * TimerX); void MyTimer_ActiveIT(TIM_TypeDef * TimerX, uint8_t Prio); void Init_Periph (void (* ptrFonction)(void)); void MyTimer_PWM_Init(MyPWM_Struct_TypeDef * PWM); +MyGPIO_Struct_TypeDef GPIOFromPWM(MyPWM_Struct_TypeDef PWM); #define MyTimer_Base_Start(Timer) (Timer->CR1 |= (0x01<CR1 &= ~(0x01<CCMR1 |= (0x6<<12); - //TIM2->BDTR |= (1<CCR2 = 10; - //TIM2->CCER |= (1<<4); //0 pour CC1E, 4 pour CC2E // 4*(channel-1) + MyPWM_Struct_TypeDef PWMTIM2 = {TIM2,3,400}; //creation of PWM + MyTimer_PWM_Init(&PWMTIM2); //Init useful registers + MyGPIO_Struct_TypeDef gpioPWMTIM2 = GPIOFromPWM(PWMTIM2); //Returns the GPIO from the given PWM (Timer + Channel) + MyGPIO_Init(&gpioPWMTIM2); //Init the GPIO + MyPWM_Base_Start(TIM2); //STart the TIMER + do{ }while(1) ; diff --git a/ProjetsKEIL/timer_interruption/timer_interruption.uvoptx b/ProjetsKEIL/timer_interruption/timer_interruption.uvoptx index 519fefc..7ffffc4 100644 --- a/ProjetsKEIL/timer_interruption/timer_interruption.uvoptx +++ b/ProjetsKEIL/timer_interruption/timer_interruption.uvoptx @@ -125,7 +125,7 @@ 0 DLGDARM - (1010=895,198,1271,755,1)(1007=105,137,292,412,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=498,100,919,527,1)(121=491,538,912,965,1)(122=875,109,1296,536,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=105,137,504,482,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=1175,164,1769,915,1)(132=1172,171,1766,922,1)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) + (1010=895,198,1271,755,1)(1007=105,137,292,412,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=771,85,1192,512,1)(121=791,523,1212,950,1)(122=875,109,1296,536,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=105,137,504,482,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=1175,164,1769,915,1)(132=1172,171,1766,922,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) 0