Mettre à jour 'Drivers/Sources/Driver_Timer.c'
This commit is contained in:
parent
9e9fc9eb4e
commit
da4f66ed73
1 changed files with 11 additions and 7 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
//-----------------------INITIALISATION TIMER---------------------//
|
||||
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer){
|
||||
|
||||
/* Activation de la clock liée au TIMER sélectionné */
|
||||
if(Timer->Timer == TIM1){
|
||||
//RCC->APB2ENR |= 0x0001<<11;
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
|
||||
|
@ -19,6 +21,7 @@ void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer){
|
|||
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
|
||||
}
|
||||
|
||||
/* Load des valeurs de l'ARR et du PSC */
|
||||
Timer->Timer->ARR = Timer->ARR;
|
||||
Timer->Timer->PSC = Timer->PSC;
|
||||
|
||||
|
@ -27,20 +30,21 @@ void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer){
|
|||
|
||||
//-----------------------START----------------------//
|
||||
void MyTimer_Base_Start(TIM_TypeDef * Timer){
|
||||
Timer->CR1 |= TIM_CR1_CEN; //Masque OU pour placer un 1 décalé avec des 0
|
||||
Timer->CR1 |= TIM_CR1_CEN; //* Masque OU pour placer un 1 décalé avec des 0 */
|
||||
}
|
||||
|
||||
//------------------------STOP----------------------//
|
||||
void MyTimer_Base_Stop(TIM_TypeDef * Timer){
|
||||
Timer->CR1 |= ~TIM_CR1_CEN; //Masque ET pour placer un 0 décalé avec des 1 (~)
|
||||
Timer->CR1 |= ~TIM_CR1_CEN; /* Masque ET pour placer un 0 décalé avec des 1 (~) */
|
||||
}
|
||||
|
||||
|
||||
void MyTimer_PWM( MyTimer_Struct_TypeDef * Timer, uint16_t cycle){
|
||||
Timer->Timer->CCMR1 &= ~TIM_CCMR1_OC1M_0; //Configuration du canal CH1
|
||||
Timer->Timer->CCMR1 |= TIM_CCMR1_OC1M_1| TIM_CCMR1_OC1M_2; // Ajouter 110 aux bits OC1M (registre CCMR1)
|
||||
|
||||
Timer->Timer->CCER |= TIM_CCER_CC1E; // Canal CH1 validé par bit CC1E (registre CCER)
|
||||
Timer->Timer->CR1 |= TIM_CR1_CEN; // Lancement du timer
|
||||
Timer->Timer->CCR1 = (cycle * Timer->ARR) / 100; // Fixer la durée à 20%
|
||||
Timer->Timer->CCMR1 &= ~TIM_CCMR1_OC1M_0; /* Configuration du canal CH1 */
|
||||
Timer->Timer->CCMR1 |= TIM_CCMR1_OC1M_1| TIM_CCMR1_OC1M_2; /* Ajouter 110 aux bits OC1M (registre CCMR1) */
|
||||
|
||||
Timer->Timer->CCER |= TIM_CCER_CC1E; /* Canal CH1 validé par bit CC1E (registre CCER) */
|
||||
Timer->Timer->CR1 |= TIM_CR1_CEN; /* Lancement du timer */
|
||||
Timer->Timer->CCR1 = (cycle * Timer->ARR) / 100; /* Fixer la durée à 20% */
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue