Shop OBEX P1 Docs P2 Docs Learn Events
how to count with sx? — Parallax Forums

how to count with sx?

ellizardellizard Posts: 106
edited 2005-03-15 19:23 in General Discussion
HI

I am used to basic stamps, and trying to do some project with sx, but could not come out of the count problem.
I want to count pulses on a pin during a finite period of time ( a rev counter),
in the PBasic there is the magic command COUNT, but not in the SX-B, being less than an apprentice with the assembler, i'm trying to do it with the sx basic, but the only result is a mess of stucked program.

could anyone give me a little help to enlighten the dark night?????
thank you in advance

(of course i'm not looking for the complete solution of the problem!!!!)

Ellizard

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-03-15 19:23
    the easiest way is to use the RTCC pin, but since you want to have a timeout function, you'll need to use the RTCC for that. It depends on how quickly the pulses occur, if its slow you can set the rtcc to overflow frequent enough (according to Nyquist's theorem at least twice the maximum frequency of your incoming pulses your counting), in the ISR youll increment a counter indicating how many times the ISR is executed then poll the input your counting, and conditionally increment a count register, when your first counter gets to the point that corresponds to your time out value, you then take the count register as your result. If your counts are coming in real fast (and I mean really really fast·(several million/ second)) then you can use the B port's pin change interrupt, but you'll have to take special precautions to make sure you deal with the case that if your handling a pin change interrupt·and the RTCC timout interrupt occurs you notice it, becuase if your in the ISR when the RTCC interrupt occurs it will be lost unless you explicitly test for it and deal with it·(in this second method you would set the RTCC to interrupt only once, when the timeout time occurs, the first one you would set it to interrupt many times (subdividing the timeout period into smaller peices))

    Post Edited (Paul Baker) : 3/15/2005 7:33:41 PM GMT
Sign In or Register to comment.