Author

Message

Last Edited: Sat. Apr 18, 2020 - 09:43 AM

Your counters may not have a large enough prescale or enough counter bits to carry out the servo timing with a 12MHz clock. Have you checked whether or not this is the case?

Jim

20KHZ and the range is 50cm MAX.

20kHz with 8bit pwm would not have worked on 1MHz - do the math. 20000 * 256 * prescaler = ?

What prescale options do you have?

What is 50cm in time?

My bad there on the PWM freq,it is 20KHZ max PWM I want since that is the max my driver can function at.I did not dive into this too much since I tried with no prescaler from the start and it worked.And by my calculations that would mean the driver would work around 3KHZ.

As prescaling options for the 8bit timers I have:

About the distance in time you mean the formula used by the sensor?

Last Edited: Thu. Apr 9, 2020 - 07:29 AM

Last Edited: Thu. Apr 9, 2020 - 07:30 AM

A prescale of 64 will probably work for your motors - gives a 700Hz pwm freq approx

Your sensor has no idea of distance or time - it is up to your code to measure the time then convert that into a distance. So you need to determine what range and resolution of time you require.

The specs I am looking for are:

-> 1% to 100% duty cycle range

-> 20 steps of adjustment

-> based on the datasheet formula for 12MHZ and a prescaler of 8 i get a PWM frequency of 5859.375

-> based on the datasheet formula for 12MHZ and a prescaler of 8 i get a PWM frequency of 5859.375

Well, that is not *quite *correct. Your calculation is good...however.

The max number of counts is something **you **set...this controls the number of counts you can have per cycle, the step size, and the PWM freq.

It just so happens an 8 bit PWM has a max setting limit of 255....but you can use 23, 98, 157, 222 or whatever you like as your max (up to 255). Thereafter, you can adjust the pwm duty value from 0 (0%) up to the max (100%) that you determined*.

A lower max, means a lower freq divider, allowing higher PWM freqs to be generated. You might also use your own max so you can generate some __exact __ratios, that you can't get using 255.

* well not exactly, most (if not all) avrs limit you to not *quite *going to 0% (full off) or not *quite *to 100% (full on), within 1 tick...you **must **choose one limit or the other. There are workaround "tricks" to get the full range.

Last Edited: Thu. Apr 9, 2020 - 09:27 AM