Go Down

Topic: How to use analog interrupts? (Read 531 times) previous topic - next topic

rokgin

Hello,

I am having trouble figuring out how to use an arduino analog interrupt program.

I want a program to execute a certain code, whenever the voltage on analog pin drops anywhere below 4V. The problem I'm having is that I want program to be able to execute that part of code even if it is already doing another function. The worst case scenario is to just set a digital pin on high when voltage is under 4V and set it back to low when it's over 4V, but like i said it is the worst case scenario since i could do that with external hardware logical gate and i would prefer to do it with arduino software. Would it be possible and if it is, how?

Thank you in advance.

johnwasser

Look in the ATmega328P datasheet for the ACSR: Analog Comparator Control and Status Register.  You would put 4V on the negative comparator input and your test voltage on the positive comparator input.  When the compare goes LOW the positive input has dropped below 4V.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

rokgin

Yes, I've seen this option mentioned somewhere, but this is well, a hardware solution and ideally I would like to be able to read the exact value of analog pin and output that to a display and as far as i understand by using analog comparator, all you get is a 1 or 0.

Nick Gammon

Take a look at: http://www.gammon.com.au/forum/?id=11916

That shows using the analog comparator.

You set up a reference voltage (eg. 4V in your case) on one pin and the comparator gives an interrupt on the rising, falling or both edges (on another pin).

Quote
I would like to be able to read the exact value of analog pin ...


It will be at or about the reference voltage. What else would it be?

Quote
I want a program to execute a certain code, whenever the voltage on analog pin drops anywhere below 4V


You can execute code but interrupt routines are supposed to be short.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

rokgin

Thank you both for your help, it is not exactly what i wanted, but that is the reason why i asked here since i couldn't find a possible way to do it using arduino  :) But i found a way to do exactly what i wanted using inverted schmitt trigger and another output straight to arduino analog input for the reading. But thank you anyway.

Go Up