diff --git a/Drivers/Inc/TIMER.h b/Drivers/Inc/TIMER.h index 235b60b..57bfb3c 100644 --- a/Drivers/Inc/TIMER.h +++ b/Drivers/Inc/TIMER.h @@ -31,6 +31,12 @@ void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void) #define MyTimer_Base_Start(Timer) (Timer->CR1 |= 0x01) #define MyTimer_Base_Stop(Timer) (Timer->CR1 &= ~0x01) +#define PWM_output 0x00 +#define PWM_inputTI1 0x01 +#define PWM_inputTI2 0x10 +#define PWM_inputTRC 0x11 +void MyPWM_init ( TIM_TypeDef * Timer,char Channel); +void MyPWM_Duty (TIM_TypeDef * Timer,char Channel, unsigned short CRR ); #endif diff --git a/Drivers/Src/TIMER.c b/Drivers/Src/TIMER.c index 7b9f22b..7c68ef5 100644 --- a/Drivers/Src/TIMER.c +++ b/Drivers/Src/TIMER.c @@ -29,6 +29,60 @@ void MyTimer_Base_Init ( MyTimer_Struct_TypeDef * Timer) Timer->Timer->PSC=Timer->PSC; } +void MyPWM_init ( TIM_TypeDef * Timer,char Channel) +{ + if(Channel==1) + { + Timer->CCMR1&=~0x00FF; + Timer->CCMR1|=0x11<<5; + Timer->CCMR1&=~0x000F; + + } + if(Channel==2) + { + Timer->CCMR1&=~0xFF00; + Timer->CCMR1|=0x11<<12; + Timer->CCMR1&=~0x0F00; + + } + if(Channel==3) + { + Timer->CCMR2&=~0x00FF; + Timer->CCMR2|=0x11<<5; + Timer->CCMR2&=~0x000F; + + } + if(Channel==4) + { + Timer->CCMR2&=~0xFF00; + Timer->CCMR2|=0x11<<12; + Timer->CCMR2&=~0x0F00; + + } +} +void MyPWM_Duty (TIM_TypeDef * Timer,char Channel, unsigned short CRR ) +{ + + + if(Channel==1) + { + Timer->CCR1=CRR; + } + if(Channel==2) + { + Timer->CCR2=CRR; + } + if(Channel==3) + { + Timer->CCR3=CRR; + + } + if(Channel==4) + { + Timer->CCR4=CRR; + } + +} void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void)) { int num_tim; diff --git a/Projet_DevDrivers/Sources/Principal.c b/Projet_DevDrivers/Sources/Principal.c index 1cd5850..ee1f527 100644 --- a/Projet_DevDrivers/Sources/Principal.c +++ b/Projet_DevDrivers/Sources/Principal.c @@ -23,6 +23,9 @@ int main ( void ) MyTimer_Base_Init(&timer2); MyTimer_ActiveIT(timer2.Timer,1, &Mafonction_IT); MyTimer_Base_Start(timer2.Timer); + MyPWM_init (TIM2,1); + MyPWM_Duty (TIM2,1, 10000); + while(1) { diff --git a/Projet_DevDrivers/TP1.uvoptx b/Projet_DevDrivers/TP1.uvoptx index 6d8b9ef..4020d24 100644 --- a/Projet_DevDrivers/TP1.uvoptx +++ b/Projet_DevDrivers/TP1.uvoptx @@ -103,7 +103,7 @@ 1 0 0 - 0 + 6 @@ -114,7 +114,7 @@ - BIN\UL2CM3.DLL + STLink\ST-LINKIII-KEIL_SWO.dll @@ -410,7 +410,7 @@ 1 2 1 - 0 + 1 0 0 ..\DRIVERS\Src\GPIO.c diff --git a/Projet_DevDrivers/TP1.uvprojx b/Projet_DevDrivers/TP1.uvprojx index dcb8b2b..fe727e7 100644 --- a/Projet_DevDrivers/TP1.uvprojx +++ b/Projet_DevDrivers/TP1.uvprojx @@ -134,11 +134,11 @@ 0 1 1 - -1 + 4096 1 BIN\UL2CM3.DLL - + "" () @@ -339,7 +339,7 @@ - .\Includes;..\Drivers\Inc + ..\Drivers\Inc