17 Eylül 2017 Pazar

Motor Speed Control

We can further enhance the simple motor control example by adding speed control using PWM.

Proteus: RA0 is used for ADC input, RC1 is for PWM output (it may differ to PIC model used). RC0 and RC2 will control the motor direction. We added a scope to observe PWM signal. PWM output is connected to ENABLE port of the motor to control the speed.


MCC: add CCP2, TMR2 and ADC peripherals. CCP2 uses TMR2. Select PWM mode.








XC8: first set motor rotation direction using RC0, RC2 ports. Now, you can adjust the speed within while loop; read ADC, get the value change the duty cycle.


    IO_RC0_SetHigh();
    IO_RC2_SetLow();

    while (1)
    {
        // Add your application code
        ADC_StartConversion();
        while(!ADC_IsConversionDone());
        c=ADC_GetConversionResult();
        PWM2_LoadDutyValue(c);

    }
}



Hiç yorum yok:

Yorum Gönder