Project: PIC based Scalextric Lap Counter

Discussion in 'The Completed Projects Collection' started by Crossie, Nov 19, 2010.

  1. Crossie

    Thread Starter New Member

    Jul 22, 2010
    4
    0
    PIC18f452 Based Scalextric Lap Counter


    Many years ago I started a project to build a Scalextric lap counter based on an HC11 UV erasable EEPROM microcontroller that we were using on products at work. We stopped using the device, the Unix assembler went and my project ended. Some years later, spurred on by my son getting a Scalextric micro track for his birthday I revived the project, this time based around a PIC having taken up the Microchip PICkit2 for £9.99 offer!


    Designed and built to work with Micro Scalextric racing track but could be adapted to work with standard size track.


    Car sensing is done by IR beam breaking with a pair of IR LEDs over each lane and an IR opto transistor under each lane with a small cut in the plastic track.


    The output from the opto transistor is cleaned up by a simple comparator based threshold detector and this is fed into time inputs on the PIC.
    The PIC counts the number of laps for each lane and also calculates the lap times. These are displayed on a 2x20 VFD display.


    A 4x1 membrane keypad is used to enable selections to be made such as track names from pre-programmed lists and the mode of operation: simple free running mode which counts up to 99 laps then rolls over or race mode where the number of laps for the race is selected and a fomula 1 style starting sequence is run on the five over track LEDs. This is a simple one LED, two LED up to five LEDs where upon the LEDs all go out after a random delay and the race is on. If a car breaks the IR beam before the five LEDs are turned off a false start is flagged.



    The project comprises two parts; track mounted sensors and LEDs and main PIC unit.


    [​IMG]


    Track Mounted Unit

    LEDs and opto transistors are mounted on vero board. Five forward facing start LEDs and four downward facing IR LEDs, two per track. These are mounted in a length of plastic wiring conduit (the type with a detachable lid and self adhesive backing).


    [​IMG]

    [​IMG]

    [​IMG]

    Main PIC unit

    PCB was bread boarded on square pad board.
    PCB was then laid out in Eagle and I had a PCB made by PCB Pool.


    http://www.pcb-pool.com/ppuk/info.html


    Display and keypad are mounted off board and are connected by 14way DIL header and 5 way SIL header respectively. On board switches are in parallel with the keypad to make debugging easier and I added an LED to a spare PIC pin also for debug.


    On board regulator is provided and there is also a reverse protection diode given the variability of external power brick polarity. The unit runs with a variable PSU block set at 7.5V.

    [​IMG]

    [​IMG]

    Coding

    All coding was done in MPLAB IDE using C18. I’m not a software engineer so the code may not be elegant but it is functional!
    Possible Improvements


    The pitch for the two crystal capacitors was originally 5mm when I sent the PCB for manufacture. When assembly the PCB it was obvious that the 22pF capacitors were 2.5mm pitch.

    Always run a full DRC check when doing a PCB. One net on the PCB looked connected but was not so I have a small wire link to fix that.


    The physical position of the 6 pin PIC programming header does not allow enough room to fit the PIK Kit 2 when the display lead is plugged in – I had to make an adapter lead.


    Other than that I’m really pleased with the project. The software is a never ending task with endledd tweaks and improvements but it works really well and provides an extra dimension to slot car racing with my son!

    Attachments

    The ZIP file attached contains the eagle data for the PIC board and schematic for the track end. Also included is the PIC c code and a parts list. I did some scope captures of the sensor output and some simulations in Simetrix,

    I have included the scope capture and could put the Simetrix stuff if od interest)
     
  2. Georacer

    Moderator

    Nov 25, 2009
    5,142
    1,266
    Great Modding! I always love practical additions on trivial applications. Combined with the thrill of cutting seconds off of your lap time, that makes that project trully awesome!

    Good job!
     
    Crossie likes this.
  3. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Excellent work!

    The fit and finish of the control unit looks professional.

    The ONLY thing I can point at is the parts list is in Office 2010 format instead of PDF or txt, but that is a minor issue.
     
    Crossie likes this.
  4. Crossie

    Thread Starter New Member

    Jul 22, 2010
    4
    0
    Having completed the main control box I am left thinking that the track mod could have been done better.

    I have seen another similar project where the track bit was built into a modrock made landscape. I may have a go at something like this at some point in the future.
     
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Forgot to ask. What was your source for the VFD? Looking at the ribbon cable, the VFD board appears to have onboard power supply and control similar to an LCD.

    I like VFDs a lot, but haven't found much for hobby use. They are very brilliant and professional looking if put in a tinted case.
     
  6. Crossie

    Thread Starter New Member

    Jul 22, 2010
    4
    0
  7. Crossie

    Thread Starter New Member

    Jul 22, 2010
    4
    0
    Good point. pdf attached (I hope)
     
Loading...