Frequency generation

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

I want to create a frequency, 9kHz~110kHz.
It doesn't need to be 50/50 duty cycle.

I have played around with a Tiny861 and can get the frequency, but at the cost of resolution. I maybe get 5-6 bits in the desired range.
Ideally I would like to get 10-12 bits of resolution.

My second attempt was a slave AVR, a 2313 running at 20MHz.
I used the serial link in the 2313 to get the values from the 861, but the resolution is still too low.
In the 2313 I used a simple while loop with a NOP inside to create the pulses.

What ideas have you guys on this subject?

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

I would use PWM output from a 16 bit timer.

Its dead simple. Happens in the background so time jitter is very low. Only time the software even has to deal with it is when it is changed.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

To use simple numbers from 10kHz (100us period) to 100kHz (10us period) and an AVR running at 10MHz (100ns clock period):

Then you'd need 5000 timer counts at /1 for 10kHz, and 500 timer counts at 100kHz. That gives you over 4000 counts "range", or 12 bits of resolution. This is using CTC mode, 50% duty cycle, toggle pin on compare match.

No interrupts, no jitter during operation. If you interrupt on compare match and only change the match value there, then there should be no glitches, either.

If you need to vary the duty cycle then yes, use an AVR with a 16-bit timer with TOP of ICR1 to control the frequency and OCR1A to control the duty cycle. I cannot recall if Tiny861 has ANY 16-bit timers [datasheet excursion shows that it does, but not really suitable for what Jim and I are suggesting]. Tiny2313 Timer1 will work fine using Mode 14. AT90S2313 will not.

Those frequencies are low enough that one could construct the app with any old timer, but do yourself a favour and get a Mega48 or a few. ;)

Take a trip to see Jesper, too: http://www.myplace.nu/avr/minidds/

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Thanks,

My choice of AVR is not firm.
I will try this using Mega88.

I'll come back with the progress.

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

With a 20 MHz clock (e.g. Mega88 oder tiny2313) and a 16 bit timer one has nearly 200 cycels in a period at 110 kHz. This is close to 8 bit resolution.
The Tiny861 has a PLL to get up to 64 Mhz timer clock on timer 1. But this is only a 10 bit timer, so some extra programming my be needed.