Saturday, 24 September 2011

VeeCAD

I was recommended to try VeeCAD by a colleague who's a member of CMES.

I polished up my schematic in Eagle and, using the VeeCAD recommended export script, generated a netlist that VeeCAD could open. The advantage over diylc is that it tells you when you've not followed the netlist, allowing you to move components around until they fit nice and tightly together while knowing the circuit should still work. The disadvantage is it's slightly less pretty than diylc and it's a touch more fiddly to pick up and move components.

This schematic has 8 high side 12V outputs and 8 strobed 12V output pairs, so it will drive 4 2-aspect signals and 8 points. I think that means I'll need three of these and another, smaller, board that does just the signal outputs. The boards take as an input a 4 wire SPI bus and two pins to control whether the points are driven left or right (it didn't make sense to lose two pins off every MCP23S17 to do this), plus 12V, 5V and GND. The only thing I haven't added is smoothing capacitors for every IC, but there's plenty of spare board space for that.

Free Photo Sharing by ThumbSnap
Eagle schematic

Free Photo Sharing by ThumbSnap
VeeCAD stripboard layout

Sunday, 18 September 2011

Moving signals

I think this is a little more prototypical. I've moved to 3 aspect for the double track mainline and moved the up feathers onto the platform starters. Free Photo Sharing by ThumbSnap The signal BOM is:
All signals from http://www.crsignals.com

-- (20) --

Platform 1 up (London or Hilton Parkway)
	3 Aspect with two Feathers
	SN34 3-aspect Home LH Platform starter £15.95
	RI12 Position 1 + 2 Route Indicator £20.00

Platform 1 down (Birmingham or Radford)
	3 Aspect with Feather
	SN33 3-aspect Home RH Platform starter £15.95
	RI01 Position 1 Route Indicator £10

Platform 2 up (London or Hilton Parkway)
	3 Aspect with Feather
	SN33 3-aspect Home RH Platform starter £15.95
	RI01 Position 1 Route Indicator £10.00

Platform 2 down (Birmingham)
	3 Aspect
	SN34 3-aspect Home LH Platform starter £15.95

Platform 3 up (London or Hilton Parkway)
	3 Aspect with Feather
	SN34 3-aspect Home LH Platform starter £15.95
	RI01 Position 1 Route Indicator £10.00

-- (12) --

Hilton Up Approach Junction
	3 Aspect with two Feathers
	SN08 3 Aspect Home with Safety Ring £14.59
	RI12 Positions 1 + 2 Route Indicator £20.00

Hilton Down Approach
	3 Aspect
	SN08 3 Aspect Home with Safety Ring £14.59

Hilton Approach from Hilton Parkway
	2 Aspect
	SN06 2 Aspect Home with Safety Ring £14.00

Hilton Approach from Radford
	2 Aspect
	SN06 2 Aspect Station with Safety Ring £14.00

-- (4) --

Hilton Parkway (Hilton)
	2 Aspect
	SN31 2-aspect Home RH Platform starter £14.25

Radford (Hilton)
	2 Aspect
	SN31 2-aspect Home RH Platform starter £14.25


36 12V on/off outputs required = 5 UDN2938 drivers

Sunday, 11 September 2011

Feathers

The CR signals website (www.crsignals.com) is proving potentially ruinously expensive. They have a much larger range than Berko, including a selection of route indicators. These come in in a range of positions (numbered 1 through 6, corresponding to 11 o'clock, 9 o'clock, 7 o'clock, 1 o'clock, 3 o'clock and 5 o'clock respectively) to indicate which upcoming junction the train is about to take - see Wikipedia or Railsigns.co.uk.

AnyRail doesn't have symbols for any British style N gauge signals, so I've had to approximate with some P├ęgase symbols.

Free Photo Sharing by ThumbSnap
At £14 per signal and £10 per route indicator, they dwarf the costs of the Arduino and driver circuitry. Sadly, though, I don't really have the fine motor skills to build them myself. The little brass ladder must only be 3mm across!

Saturday, 10 September 2011

Signals

I went to the March and District MRC show today. Talked to some great people - made me really enthusiastic about getting stuck in to it all again. www.layouts4u.net had a stand there. I had a look at some N-gauge suitable signals from CR signals. These are the first signals I've seen up close as I've only seen the Berko ones on-line. They have small enamelled copper flying leads with pre-fitted resistors for 12V operation on the two anodes, with a common cathode return. This simplifies the veroboard somewhat as I won't have to worry about the resistors. I am concerned about what to do with the signals while the layout is in storage though. My best suggestion so far is to pull them out of their mounting holes and clamp them to the track using magnetic straps.

Well stone me, it works

I'm hugely surprised to be honest. I expected more fire, or at least some melting.

I do have a problem with the L293 on power up - it drives all four outputs high for a few seconds until the MCP23S17 is initialised. I think if I pull the enable lines low this should stop. Probably not good to drive every point on the layout in both directions simultaneously for a second. Certainly not at 1.2A per point per direction!

Incidentally the diodes you can see on the reverse of the motor are the flyback diodes. These are ultra-fast UF4007s, because that's what I had to hand. I really need to leave it on a soak test to see if the L293 survives.

Sunday, 4 September 2011

L293 driver

Just put some more code on github. I'm still not entirely sure what I'm doing with git, or why I have to 'add' code whenever I change it, even if it's already been added.

See http://github.com/thejpster/L293

I'll take a video of the code running soon, but here it is.

/* Simple MCP23S17 demonstration */

/* Supplied with Arduino IDE */
#include <SPI.h>

// Mcp23s17 library available from https://github.com/thejpster/Mcp23s17
#include <Mcp23s17.h>

// L293 point driving library available from https://github.com/thejpster/L293
#include <l293.h>

// Wire up the SPI Interface common lines:
// SPI_MOSI   11 //arduino <-> SPI Master Out Slave In   -> SI  (Pin 13 on MCP23S17 DIP)
// SPI_MISO    12 //arduino <-> SPI Master In Slave Out   -> SO  (Pin 14 on MCP23S17 DIP)
// SPI_CLOCK  13 //arduino <-> SPI Slave Clock Input     -> SCK (Pin 12 on MCP23S17 DIP)

// Then choose any other free pin as the Slave Select (pin 10 if the default but doesnt have to be)
#define MCP23S17_SLAVE_SELECT_PIN  9 //arduino <-> SPI Slave Select -> CS  (Pin 11 on MCP23S17 DIP)

// Instantiate a single Mcp23s17 object
MCP23S17 io_chip = MCP23S17( MCP23S17_SLAVE_SELECT_PIN /* CS */, 0x0 /* Tie A0/A1/A2 low */);

// L293 drivers
L293 points[2] = {
  L293(&io_chip, MCP23S17::GPIO_B0 /* Strobe */, MCP23S17::GPIO_A0 /* Left */, MCP23S17::GPIO_A1 /* Right */),
  L293(&io_chip, MCP23S17::GPIO_B1 /* Strobe */, MCP23S17::GPIO_A0 /* Left */, MCP23S17::GPIO_A1 /* Right */)
};

void setup()
{
  // Setup the serial port so we can see some debug
  Serial.begin(115200);
  Serial.print("Starting...");

  Serial.println("Started.");
}

void loop()
{
  // send data only when you receive data:
  if (Serial.available() > 0)
  {
    char incomingByte;
    // read the incoming byte:
    incomingByte = Serial.read();
    switch(incomingByte)
    {
    case '1':
      Serial.println("Point 1 Left");
      points[0].strobeLeft();
      break;  
    case '2':
      Serial.println("Point 1 Right");
      points[0].strobeRight();
      break;  
    case '3':
      Serial.println("Point 2 Left");
      points[1].strobeLeft();
      break;  
    case '4':
      Serial.println("Point 2 Right");
      points[1].strobeRight();
      break;  
    default:
      break;    
    }
  }
}

Monday, 29 August 2011

Re-work

Following on from this morning's post about ditching the LEDs/push-button control panel, here's a revised version of my first strip board layout. It's much more manageable.

Free Photo Sharing by ThumbSnap

I've retained the resistors for sinking current from the 2-aspect signals, but they could be omitted from the strip-board and fitted in-line in the cabling instead. I really need to buy one and see what they look like.

Bluetooth

I've spent the past couple of days re-laying track. I'd laid the two outer loops with Gaugemaster foam underlay, but it doesn't seem particularly compatible with Peco point motors. When I laid the track, that wasn't a problem, but now I want to automate everything, it is. So, the track's coming up in sections and I'm drilling ~6mm holes under one end of the tie bar on each point. I have one motor on a mounting plate that I'm offering up to check the holes are large enough and aligned correctly - you'd be surprised how hard that is to do.

I've also decided (for today, at least) that wiring up indicator lamps and push switches is all too 1980s. I think I'm going to start by connecting the Arduino to my laptop and developing a serial protocol for activating the points and signals. The upgrade path is then to connect over Bluetooth using Serial Port Profile to either my Nokia N900 or one of those dirt cheap Android tablets that seem to be flooding the market at the moment.

While I was following down that avenue, it occurred to me that an L293 driven from one of the PWM outputs of the Arduino would make a passable train controller. I could then have both signalman and train driver apps, the latter offering full inertia simulation.

I've also been looking at Raspberry Pi ARM based SBC. I have HDMI-enabled TVs in the rooms I'm most likely to operate the railway in, so I would run the signalman and/or train-driver apps on the Raspberry Pi and watch the output on the big screen. Again, I can start by working with the laptop.

Wednesday, 17 August 2011

Less wires

Well, this one has less insane wiring, but uses a larger board. I could probably build it on three boards and each piece is fairly standalone. To make things easier, I've ditched the common Vcc or Gnd connections for each LED and decided to daisy-chain those connections on the back of the display panel.

Free Photo Sharing by ThumbSnap

Monday, 15 August 2011

Tidier

This is a bit better.

Free Photo Sharing by ThumbSnap

I could halve the number of resistors on the signal indicator outputs in the middle as I shouldn't turn red and green on together. Perhaps, however, I should leave it as is as it will stop the indicator LEDs going dim if I get it wrong.

Sunday, 14 August 2011

Wires

Well, it's pretty good on board size, but perhaps I should expand it a few rows to try and tidy up some of the wiring.

Free Photo Sharing by ThumbSnap

I drew it using DIY Layout Creator 3 (beta). It crashed a couple of times (and, to be fair, the wiring is insane), but the autosave recovered me perfectly and it's far faster than Fritzing.

The top bank of resistors is to drive common-cathode pairs of LEDs. This is because that's how the Berko signals come (I believe) and it was easiest to make the repeaters on the panel work the same way. The bank of resistors below that show the status of the points on the panel, and they use two LEDs top-to-tail with a switched centre. I did that to halve the number of outputs needed, at the expense of doubling the number of resistors. The bank below that are the four MCP23S17 I/O expanders (three of which have UDN2981 source drivers fitted to drive the signals) and the bottom bank are the L293 motor drivers. I will set every side of every L293 to high/low or low/high simultaneously (bad things will happen if I set it high/high!) and strobe the enable lines for the points to be set, one at a time.

Thursday, 11 August 2011

Schematic

Here's my final schematic. I've only put one signal and point motor in - duplicate to taste. Multiple MCP23S17s can be wired in parallel, provided each has a unique binary value on the A0/1/2 pins.

Diodes D1/D2 should be something like a 1N4004. I read somewhere (must find the link) that the inductive spike could be 300V, so make sure they can handle that.

Free Photo Sharing by ThumbSnap

Sunday, 7 August 2011

Darlington Pairs

I spent some time today deciding whether I could use a 7 or 8 channel Darlington Pair IC (like the ULN2003A) to drive the point motors. They can only handle 500mA per channel, but it's possible to parallel up multiple ICs to increase the maximum current. The problem is the Vce(sat) is 1.2V and sinking 500mA means each IC will have to dump 600mW of power somewhere. It's nice that the chips are under 20p each, but I'd need a lot of chips to drive all 19 point motors (19 solenoids x 2 coils x 3 channels per coil / 7 channels per chip = 17 chips). That's an awful lot of soldering.

The other option is MOSFETs. They can handle huge loads without wasting too much power as heat, so I only need one per motor coil. You seem to have to buy them a singles - there aren't any cheap 7 or 8 way packages. They cost around 65p each 56p each if you buy a few (I'd need around 40). But, if you're spending £1.30 per point on MOSFETs, why not just spend £1.77 on an SN754410. It's almost exactly like an L293N, rated to 2A and will drive two points, so works out at 89p per point and involves less soldering as there are no resistors to worry about.

I am definitely satisfied that the SN754410 or L293N is the way to go. Until I change my mind again, anyway.

Edit: Turns out the SN754410 is only 1A per channel (2A per device). The L293D is 1.2A per channel. I will need the full-fat L293N, rated to 2A per channel.

Friday, 5 August 2011

Price update

CPC (who seem to be in some way related to Farnell, except that they charge entirely different prices) have the Allegro UDN2981 for £1.67 inc VAT. Bargain. I think I'll order a couple.

Thursday, 4 August 2011

Easier than mucking around with MOSFETs

I found this: http://uk.rs-online.com/web/p/darlington-transistor/0162795/

Basically it has 8 channels and each of those can continuously source 150mA at up to 50V. This means I can drive four 2-aspect Berko signals from one £2.15 IC. This is good.

Answers on a postcard (or in the comments) if you know the difference between a 2981 and a 2982. *shrug*

The Allegro UDN2981A-T appears to be the same as the Micrel MIC2981, in case you find that in stock instead. If you're doing things on breadboard, like me, you'll want the DIP package, not the surface mount ones.

Code

You can get my modified MCP23S17 library from Github: https://github.com/thejpster/Mcp23s17

My four-led twinkling app is:

/* Simple MCP23S17 demonstration */

/* Supplied with Arduino IDE */
#include 

// Mcp23s17 library available from https://github.com/dreamcat4/Mcp23s17
#include 

// Wire up the SPI Interface common lines:
// #define SPI_MOSI             11 //arduino   <->   SPI Master Out Slave In   -> SI  (Pin 13 on MCP23S17 DIP)
// #define SPI_MISO             12 //arduino   <->   SPI Master In Slave Out   -> SO  (Pin 14 on MCP23S17 DIP)
// #define SPI_CLOCK            13 //arduino   <->   SPI Slave Clock Input     -> SCK (Pin 12 on MCP23S17 DIP)

// Then choose any other free pin as the Slave Select (pin 10 if the default but doesnt have to be)
#define MCP23S17_SLAVE_SELECT_PIN  9 //arduino   <->   SPI Slave Select           -> CS  (Pin 11 on MCP23S17 DIP)
#define MCP23S17_RESET_PIN         8
// SINGLE DEVICE
// Instantiate a single Mcp23s17 object
MCP23S17 Mcp23s17 = MCP23S17( MCP23S17_SLAVE_SELECT_PIN );

// MULTIPLE DEVICES
// Up to 8 MCP23S17 devices can share the same SPI bus and slave select pins.
// Assign each chip a unique 3-bit device address (by setting the A2,A1,A0 pins)
// Then below, device address is optional 2nd parameter to the constructor fn...
// MCP23S17 Mcp23s17_0 = MCP23S17(MCP23S17_SLAVE_SELECT_PIN,0x0);
// ...
// MCP23S17 Mcp23s17_7 = MCP23S17(MCP23S17_SLAVE_SELECT_PIN,0x7);

void setup()
{
  // Setup the serial port so we can see some debug
  Serial.begin(115200);
  Serial.print("Starting...");

  pinMode(MCP23S17_RESET_PIN, OUTPUT);
  digitalWrite(MCP23S17_RESET_PIN, HIGH);
  delay(250);
  digitalWrite(MCP23S17_RESET_PIN, LOW);
  delay(250);
  digitalWrite(MCP23S17_RESET_PIN, HIGH);

  // Setup the SPI interface (default clock rate, etc)
  SPI.begin();

  // Set all pins to be outputs (by default they are all inputs)
  Mcp23s17.pinMode(OUTPUT);

  Serial.println("Started.");
}

// Cycle the output lines
long timeoutInterval = 250;
long previous = 0;
uint16_t counter = 0x0100;

void timeout()
{
  Mcp23s17.port(counter);
  counter <<= 1;
  if (counter == 0x1000)
  {
    counter = 0x0100;
  }
}  

void loop()
{
  // handle timeout function, if any
  long now = millis();
  if ( (now - previous) > timeoutInterval )
  {
    timeout();
    previous = now;
  }
  // Loop.
}

Stuff has arrived!

The Arduino Uno has arrived,. along with some other bits and pieces.

Firstly, the Arduino Uno is awesome. It's so simple to program. I didn't need to install any drivers (I use Ubuntu). The special Arduino IDE is very light on features, but that makes it very simple to use. I had an LED blinking on and off in no time at all.

The MCP23S17 had me baffled for a while, but I got it up and running eventually. The major pit falls were connecting both GND and VCC on the breadboard to GND on the Arduino (the pins are quite close together and my eyesight isn't that good). The second pitfall was using some example code that presumed I had tied the address pins one low and two high. I'd tied them all low. The third was that I need to strobe reset on power-up - something I'd not seen in any examples. As is usual, multiple intersecting bugs mean each makes the others really hard to find (I'd tried fiddling the addresses and moving the power pins, but never at the same time...). Anyway, it's now running.

I'm using the library from http://arduino.cc/playground/Code/Mcp23s17, but I've had  to tweak it as the SPI library supplied with my version of the IDE has SPI spelled all in capitals, whereas the library seems spell it Spi. The API is compatible, fortunately.



I've been talking to some chaps at the office about the best way to drive my point motors and signals. Some searching (http://www.n-gauge.org.uk/BERKON.htm) suggests that the signals I want to use have two LEDs with a common cathode (negative pin). This means I need a high-side switch, which means an NPN transistor driving a PNP transistor. I have a couple of ideas for driving the point motors, but I'm starting with the L293 Half-H bridge chip, which works out at £2.30 each for 10 off, which will supply 20 points. It handles up to 36V but only 2A peak, so with the 11 ohm Peco PL10WE motors I can try up to 22V. When the test motor arrives, I'll start with 12V and see what happens.

Monday, 1 August 2011

Links

Here we go.

For gEDA:
MCP23S17 symbol
L293 symbol

For AnyRail:
Track schematic

Welcome!

I'm considering adding some form of electronic control to my N-gauge model railway.

It's a fairly compact layout, at 5' x 3' (approx 1500mm x 900mm), but has around 16 points. I'm done the layout in AnyRail and will post up the schematic soon.

I've ordered an Arduino Uno (http://arduino.cc/) to get things rolling on the automation side, along with:


The idea behind the port expander is that the Uno doesn't have many pins, and the Arduino Mega is a bit pricey (~£50, as opposed to ~£20). You can think of the MCP23S17 as an upgrade to the common 74HC595 shift register. Controlled via SPI, you can set each of the 16 pins as an input or an output and generate interrupts when the inputs change. It'll handle around 20mA source/sink, so it should drive some LEDs for testing.

I've also taken the opportunity to lean gEDA, the schematic editor for Linux. I've made some symbols for the L293 and the MCP23S17. I'll upload those soon, too.