cancel
Showing results for 
Search instead for 
Did you mean: 

I need a timer to change its frequency every millisecond.I'm controlling a AC synchronous servo with pulse and direction in velocity mode(by changing the frequancy of the pulse) what is the ideal way

vsk.1
Associate II

I have stm32f4 discovery board(STM32F407VGT06) running at 168Mhz.

requirement 1)

i have to run a motor (AC synchronous servo - yaskawa ) by pulse and direction.

for which i can use a timer in PWM mode with 50% duty cycle.

relation of motor rotation to pulse

360' of motor shaft rotation = 360000 pulses input. (it counts only the number of rising edges)

so if i give pulses in frequancy of 360000 Hz then i drive the motor in

1 Rotation Per Second or 60 Rotations Per Minute.

My minimum speed of operation is 0.01 degree / sec. - 10 Hz ------(0.01 *(360000/360))

my maximum speed of operation is 10 degree / sec. -10000 Hz---- (10 *(360000/360))

requirement 2.

i calculate a new velocity every milli second, and i need to change my motor frequancy every millisecond.

what is the best way to do it?

tried 2 options and failed

pwm update ARR and CCR

(ARR is pre load register ) it updates on the next cycle .

updating PSC(prescalar)

instant but can't get lot of combinations

**option 3

use a timer interrupt in time base to toggle a GPIO output // could it work?

thanks in advance.

and forgive if this doubt is very silly.

expecting your help for my project.

vallab

7 REPLIES 7
chaaalyy
Senior II

I think, if you want to keep the duty cycle at always 50% ... Two lines of code to do so:

a) set up timer in pwm mode with prescaler, giving you the possibility to reach the frequencies, you want to reach

b) in your code (let´s assume, you use Timer 3, Channel 4 ....):

TIM3->ARR = xxxx (where xxxx represents the period , which gives you the frequency together with the prescaler. Don´t forget to work in Hex or to substract 1 in decimal)

TIM3->CCR4 = TIM3->ARR /2

but anyway: As far, as i know (correct me, if i´m wrong) the yaskawa-servo systems (older ones...) and every other controller, which relies on step/dir signals, have a minimum duration of the pulse and not a fixed duty cycle ... and at frequencies in 100s of kHz, this pulse duration will be very, very short ....

berendi
Principal

Set the timer channel to toggle mode instead of PWM and double the frequency. Set the ARR preload (ARPE) bit in CR1.

Then you can simply update ARR whenever you want.

And again something learned 🙂 tnx 🙂

duty cycle is not a important factor yaskawa servo drive can read upto 10 Mhz of input frequancy.

but. i am not able to achieve all the frequancy by just using fixed PSC or ARR, I might have to change both, But changing ARR which is shadow register changes after the next completion of CCR event(as per my understanding),

suggest me any other 3rd party pulse generators which i can communicate with UART and update frequancy every one milli second. (if using internal timer is not going to work out)

thanks for your response and sorry for the delayed reply

great tip. I'll try, but i have a doubt here. getting frequancy from 1000 Hz to 100000 Hz with resolution of 1000Hz i'm finding it difficult to calculate the ARR for each with fixed PSC sometimes i get ARR as float value.

suggest me any other 3rd party pulse generators also if any. if that works out better and easy

thanks for your response and sorry for delayed reply

Use one of the 32 bit timers for better accuracy.