ATmega pulse generator...

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

Hi,

I need to generate pulse trains using a ATmega328 or similar - I have made up some carrier boards so I can play with these on a breadboard. Frequency is quite low - basic requirements are

    mark: 20uS - 100mS (20uS to 1mS, 1mS steps thereafter)
    space: 1mS - 10S (1mS steps to 100mS, 10mS steps to 1S, 100mS steps thereafter)

Precision is not at the top of the list. Should I do this my fiddling with the timer settings, or have a free-running timer with reasonably fine granularity and toggle a bit as required? I'll be adjusting either the mark or space using a rotary encoder.

The maths for this sort of thing should be pretty straight forward, and I would have thought that there would be example GCC code out there, but I could not locate any...

Thanks for any input you can provide...

Cheers

Nick

Nicko

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

This is really just PWM with a variable TOP.

Regards,
Steve A.

The Board helps those that help themselves.

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

There was a fairly extensive thread on this a while back. I can't remember good key words but try searching it out.

LOL _ found it. It was when you asked the same question six months ago...
https://www.avrfreaks.net/index.p...

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

In addition to Steve's suggestion, note that the maximum the PWM bits used, the maximum the analysis (steps), but lower frequency.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

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

Will every combination of mark and space be allowed? I ask because 20us resolution over 10 seconds is 1:500000, meaning it can't be done nicely with a 16-bit timer. That is by no means saying it can't be done at all, just that you'd have to get a bit more clever. But if you can guarantee that the mark/space ratio will never be more than 65k it gets easier.

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

theusch wrote:
There was a fairly extensive thread on this a while back. I can't remember good key words but try searching it out.

LOL _ found it. It was when you asked the same question six months ago...
https://www.avrfreaks.net/index.p...


Mea culpa. I obviously had brain fade due to far too many celebrations over the last few days and zero recovery time. Need more sleep!

Nicko

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

I like the part where we redesign the whole project once we get the explanation of what it is really supposed to do. Ready to give us the Big Picture? Might get some out of the box ideas.

Imagecraft compiler user

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

bobgardner wrote:
I like the part where we redesign the whole project once we get the explanation of what it is really supposed to do. Ready to give us the Big Picture? Might get some out of the box ideas.

No, it really is that boring. I need to generate a pulse train with variable mark vs. space. Some twiddles go in where rather than explicitely specify mark or space time, you get to specify frequency, where the m/s ratio is fixed but the frequency set, or you get to specify the m/s ratio, but the frequency stays the same. The problem boiled down to the best way to explicitly set mark & space - the rest follows from that.

So, the AVR is not doing a whole bunch of interesting stuff - driver a rotary encoder, a few buttons, an OLED display, and generates a resulting pulse train - that's about it.

I need more paracetamol & sleep....

Nicko