quentin godbert
/
t2-stm32_thread
avec thread
Fork of T2_STM32 by
Diff: pwm.h
- Revision:
- 4:b01a3ce6ef01
- Parent:
- 2:ab0ccf9bb38c
diff -r dfbd0ce2963a -r b01a3ce6ef01 pwm.h --- a/pwm.h Sun Jan 14 15:56:09 2018 +0000 +++ b/pwm.h Sun Jan 14 17:39:09 2018 +0000 @@ -6,12 +6,45 @@ DigitalOut myled(LED1); -int main() { + +void InitializeTimer(int period = 500) +{ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); + + TIM_TimeBaseInitTypeDef timerInitStructure; + timerInitStructure.TIM_Prescaler = 40000; + timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up; + timerInitStructure.TIM_Period = period; + timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; + timerInitStructure.TIM_RepetitionCounter = 0; + TIM_TimeBaseInit(TIM4, &timerInitStructure); + TIM_Cmd(TIM4, ENABLE); +} + + +void SendPWM_Carre(int temps, PinName pin) { - mypwm.period_ms(10); - mypwm.pulsewidth_ms(1); + int middle-temps = roundUp_uint32(temps); + PwmOut pwm(pin); + pwm.period_ms(temps); + pwm.pulsewidth_ms(middle-temps); - printf("pwm set to %.2f %%\n", mypwm.read() * 100); + printf("pwm set to %.2f %%\n", pwm.read() * 100); + + while(1) { + myled = !myled; + wait(1); + } + +void SendPWM_Nul(PinName pin) { + + + PwmOut pwm(pin); + + pwm.period_ms(0); + pwm.pulsewidth_ms(0); + + printf("pwm set to 0 \n"); while(1) { myled = !myled;