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
  • Well i am sorry for posting in wrong format. I am new to this Embedded Domain and Programming Field. For u guys like pro every thing will be silly, but for me even displaying a single character in LCD is a big think.And moreover I m learning now n i would mind getting embarrassing.

    As u said i ve debugged the program and i m now getting the count properly. but i don't how to count only once when the led turned off .

    if(LED1 == 0) { value++; Count = value;

    UserMessageStorage[4]= Count/100; Count=(Count-(UserMessageStorage[4]*100)); UserMessageStorage[4]+=0x30;

    UserMessageStorage[5]= Count/10; Count=(Count-(UserMessageStorage[5]*10)); UserMessageStorage[5]+=0x30;

    UserMessageStorage[6]= Count%10; UserMessageStorage[6]+=0x30;

    TotalCount[0] = UserMessageStorage[4]; TotalCount[1] = UserMessageStorage[5]; TotalCount[2] = UserMessageStorage[6];

    SerTx(TotalCount[0]); SerTx(TotalCount[1]); SerTx(TotalCount[2]); LED1 = 1; }
    Please help me .. thanks for ur information . its really useful MR.Mark

Reply
  • Well i am sorry for posting in wrong format. I am new to this Embedded Domain and Programming Field. For u guys like pro every thing will be silly, but for me even displaying a single character in LCD is a big think.And moreover I m learning now n i would mind getting embarrassing.

    As u said i ve debugged the program and i m now getting the count properly. but i don't how to count only once when the led turned off .

    if(LED1 == 0) { value++; Count = value;

    UserMessageStorage[4]= Count/100; Count=(Count-(UserMessageStorage[4]*100)); UserMessageStorage[4]+=0x30;

    UserMessageStorage[5]= Count/10; Count=(Count-(UserMessageStorage[5]*10)); UserMessageStorage[5]+=0x30;

    UserMessageStorage[6]= Count%10; UserMessageStorage[6]+=0x30;

    TotalCount[0] = UserMessageStorage[4]; TotalCount[1] = UserMessageStorage[5]; TotalCount[2] = UserMessageStorage[6];

    SerTx(TotalCount[0]); SerTx(TotalCount[1]); SerTx(TotalCount[2]); LED1 = 1; }
    Please help me .. thanks for ur information . its really useful MR.Mark

Children
  • "sorry for posting in wrong format."

    But you've done it again!

    "I am new to this Embedded Domain and Programming Field"

    But choosing the correct format for posting is simply a matter of following simple, clearly stated instructions - as this picture shows you (click the link to see it):

    www.danlhenry.com/.../keil_code.png

    This requires no particular Embedded or Programming skills!

    However, Programming does require great attention to detail; you need to carefully study all the available documentation, and pay attention to what you find.

    Some people are just not cut out for this, which is fair enough - but it is what you'll need to do if you want to be a programmer.

    If you are new to programming, then you may find it easier to learn the 'C' programming language on a PC first. Then, once you have learned the language, you can move on to apply it in the embedded microcontroller field

    The following lists some books & training providers:
    http://www.keil.com/books/
    http://www.keil.com/events/links.asp

    publications.gbdirect.co.uk/.../

    www.eskimo.com/.../

    Note that using microcontrollers like this also requires at least a basic understanding of electronics...