External Interrupt

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

Hy all,

I use external interrupt to measure the frequency of an astable multivibrator (with ne555). Now I'd like to reach, that one of the output of the AVR shows the square wave, what exactly the ne555 make, but with a time delay in function of the frequency. (If the freq for example 600Hz, the output squarewave also 600Hz, but with 10ms delay). I use Attiny2313. Can somebody help me how to start?

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

Well it's not the same 600Hz signal that you'll use. So you need to set up an AVR timer to produce 600Hz when requested. You will probably use CTC mode (and prescaling) to achieve the exact/close frequency. Turn it on/off either by just setting the COM bits or actually turning the timer on/off completely with the CS bits.

Meanwhile you need some way to monitor the input signal to know when it is "active". You could use a transition interrupt (PCINT/INTn) to do this or you could use ICP to tell when the signals starts to be active. When it starts to clock start a timer and wait for 10ms then switch the output timer on. When the input signal stops activity equally set a timer (probably the same one as before) and when it expires turn the output signal off.

I'm intrigued - why would you want to do this - what's the actual real-world application of such a thing?

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

You would use input capture and output compare of one of the timers. When you get an input capture event, add the required time delay and setup up an output compare. Things get a little trickier if the frequency varies and you want to maintain a constant phase angle. This is usually done for 'intercepters' for fuel injection systems to modify the ignition timing.

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

In the example given, the delay is considerably more than the period.
Is that what you want?
To follow the waveform in the most straightforward fashion
would require storing a queue of future times at which to change the output pin.
Depending on the cpu frequency, you might have to wait a few timer overflows before the first output change.

Is the period of the 555 reasonably stable for 10 ms?
In that case, you might want to replace the first delay by period + delay mod period.
After that, use the formula out[j+1]=out[j]+in[j+1]-in[j].
Unsigned arithmetic will do the right thing.
Keeping track of the data might be interesting.

Iluvatar is the better part of Valar.