Actualiser Pilotes/Source/PWM.c
This commit is contained in:
parent
0f0531465b
commit
df0723ffda
1 changed files with 112 additions and 108 deletions
|
|
@ -11,7 +11,7 @@ void MyTimer_PWM(TIM_TypeDef * Timer , int Channel){
|
|||
|
||||
if (Channel == 1){
|
||||
Timer->CCMR1 &= ~(0b111<<4); //On clear les trois bits qui sont de pwm
|
||||
Timer->CCMR1 |= (pwrmd<<4); //On affecte le powermode au bits de lecture pour le µ-controlleur
|
||||
Timer->CCMR1 |= (pwrmd<<4); //On affecte le powermode au bits de lecture pour le µ-controlleur
|
||||
Timer->CCMR1 |= TIM_CCMR1_OC1PE; //Update preload, il n'affecte pas le valeur avant que la prochaine cycle
|
||||
Timer->CCER = TIM_CCER_CC1E; //Enable le pin voulu basculer
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ void MyTimer_PWM(TIM_TypeDef * Timer , int Channel){
|
|||
}
|
||||
|
||||
//En dessous d'ici, on a l'aide du plus gentil chat que je connais
|
||||
// Enable auto-reload preload -- //Ensures that your initial configuration — PWM mode, duty cycle, period — actually takes effect before the timer starts counting.
|
||||
// Enable auto-reload preload -- //Ensures that your initial configuration — PWM mode, duty cycle, period — actually takes effect before the timer starts counting.
|
||||
Timer->CR1 |= TIM_CR1_ARPE;
|
||||
// Force update event to load ARR and CCR values immediately
|
||||
Timer->EGR |= TIM_EGR_UG;
|
||||
|
|
@ -75,9 +75,13 @@ int Set_DutyCycle_PWM(TIM_TypeDef *Timer, int Channel, int DutyC){
|
|||
int CCR_VAL = (Timer -> ARR + 1) * DutyC / 100;
|
||||
switch (Channel){
|
||||
case 1: Timer->CCR1 = CCR_VAL;
|
||||
break;
|
||||
case 2: Timer->CCR2 = CCR_VAL;
|
||||
break;
|
||||
case 3: Timer->CCR3 = CCR_VAL;
|
||||
break;
|
||||
case 4: Timer->CCR4 = CCR_VAL;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue