I am a model railroader and the new locomotives have Pics in them that read serial data from the track for control rather than conventional DC power. I wanted to build one of my own because sound decoders are $100+. I built the board for a PIC 16F84a and now need help programing. The electrical specs for the serial timing can be found here.
http://www.nmra.org/standards/DCC/standards_rps/DCCStds.html.
Basically for a standard serial stream, 4 packets of 8 bits are sent. For an extended packet, 11 bits are sent. A 1 bit is represented by two halves of a rise and fall of the clock between 52 and 64 microseconds and 0 is between 99 and 10000 microseconds (not a typo. A 0 can be long to simulate DC voltage on the track). My decoder needs to be able to read these packets, update the PWM to motor, run the lights/accessories, and run the sound. I am having trouble deciding code order. Should I read all the data from the track, then update everything or should Iupdate between readings (worried about throwing timing off there). I need code design help.
http://www.nmra.org/standards/DCC/standards_rps/DCCStds.html.
Basically for a standard serial stream, 4 packets of 8 bits are sent. For an extended packet, 11 bits are sent. A 1 bit is represented by two halves of a rise and fall of the clock between 52 and 64 microseconds and 0 is between 99 and 10000 microseconds (not a typo. A 0 can be long to simulate DC voltage on the track). My decoder needs to be able to read these packets, update the PWM to motor, run the lights/accessories, and run the sound. I am having trouble deciding code order. Should I read all the data from the track, then update everything or should Iupdate between readings (worried about throwing timing off there). I need code design help.