Using the PIC to design DCC components.
I plan to use PIC microcontrollers to build my DCC components. You can find many examples on the Internet that show how to do this. So you might be asking "Why do it yourself?"
That's a great question. I want to learn how. My interest in Model Railroading is really computer based control. Many of the examples on the web are quite dated. Some of the newer PICs can replace even more of the few components on the decoder and accessory boards. It's my goal to learn how to do this. I am not an electrical engineer and find it difficult to use assemble. I prefer C.
To that end I downloaded a C compiler from Hi-Tech that I use with Microchip's MPLAB to program the microcontroller devices. I am experimenting with Microchip mechatronics board, tying to work out some of the decoder functionality in C rather than assembly. I will start with the PIC16F917 just because it happens to be the part the board came with. I will retarget the device in the future. This PIC is a large 40pin device with LCD outputs for a lot of segments. This would be overkill as a DCC mobile Decoder, but may be perfect for a cab ( the hand-held train controller) or a command station. One idea I have been kicking around is a super controller that can manage remote switches.
if a noteworthy change is seen. The other method is using interrupts to trigger service routines when an event on a pin occurs. I am still wrestling with the method to choose. Coming from a software background I am leaning to an interrupt driven approach. However, all the embedded control experts are telling me that polling is much simpler to get right. Moving to the 16 bit connrollers like the PIC24 would make me more comfortable with an interrupt based approach. The devices are faster and have much more memory capacity. ( Yes... You're right... I can be more sloppy )
Steps
Decide on an algorithm and overall code design
Helps decide PIC family
Helps narrow down pin count.
Configure the device
Define the ports you want to use. Determine IO.
Which pins are input : analog and digital.
Which pins are output: analog and digital
Select the peripherals you want.
Timers
ADC/DAC
LCD
PWM
Capture
I've been converting the labs for the motor driver board into C from the original assembly. It was an interesting challenge but now I can structure the code in such a way that the assembly generated from the compiler is very close to that of the lab. It was a great learning experience.
Now I am about to start on the DCC decoding. This requires tighter timing controls. The C version should be easier to follow but might turn out radically different from the current assembly based decoders. I think I''ll start from scratch.
There are two primary means of processing external events on a microcontroller. The use of polling is simply a busy wait on an external event that causes a jump to some code