I've been trying to get a model train DCC command station library running, but I'm having problems getting past the initialisation routine.
It's generating a DCC pulse train ok, but it doesn't seem to be getting past this function in DCCPacketScheduler.cpp,
void DCCPacketScheduler::setup(void) //for any post-constructor initialization
{
setup_DCC_waveform_generator();
//Following RP 9.2.4, begin by putting 20 reset packets and 10 idle packets on the rails.
//use the e_stop_queue to do this, to ensure these packets go out first!
DCCPacket p;
byte data[] = {0x00};
//reset packet: address 0x00, data 0x00, XOR 0x00; S 9.2 line 75
p.addData(data,1);
p.setAddress(0x00);
p.setRepeat(20);
p.setKind(reset_packet_kind);
e_stop_queue.insertPacket(&p);
//idle packet: address 0xFF, data 0x00, XOR 0xFF; S 9.2 line 90
p.setAddress(0xFF);
p.setRepeat(10);
p.setKind(idle_packet_kind);
e_stop_queue.insertPacket(&p); //e_stop_queue will be empty, so no need to check if insertion was OK.
}
It's almost like the setRepeat is repeating for ever.
Short pulses are 1 and long pulses a 0,
The string of 1's is a preamble, and all 0's i believe is a reset packet. This is all I ever get.
I'm using the CmdrArduino_minimum.pde example,
/********************
* Creates a minimum DCC command station from a potentiometer connected to analog pin 0,
* and a button connected to ground on one end and digital pin 4 on the other end. See this link
* http://www.arduino.cc/en/Tutorial/AnalogInput
* The DCC waveform is output on Pin 9, and is suitable for connection to an LMD18200-based booster directly,
* or to a single-ended-to-differential driver, to connect with most other kinds of boosters.
********************/
#include <DCCPacket.h>
#include <DCCPacketQueue.h>
#include <DCCPacketScheduler.h>
DCCPacketScheduler dps;
unsigned int analog_value;
char speed_byte, old_speed = 0;
byte count = 0;
byte prev_state = 1;
byte F0 = 0;
void setup() {
dps.setup();
//set up button on pin 4
pinMode(4, OUTPUT);
digitalWrite(4, HIGH); //activate built-in pull-up resistor
}
void loop() {
//handle reading button, controls F0
byte button_state = digitalRead(4); //high == not pushed; low == pushed
if(button_state && (button_state != prev_state))
{
//toggle!
F0 = (F0+1)%2;
Serial.println(F0,BIN);
dps.setFunctions0to4(3,F0<<4);
}
prev_state = button_state;
//handle reading throttle
analog_value = analogRead(0);
speed_byte = (analog_value >> 2)-127; //divide by two to take a 0-1023 range number and make it 0-127 range.
if(speed_byte != old_speed)
{
dps.setSpeed128(3,speed_byte);
old_speed = speed_byte;
}
dps.update();
++count;
}
Any ideas guys?