Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Gear Tooth Code (http://www.chiefdelphi.com/forums/showthread.php?t=54504)

magical hands 18-02-2007 23:19

Gear Tooth Code
 
Can someone tell me why this code wouldn't work for Gear Tooth Sensor. To me it makes sense because its connected to digital input and it only gives 0 or 1 based on the voltage (5v).

int i = 0;

If (rc_dig_in01 == 1) //Gear Tooth Attached to dig_input 1
{
i++; // Gear Counter
printf("Gear counter=%d\r\n", i);
}

Alan Anderson 19-02-2007 00:05

Re: Gear Tooth Code
 
That code continuously increments a value whenever the Gear Tooth Sensor is high. It won't work because it doesn't count the number of times the signal from the Gear Tooth Sensor goes high.

If the signal is slow enough, you can poll it and count low-to-high transitions. Just remember the previous state of the pin, and if it was a zero last time but is a one this time, increment the counter. However, if the signal changes so quickly that you can't guarantee you'll be reading it often enough, you'll need to use the hardware interrupt feature of the RC's first few digital input pins.


All times are GMT -5. The time now is 04:54.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi