How to read rising edge of hall effect switch input without interrupt


hello,

i have loop pulses stepper motor until input hall effect detected (digital 5v) routine did not work.

however, following code detects switch nicely. there way without using interrupts? way have smooth loop running , detect precisely position of switch.

thanks

code: [select]
/*
arduino hall effect sensor project
by arvind sanjeev
please check out  http://diyhacking.com tutorial of project.
diy hacking
*/


 volatile byte half_revolutions;
 unsigned int rpm;
 unsigned long timeold;
 void setup()
 {
   serial.begin(115200);
   attachinterrupt(0, magnet_detect, rising);//initialize intterrupt pin (arduino digital pin 2)
   half_revolutions = 0;
   rpm = 0;
   timeold = 0;
 }
 void loop()//measure rpm
 {
   if (half_revolutions >= 20) {
     rpm = 30*1000/(millis() - timeold)*half_revolutions;
     timeold = millis();
     half_revolutions = 0;
     //serial.println(rpm,dec);
   }
 }
 void magnet_detect()//this function called whenever magnet/interrupt detected arduino
 {
   half_revolutions++;
   serial.println("detect");
 }

using interrupts can beneficial operations or events timing important..... or things need done right away when event occurs.

using interrupts having dedicated person keeping watch of particular event you.....and coming tell when event detected.

when don't use interrupts signalling , detecting event or occurrence......... need regularly go around periodically check see if has changed. if rate @ go check high enough..... ok. if rate isn't high enough.... there might increased chance activity might missed in between checks. terminology checking every once in while 'polling'.

for sure..... can program loop check status (eg. read value) each loop. can store current value previous value of whatever being read. however, there might chances miss activity in-between checking...... lead issues. but..... if know in advance it's not going issue...... no problem.




Arduino Forum > Using Arduino > Programming Questions > How to read rising edge of hall effect switch input without interrupt


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts