This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Object counter

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

Parents
  • So you have just learned the difference between flank-trigged and level-trigged signal processing.

    Why do you let your counter tick constantly when the light beam is blocked? Why not just count one time and then wait for the light beam to be detected again before you rearm your counter?

    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;
    

    So what happens if count is 3697 and you do the above?

    Count = 3697
    UserMessageStorage[4] = 3697/1000 (3) + 0x30. I.e. '3'.
    Count = 3697 - 3*100 = 3397;

    UserMessageStorage[5] = 3397/100 (33) + 0x30. I.e. 'Q'.
    Count = 3397 - 33*10 = 3067;

    UserMessageStorage[6] = 3067%100 (67) + 0x30. I.e. 's'.

    So the counter value 3697 should then be represented as '3Qs'. Whas that really what you intended?

    And the other thing is that your printout destroys your counter by modifying it. Isn't that quite silly?

    The big question that may be a bit embarrasing: Haven't you tried to debug your code? Haven't you tried to give Count a value and then see what would happen, step-by-step? And see if you get a suitable value to print - and that you then get back to the top of your loop with Count still containing a meaningful value?

Reply
  • So you have just learned the difference between flank-trigged and level-trigged signal processing.

    Why do you let your counter tick constantly when the light beam is blocked? Why not just count one time and then wait for the light beam to be detected again before you rearm your counter?

    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;
    

    So what happens if count is 3697 and you do the above?

    Count = 3697
    UserMessageStorage[4] = 3697/1000 (3) + 0x30. I.e. '3'.
    Count = 3697 - 3*100 = 3397;

    UserMessageStorage[5] = 3397/100 (33) + 0x30. I.e. 'Q'.
    Count = 3397 - 33*10 = 3067;

    UserMessageStorage[6] = 3067%100 (67) + 0x30. I.e. 's'.

    So the counter value 3697 should then be represented as '3Qs'. Whas that really what you intended?

    And the other thing is that your printout destroys your counter by modifying it. Isn't that quite silly?

    The big question that may be a bit embarrasing: Haven't you tried to debug your code? Haven't you tried to give Count a value and then see what would happen, step-by-step? And see if you get a suitable value to print - and that you then get back to the top of your loop with Count still containing a meaningful value?

Children