Making timers work on higher frequency

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 

Last Edited: Sat. Apr 18, 2020 - 09:43 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 what pwm frequency do you want for the motors and what is the measurement range for the ultrasonic sensor?

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

20KHZ and the range is 50cm MAX.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

They do have and I got the servo working as intended but the normal DC motors and the sensor do not work:/

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Write down your nominal motor PWM spec first...what range of duty cycles do you need  (ex: 5% to 80% tops), what PWM freq?  How many steps of adjustment is suitable?  is 10 steps from min to max plenty, or do you need 50? or 3000 steps?  Being flexible in one allows you to more easily meet the others.  Motors do not need a high pwm freq (as long as a hum is not objectionable).

 

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Thu. Apr 9, 2020 - 07:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

-> 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.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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