Pages: 1 [2]   Go Down
Author Topic: How to generate an interrupt from an analog signal  (Read 3034 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 517
Posts: 26272
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes.
Keep in mind that you will draw current thru those parts (5V/4K = 1.25mA), so go higher if you can and if battery consumption is an issue.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, CrossRoads! I think I have it now.

I made up an example based on your suggestions. Full description here:

http://www.gammon.com.au/forum/?id=11011

This screenshot shows the way that the op-amp "cleans up" the analog signal into a digital one:



This sketch takes the output from the op-amp and flashes the on-board LED when the light level goes over a certain amount, completely done by interrupts:

Code:
// Example of flashing pin 13 based on the value on pin 2, when an interrupt occurs

// Author: Nick Gammon
// Date: 27 March 2011

// interrupt service routine
void light_change ()
{
  digitalWrite (13, digitalRead (2)); 
}

void setup()
{
  pinMode(13, OUTPUT); 
  attachInterrupt(0, light_change, CHANGE);
}  // end of setup

void loop()
{

  // all done by interrupts
 
}  // end of loop
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 517
Posts: 26272
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice writeup Nick. Nicely done.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks!
Logged

Georgina Ontario
Offline Offline
Sr. Member
****
Karma: 5
Posts: 437
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Crossroads:

Thank you for the tip. It was exactly what I was looking for.

My CAD package is just too cumbersome for these quick one-off things -- and no PCB house interface.

This looks great. Schematics, PCB layout, simple and fast.

Logged

Just another Hacker

SW Colorado
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks to you guys!

I'll be trying it out myself.

Doug
Logged

0
Offline Offline
Full Member
***
Karma: 5
Posts: 231
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Doug,

Maybe it was just me, but I let the smoke out a couple of Op Amps when I was starting off.  Remember most Op Amps are cheap so get some Op Amps and breadboard some of these circuits up and if you let some smoke out just think of the loss as a very low cost tuition.  The main thing is to get in and do something as that is where the learning starts.

wade

Logged

SW Colorado
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...... if you let some smoke out just think of the loss as a very low cost tuition.  The main thing is to get in and do something as that is where the learning starts.

Wade,
Ya, but what do I tell my wife when she says she smells something.....?

Thanks for the advice - am getting some op amps tomorrow!

Doug
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 517
Posts: 26272
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"what do I tell my wife when she says she smells something "

must have been the dog ...
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

SW Colorado
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You guys are great - thanks!!

Next question......!

Can an interrupt interrupt an interrupt.......?  Got it?

Once I have an interrupt that starts my solenoid pulsing to clear the food, I'd like it to continue until the food is flowing again.  But since I'm interrupting based on a RISING photosensor signal, it can't see when it's falling.  I thought I could use another interrupt (pin 3) looking at the same signal but looking for FALLING, but that doesn't seem to work - it doesn't stop the RISING interrupt and it acts kinda weird.  Is there a better way?

Thanks again

Doug
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 517
Posts: 26272
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ideally your first interrupt will merely set a flag to kick off the pulsing - that interrupt could then be disabled until the Falling interrupt occurs, which could then re-able Rising interrupts.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Do a CHANGE interrupt?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 517
Posts: 26272
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd think you'd want to have some time built in to ensure the jam had a chance to actually clear out some before turning it off.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: 1 [2]   Go Up
Jump to: