This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

sample code for PWM Motor control with MCU CC25xx

Other Parts Discussed in Thread: DRV8801

Hi All,

I'm designing a motor controller for a DC brush motor.  I decided on the DRV8801 H-Bridge and the MCU is CC25xx. The hardware design is straight-forward. What I'm looking for is info on how to design the code for a PID loop controller using the PWM output of the CC25xx . The motor has a RPM sensor input on another PWM/ timer of the MCU. The RPM is the commanded input to the motor. I understand the approach but could use some help on the code.

Any suggestions and hints are helpful.

Thanks,

spincraft 

 

 

  • So what is the actual problem you have?

    Setting up the PWM output of one timer ?

    Getting something useful from the RPM sensor using the other timer ?

    Calculating the required values (the PID calculation)?

    For the first, look att he thread 'Resetting Timer A", which deals with generating the PWM output using CCR0 and CCRx register.

    The third, well, it heavily depends on the desired behaviour. Is it allowed to exceed the destination speed during regulation? Is a fast response required? Depending on what is allowed and what may not, the complexity of the calculation increases and the math is different. A complete PID requires much processor ressources and often isn't necessary.

    Reading the sensor for the current RPM will be the the easiest part and requires just two CCR registers of any timer (even the same as used for the PWM, if available and if the timer tick frequency is high enough). Anyway, what kind of sensor is it? A reed-relais? A photo diode with marker point? Or an electrical sensor, sensing the commutation ripple or something like that? The reed relais would be best, as it gives a sharp digital signal.

    I don't know the DRV8801. we use the VNH2SP30, which is for up to 20kHz PWM operation and up to 30A current. And we don't drive a motor, we drive a peltier element for cooling (or pre-heating) a laser, so the loopback is a temperature sensor and the loop reaction time is slooow - a real challenge for the PID.

**Attention** This is a public forum