8 years, 1 month ago.

Nucleo sync ADC read with PWM

I'm working on controlling a motor using an ST Nucleo F411RE and want to measure the current. I would like to sync the reading of an ADC with my PWM period. I can't find any information on what timers are used for the PWM. Any help?

Edit: Looking more into the timers, it seems that I could manually set up a timer using the timer registers and create a IRQ callback function that reads the ADC. However, I'm still not sure if I'd be able to use the built-in PWM functionality or if I'd have to perform that manually. Any help?

There are a couple timing issues to look into. What is the frequency/period of your PWM? The ADC has an acquisition time. I don't know what it is, but you will need to make sure it is fast enough to do in some small fraction of the pwm period. You are going to have issues if the PWM duty is very low then your ADC conversion time is going to overlap with the pwm transition. Also, I don't know motors. PWM being a digital signal, what does the current through the motor look like when you hit it with a PWM? It is smooth or is there a big discontinuity?

posted by Graham S. 24 Oct 2016

So upon doing more research, I have figured out more specifically what I want to do. I would like to use a single timer at a rate of 20kHz to both control PWM and kick off a DMA sample of an ADC channel. The current will be a bit of a triangle wave due to the inductance of the motor, but my goal with having the measurement synced with the PWM is to get repeatable current data. My main control loop will only be running at 1kHz.

posted by M O 25 Oct 2016
Be the first to answer this question.