Pages: [1]   Go Down
Author Topic: How to use analog interrupts?  (Read 324 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley 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.
Logged

Pages: [1]   Go Up
Jump to: