Hi there...
I am trying to count the no of object pass in a conveyor systems and it need to be displayed in a LCD every time a object passes through it. I used IR for this purpose... wen ir detect the Object the led gets turned off and vice versa. Now the problem is wen LED turned off the counter keeps on counting till it get turned on
And also the counter counts only upto value 10 and it gets return to 1...
can any one pls help me.
check the program below
while(True) { if (LED1 == 0) { Count = Count+1; //LED1 = 1; }
// UserMessageStorage[4] = Count; // UserMessageStorage[1]+= 1;
UserMessageStorage[4]= Count/1000; Count=(Count-(UserMessageStorage[4]*100)); UserMessageStorage[4]+=0x30;
UserMessageStorage[5]= Count/100; Count=(Count-(UserMessageStorage[5]*10)); UserMessageStorage[5]+=0x30;
UserMessageStorage[6]= Count%100; UserMessageStorage[6]+=0x30;
TotalCount[0] = UserMessageStorage[4]; TotalCount[1] = UserMessageStorage[5]; TotalCount[2] = UserMessageStorage[6];
// u8Temp = (TotalCount[0] - 0x30) * 100; // u8Temp += (TotalCount[1] - 0x30) * 10; // u8Temp += (TotalCount[2] - 0x30) * 1; //
//TotalCount[0] = UserMessageStorage[1];
// SerTx(TotalCount[0]); // SerTx(TotalCount[1]); // SerTx(TotalCount[2]);
ArrayBasePtr="Total Objects= "; DisplayLCD(1,0,ArrayBasePtr); ArrayBasePtr=&TotalCount[0]; DisplayLCD(2,0,ArrayBasePtr); ArrayBasePtr=" Objects"; DisplayLCD(2,3,ArrayBasePtr); TimeDelay(1000); LCD_CLEAR();
Thanks in advance guys
You can use interrupts or you can poll.
Polling requires that a pulse from the sensor is long in "processor time", so you are sure that you never miss catching the pulse because of worst-case loop repetition times.
My hints didn't had anything with interrupts to do, but with thinking about the difference between reacting when you see a specific change in a signal, compared to reacting when you see a signal in a continuous state.
Think about a one-shot flare gun.
You have agreed to signal whenever you see a boat.
So when you see the boat, you shoot the flare gun. Since you only have one shot in it, you only manage one shot. No repetition.
You have then agreed with yourself that you will not reload the gun until the first ship is out of sight.
So next time you see boat/ship you have a loaded gun again, and can shoot a flare.
You, on the other hand, sees your problem as a gatlin gun with infinite ammo. When you see the gun, you press the trigger and shoot and shoot and shoot until the boat is out of visible range.
Would that really be a good way to count boats?
That was what I meant when I talked about arming your logic.
In your case, you have two events (even if you may not be able to get your interrupt to handle both events) possible. One event is that the light gets blocked. One event is the light beam gets detected again.
You should only count when you get one of these two events. You could use any of the events (beam going from detected to not detected, or beam going from not detected to detected), but a professional solution would prefer the use of the second event - when the light beam gets detected again.
The reason for using the second edge/event, is that you can then measure the time the light beam was blocked. Why do that? 1) In case you have a narrow beam, you could interrest a couple of flies that gets buzzing through the beam, producing large numbers of very short pulses.
2) In case the beam fails, you would then be able to detect that the beam has been off for a very long time, so you could generate an alarm, reporting a equipment failure (maybe dead lamp, maybe dead light sensor, maybe stuck belt transporting the goods).