![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
avec thread
Fork of T2_STM32 by
Revision 4:b01a3ce6ef01, committed 2018-01-14
- Comitter:
- ketingue
- Date:
- Sun Jan 14 17:39:09 2018 +0000
- Parent:
- 3:dfbd0ce2963a
- Commit message:
- test_pwm_01;
Changed in this revision
diff -r dfbd0ce2963a -r b01a3ce6ef01 Cylinder.h --- a/Cylinder.h Sun Jan 14 15:56:09 2018 +0000 +++ b/Cylinder.h Sun Jan 14 17:39:09 2018 +0000 @@ -97,10 +97,17 @@ } void Cylinder::Origin(int OriginSensor) { - digitalWrite(sdirPin, LOW); - analogWrite(sstepPin, 127); - while (digitalRead(sOriginSensor) == true); - analogWrite(sstepPin, 0); + + int periode = 100; + DigitalOut test_sortie_pwm(PD0); + SendPWM_Carre(periode, test_sortie_pwm) + while(DigitalOut(OriginSensor)==true); + SendPWM_Nul(test_sortie_pwm); + //digitalWrite(sdirPin, LOW); + //analogWrite(sstepPin, 127); + //while (digitalRead(sOriginSensor) == true); + //analogWrite(sstepPin, 0); + */ } #endif \ No newline at end of file
diff -r dfbd0ce2963a -r b01a3ce6ef01 StepperMotor.h --- a/StepperMotor.h Sun Jan 14 15:56:09 2018 +0000 +++ b/StepperMotor.h Sun Jan 14 17:39:09 2018 +0000 @@ -29,7 +29,7 @@ sPos_Max = Pos_Max; DigitalOut sstepin(sStepPin); DigitalOut sdirPin(sDirPin); - DigitalIn soriginsensor(sOriginSensor); + DigitalIn sOriginSensor(OriginSensor); } StepperMotor::~StepperMotor(void){
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;