Go Down

Topic: How to generate an interrupt from an analog signal (Read 3892 times) previous topic - next topic

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Nick Gammon

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: [Select]
// 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
Please post technical questions on the forum, not by personal message. Thanks!

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

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

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

WillR

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.

Just another Hacker

DBB

Thanks to you guys!

I'll be trying it out myself.

Doug

wwbrown

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


DBB


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

CrossRoads

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

must have been the dog ...
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

DBB

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

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

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

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up