hello everyone
i wanna read an analog signal from A0 pin in arduino mega2560
when value is more than 60, wait 8 microseconds then digital pin no.3 ( for example ) be in HIGH state and after 16 microseconds it change to LOW state
in other words:
if signal from A0 value > 60 :
wait 8 microseconds
digitalWrite(3, HIGH)
wait 16 microsends
digitalWrite(3, LOW)
end
but i want to do it by interrupts using 16 bit timers NOT any delay or delayMicroseconds JUST BY INTERRUPTS USING 16 BIT TIMERS
hmdsmit: but i want to do it by 16 bit interrupts NOT any delay or delayMicroseconds JUST BY USING 16 BIT INTERRUPT
Do you mean that you want to use one of HardwareTImers to create the intervals rather than using delayMicroseconds() ?
That should be possible, but if what you are trying to avoid is the Arduino being blocked until the time interval expires then have a look at how millis() is used to manage timing without blocking in Several Things at a Time. You can use the same technique with micros()
What are your trying to achieve. What is the purpose of the pulse? What is reading the pulse?
Normally, analogRead() takes 110 microseconds, and the desire for tight digital pulse timing after the reading seems unusual.
sorry for bad typing
i mean just by interrupts using 16 bit timers
actually i want to have highest possible resolution for delay and it seems i have to use 16 bit timers interrupts in arduino mega2560
the purpose of pulse is being as a clock pulse to run another part of a circuit in the exact delay after something by highest possible resolution
in fact i wanna :
loop {
1 - when analog value from A0 goes upper than 60
2 - delay 7 microseconds
3 - digital pin no. 3 will be HIGH
4 - after 20 microsends digital pin no.3 will be LOW
}
but, it seems delaMicroseconds is not accurate enough
actually
this loop will repeats every one milisecond
Robin2:
Do you mean that you want to use one of HardwareTImers to create the intervals rather than using delayMicroseconds() ?
That should be possible, but if what you are trying to avoid is the Arduino being blocked until the time interval expires then have a look at how millis() is used to manage timing without blocking in Several Things at a Time. You can use the same technique with micros()
...R
hi
actually i want to have highest possible resolution for delay and it seems i have to use 16 bit timers interrupts in arduino mega2560
in fact i wanna :
loop {
1 - when analog value from A0 goes upper than 60
2 - delay 7 microseconds
3 - digital pin no. 3 will be HIGH
4 - after 20 microsends digital pin no.3 will be LOW
}
but, it seems delaMicroseconds is not accurate enough
actually
** this loop will repeats every one milisecond** thanks
Using the hardware Timers directly is considered to be beyond the needs of the beginners that the Arduino system is targeted at, However it is perfectly possible to program the Timers from an Arduino program as all the Atmega hardware registers are recognized.
The Atmel (now Microchip) datasheet for the Atmega 2560 has all of the details necessary to understand how to use the Timers.
If you are just concerned with an analog value exceeding a threshold the analog comparator may give you more precise timing than an analogRead(). Again, all the details are in the datasheet.