Determining Pulse Width
How do you make an variable equal to 1 if the width of an incoming pulse on RA.0 is 58us and equal to 0 if the pulse is 100us?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
do
pulsout RA.0, 6
loop
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PULSOUT inverts the state of the pin. If the pin start out high, then you WILL get a negative pulse.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
DO
ra.0 = ~ra.0
pauseus 58 'Pause duration
LOOP
It gives me the bipolar AC necessary but it cannot use transmit any data. Also the bipolar AC starts with a positive pulse instead of the negative one. The digital command decoder interprets a logic level high as two pulses. The first pulse is a 58us -14 volt pause. The second is a +14 volt pulse at the same duration. A logic level low is read as a 100us -14 volt pulse and then a +14 volt pulse.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (Lightfoot) : 6/26/2007 4:48:40 AM GMT
Post Edited (JonnyMac) : 6/26/2007 2:01:04 PM GMT
www.nmra.org/standards/DCC/standards_rps/S-91-2004-07.pdf.
I tried running the preamble routine on my scope and no square waves. Nothing is coming off of RA.0, just 0 volts. Same happens when I transmit a bit.
code I ran:
Main:
PREAMBLE
goto Main
Thanks again
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (Lightfoot) : 6/26/2007 7:29:02 AM GMT
Note that I can't guarantee the program will work; in fact, you should count on having to fix it as it's just intended to show you a method of transmitting bits in a byte and based on the information you provided. Since there's bit of subtlety in using the TX_DCC_BYTE sub I've fixed and re-uploaded the demo (see above for new code).
Post Edited (JonnyMac) : 6/26/2007 2:01:59 PM GMT
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (Lightfoot) : 6/27/2007 12:48:13 AM GMT
Transmitter Code: ******************************
tris_a = 0
_data var byte
DO
SEROUT RA.0, T2400, _data
pauseus 100
LOOP
Receiver Code: ******************************
tris_b = 0
plp_a = 0
DO
SERIN RA.0, T2400, rb
LOOP
The only problem with the serout command is that it does not generate bipolar AC from my H Bridge. Only inverting a pin does that (the only way I know of). So the transmitter would need to transmit serial data at 2400 baud doing (ra.0 = ~ra.0) bitwise nots. I do not know how to calculate the pauses needed to send a binary 1 or 0 or have an accurate idea how to code a bitwise not serialout program. Also if there is a way (even using serout) besides bitwise not that can generate bipolar AC please say so.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Transmitter:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔