cancel
Showing results for 
Search instead for 
Did you mean: 

Scheduling timers for motor control

sb_st
Senior

Hi!

I'm struggling to wrap my head around timers - I am trying to schedule some ADC reads of a current sense amplifier in a motor control setup.

I have three center-aligned PWM waveforms being generated by Timer1, which successfully commutate a BLDC motor. That's great. 

I would now like to schedule an ADC read once per PWM period. A simple first try at this would involve a single read right in the center of the PWM waveform. A slightly swankier version would be to calculate the largest duty cycle of my three PWM phases, and schedule my ADC read just after this point (but, again, just once per PWM period). 

I have experimented with configuring Timer1's TRGO to "Update Event", and scheduling my injected ADC read to be "Timer 1 Trigger Out Event". This, however, schedules the read at the beginning of the PWM period, rather than in the center of it. 

I'm also experimenting with setting up a slave timer - the idea being to trigger this secondary timer based on the above Timer1 TRGO trigger, and then being able to calculate a delay to either the center of the PWM waveform (Timer1 ARR) or after my largest PWM duty cycle (max(channel1, channel2, channel2) + offset). 

But this is where I'm getting confused - I can't quite wrap my head around how a slave timer behaves - I see One Pulse Mode, and each slave timer has its own PSC and ARR. There's a 'mode' parameter with options like "toggle on match", and a "Pulse" parameter which I think I understand to be the Capture Compare value for a given channel of the slave timer. I keep trying to modify these settings and scope the result on an oscilloscope, but I'm still having trouble building an intuitive understanding of what these parameters all mean. 

Would anyone be able to offer advice?

Thank you!

 

0 REPLIES 0