Slot Car timer with pic 16f84a


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2007
    Location
    Southern Ontario
    Posts
    50

    Default Slot Car timer with pic 16f84a

    Hello again, I am still working on my slot car timer and am very close to finishing it. However I am having a real problem when the cars cross the timing gantry at the same time. When a car tripps the light sensor it tells the pic to send a number to the pc to say I am in this lane and have passed another lap. The pic can do this so fast that it will actually reset and send another signal before the car has passed over the light. This registers more then one lap. I put in a pause of 1 sec after the signal has been sent and it works UNLESS another car trips it's sensor while the one second pause is timing. When two cars cross at more or less the same time one does not register. Is there any way to send a signal and wait a second or two but still send a different signal if it happens inside the pause. Im thinking there might be a way with interupts?
    Any help would be appreciated. I will share the VB program when I am done.

    Here is the code

    Use the Pic 16f84 to controll the slot car track and
    ' Send the laps to the PC for timing and data storage
    '
    '
    '
    B0 var byte
    'scale var byte
    loop:
    low portb.2
    input 5

    pot 3,49,B0
    if (B0>45) then Car
    if (b0<2)then Car

    pot 4,49,B0
    if (B0>45) then Car2
    if (b0<2)then Car2
    if portb.5 = 1 then reset
    goto loop
    Reset:
    high portb.2
    serout porta.2,0,[#100]
    pause 2000
    goto loop

    Car:
    high portb.2
    serout porta.2,0,[#200]
    pause 100
    goto loop
    Car2:
    high portb.2
    serout porta.2,0,[#300]
    pause 100
    goto loop

    Thank You for you time ,Snap
    Beer is proof that God loves us and wants us to be happy.

  2. #2
    skimask's Avatar
    skimask Guest

    Default

    Use a shorter pause inside a loop (for temp = 0 to 1000 : pause 1 : check for another car here : next temp ) while checking for a 2nd car, set a flag (or flags), then when the tight-loop-pause exits, check the flag to see if another notice has to be sent out, then reset the flag.

  3. #3
    Join Date
    Apr 2007
    Location
    Southern Ontario
    Posts
    50

    Default

    Thank you for your reply,
    I have not done flags before I will have to research them. I get what you are saying about small loops inside of loops but would like to know if there are any examples out there to study from.
    Beer is proof that God loves us and wants us to be happy.

  4. #4
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Snap View Post
    Thank you for your reply,
    I have not done flags before I will have to research them. I get what you are saying about small loops inside of loops but would like to know if there are any examples out there to study from.
    Example right there in my last post...
    Your one second pause =
    Pause 1000

    Another way to do it, and to check stuff in between...
    For temp = 1 to 1000
    Pause 1
    'check for other stuff
    Next temp

    Of course the looped way of doing it will always end up being over one second, so you might end up having to use 900 instead of 1000 depending on how much 'check for other stuff' you do.
    Past that, you could always learn about interrupts and use those as you initially suggested.

    But, I'd suggest you get rid of that POT command and whatever light sensing resistors you're using and switch over to some sort of 'beam breaking' method or maybe a magnetic reed switch since slot cars tend to have magnets in them (don't they?). The POT command takes too much time with what you want to do, and it's a show stopping command. When the POT command is executing, nothing else is, hence you miss a second car while trying to sense the first.
    With the beam breaking method, you can instantly scan multiple lanes and put each beam break into a queue with a time stamp and send the information out the serial port when you want.

  5. #5
    Join Date
    Apr 2007
    Location
    Southern Ontario
    Posts
    50

    Default Back to the drawing board

    Thank you for all your help. I nested a few small loops and it worked like a charm....except for like you said when a very fast car goes by when the other lane is potting it can miss it. It happens rarley but it happens. I am set up with the light sensors secured in the track and I built a light source above them so I am going to work on keeping them somehow. (reed switches would work but I also know that other people have made the light sensors work) I will start researching light sensing circuits tomorrow. But in the mean time Thank again for the advice.
    Snap
    Beer is proof that God loves us and wants us to be happy.

Similar Threads

  1. Timer code examples for PIC 16F628
    By Tastature in forum mel PIC BASIC
    Replies: 6
    Last Post: - 22nd November 2013, 03:47
  2. Timer 1 kills PIC
    By jpeakall in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th January 2009, 05:03
  3. 1/ 100th second Slot car Timer
    By Snap in forum Serial
    Replies: 13
    Last Post: - 7th December 2007, 20:25
  4. PIC 16F84A and 7segment LED dispay
    By select in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 21st November 2007, 22:01
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th March 2005, 00:14

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts