Shop OBEX P1 Docs P2 Docs Learn Events
count — Parallax Forums

count

adnadn Posts: 17
edited 2005-09-19 23:55 in General Discussion
Could you please help me with the code for the following...
I want to count external pulses comming into a pin of the sx28 for a period of 2.5 seconds and send the result over serial conection to a pc.
This needs to be done with inerupts and I am not very good with progamming. I am using the sx basic compiler.
Thanks

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-17 23:05
    Why are interrupts necessary? You could write a subroutine that does the counting and then user SEROUT to send the data off to a PC -- pretty easy, actually.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • adnadn Posts: 17
    edited 2005-09-18 06:19
    Thanks for your reply.
    The subroutine for counting needs to work in the backround and I dont how to do that. The serout is not a problem
    Thanks
  • BeanBean Posts: 8,129
    edited 2005-09-18 15:06
    What is the maximum count you expect over 2.5 seconds ?
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012
    Product web site: www.sxvm.com
    Available soon!! Video overlay(OSD) module...

    "I'm a man, but I can change, if I have to, I guess"
    Red Green
    ·
  • adnadn Posts: 17
    edited 2005-09-18 17:26
    Thank you for your reply.
    The max count will be 150.
  • BeanBean Posts: 8,129
    edited 2005-09-18 17:46
    Okay that will be easy. Just a couple more questions...

    What is the mimimum on and off time of the pulses ?
    What clock speed are you using for the SX chip ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012
    Product web site: www.sxvm.com
    Available soon!! Video overlay(OSD) module...

    "I'm a man, but I can change, if I have to, I guess"
    Red Green
    ·
  • adnadn Posts: 17
    edited 2005-09-18 18:16
    Thank you for your help...
    I am using the 50 MHz resonator that came with the kit but I can use the 4MHz if it is better.
    I am not sure about the mimimum on and off time of the pulses but the pulse is generated from a reed swich which is connected to a rotating mechanism of an anemometer. One rev is one pulse. I dont know if this helps...
  • BeanBean Posts: 8,129
    edited 2005-09-18 19:16
    This should get you started. I haven't tried it, but it should work (famous last words)...

    Be sure to change the pins and baud to whatever you are using.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012
    Product web site: www.sxvm.com
    Available soon!! Video overlay(OSD) module...

    "I'm a man, but I can change, if I have to, I guess"
    Red Green
  • adnadn Posts: 17
    edited 2005-09-18 20:13
    Thanks a lot for your help. I printed the file and trying to learn to work with inerrupts...
    I will give it a try and hopefully it will be ok.
    Thanks again for your time
  • BeanBean Posts: 8,129
    edited 2005-09-19 13:37
    adn,
    I fear that I have led you astray. I completely forgot about the RTCC input on the SX chip.

    You can simply connect the signal to the RTCC pin and use this code with no interrupts...

    Here is a much improved program...

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012
    Product web site: www.sxvm.com
    Available soon!! Video overlay(OSD) module...

    "I'm a man, but I can change, if I have to, I guess"
    Red Green
  • adnadn Posts: 17
    edited 2005-09-19 18:35
    Bean,
    Thanks for your reply.
    I am a litle bit confused now.
    I need to perform some other calculations at the same time and thats why I was thinking that I had to use interrupts. I can not use the pause command ... so I believe the first program is better.
    Is this correct?
    Thanks
  • BeanBean Posts: 8,129
    edited 2005-09-19 19:16
    Then I would use the interrupt simply to count elasped time. and store RTCC in "cnt" after 2.5 seconds.
    The RTCC input is made to count pulses, it's the way to go.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012
    Product web site: www.sxvm.com
    Available soon!! Video overlay(OSD) module...

    "I'm a man, but I can change, if I have to, I guess"
    Red Green
    ·
  • BeanBean Posts: 8,129
    edited 2005-09-19 23:55
    Man I really need a vacation... You cannot use RTCC to count AND use it for elapsed time at the same time.
    Oh well, go ahead and use the original version...
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012
    Product web site: www.sxvm.com
    Available soon!! Video overlay(OSD) module...

    "I'm a man, but I can change, if I have to, I guess"
    Red Green
    ·
Sign In or Register to comment.