Generatig signal on timers...

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

Hello,

I need to produce signal presented below in picture.
I thought I could use two timers:

One timer for generating period of time for allowing second timer to give impulses of smaller period.

So one timer enables second timer.

I am writing this post because I have a feeling I could do this better. Do you think it could be possible to make such signal on only one timer.

Signal: small impulses (frequency 100kHz) turned on and off with frequency 200Hz.

What would be the best concept idea to do it?

Attachment(s): 

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

Quote:

I am writing this post because I have a feeling I could do this better. Do you think it could be possible to make such signal on only one timer.

Quote:

What would be the best concept idea to do it?

"Best" is always hard to answer. ;) What else does the AVR need to do?

There are a very few AVR8 models that have a "pulse count" feature in the timer subsystem. I cannot remember which they are. AT90PWMn?

A few AVR models have a "modulated carrier" feature. I don't know if that would help you or not. (And still requires two timers.) "Output Compare Modulator (OCM1C2)" in Mega64, for example.

Let's see--200Hz is 5ms. 2.5ms on; 2.5ms off. Not too bad. Your straightforward approach should work fine if the fast signal isn't too stringent with respect to runt pulses. (Looks a lot like the high-frequency industrial ultrasonic distance sensor app I worked on -- send some high-frequency bursts and look for the echo. But there I did one burst and measure; another burst then measure; ...)

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

An AND gate?

If you, for example, use a Mega16/32U4 you could do it with two timers and the output compare modulator.

If you use an XMegaXXE5 you could do it with XCL.

Or use an interrupt on the slow timer to enable/disable output on the fast timer.

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

Your 100kHz has a period of 10us
Your 200Hz has a period of 5ms. ie. 2500us high, 2500us low.

So you are going to have 250 cycles in each half-period.

So you could just count 250 interrupts, then toggle pin output mode.

Quite honestly, using one timer in CTC mode to produce the output. And a second timer to interrupt every 2.5ms. This would be far more efficient. i.e. you could run a regular program in the foreground.

David.

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

AT90PWMn datasheet shows a picture just like yours:

Quote:
16.8.3.1 Burst Generation
Note: On level mode, it’s possible to use PSC to generate burst by using Input Mode 3 or Mode 4 (See Figure 16-24. and Figure 16-25. for details.)

OCM in Mega64 family, Mega640 family, AT90USB family.

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

david.prentice wrote:

Quite honestly, using one timer in CTC mode to produce the output. And a second timer to interrupt every 2.5ms. This would be far more efficient. i.e. you could run a regular program in the foreground.

David.

Yes I will use 2 timers and second timer to interrupt. The only problem I see I will have to enable interrupts in my interrupt routine for switch debouncing.

And gate - yes that was my first thought - use and gate but this means adding additional component to the ciruit.

New microcontrollers have more and more options available. I need to make research. For my new projects I would love to have avr with PLD together in one chip.

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

Quote:

New microcontrollers have more and more options available. I need to make research. For my new projects I would love to have avr with PLD together in one chip.


I'm a bit confused. You seem to be dissatisfied with a "generic" AVR8 approach and two timers.

No comment about the AVR8 models that >>do<< have the OCM feature, and whether it might do your job?

No comment about the AVR8 AT90PWMn models that apparently have exactly the feature you need?

What exploration have you done into Xmegas? Does the XCL module have enough programmable logic for you? Do the timers have a burst feature? Can you put an entire period of the waveform into a DMA buffer and generate it that way?

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

Why not just one timer with overflow irq set to 100khz, count 250 interrupts, and toggle a flag. If the flag is set also toggle port bit. 250 times nothing happens, and 250 times a port bit flips with each IRQ?

jc

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

Quote:

Why not just one timer with overflow irq set to 100khz,

That wouldn't be very attractive to me in any "real" app as it requires an ISR service every 10us. So the AVR would be more or less need to be dedicated to the task. But if so, then why not just use two timers? Every (?) AVR8 model has at least two timers, right? ;) [checking on brain-dead models...indeed Tiny10 family has only one]

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

I have already used atmega88 to the current project so I will stay with CTC and two timers.

For future more advanced project I will definitely go with Xmega. I hope programming logic would not be difficult. I have never used them before.

Theusch, I am sure all your proposition would do the job and as I said before I have already used atmega88 and I don`t want to change circuit. Anyway thank you for your contribution. I can`t wait to start programming xmegas. It seems I will be able to skip PLDs if there will be enough logic for my needs.

Thank you all