Shop OBEX P1 Docs P2 Docs Learn Events
Event Counting - HO Railroad — Parallax Forums

Event Counting - HO Railroad

DataJDataJ Posts: 23
edited 2009-04-28 15:39 in BASIC Stamp
Attached is the code from the original testing,·"IR Switching Display Detect",·used to determine if the IR Detectors, H Bridge and servos would work as planned, and, they do.

The second attachment·is the program code, "Event Counting,·in attempt to program some form of accountable control over the entire action on the layout.· (The basis for this code is from the StampWorks Manual).

The third attachment is the track schematic, pin identification, label names, etc., which help clarify what
is to be accomplished.

Thank you

Comments

  • Radridz3Radridz3 Posts: 49
    edited 2009-04-27 15:36
    I am a n scaler and have a system on my layout that does this but instead of using IR I use PIR motion sensors the only problem with this switching app is the pause or delay from forward to reverse and switch times . On my layout the lenght of the train. Or number of rolling stock is a variable that needs to be constant right now my delay is setup for a train with 8 cars but if I use 8 well cars the dealy is all wrong so theres 1 problem I haven't been able to solve. I thought of using IR to let the stamp now how long the train is. But have been unable to get the code right. If you get this to work let me now what you did to change the pause on the switches.... Another thing is I suppose if you lines are long enough you don't have to worry about this but my yard is kinda small so I have to figure out how to let the bs2 now how long the train is>>>...
  • DataJDataJ Posts: 23
    edited 2009-04-27 18:05
    Thank you for your reply. . .·After some fairly extensive reading this week-end, it appears that what you and I are doing·will require·more computing power than what any microcontroller can handle.

    For example, we both need a way to either count the cars or the events and then do something or go
    to a pre-defined sub-routine.

    However, as the reference manual indicates, that Stamp runs through the program, looking for whatever
    is true and responds accordingly to that input.· However, when a second event occurs on that very same
    detector there is no way I have found for it to recognize that as a second event.

    It seems to me that what is needed·is a means to hold·an event or count·in "memory" until triggered
    by the next event or count, and again, counted and held, pending the next event or count, and so on.

    Then, for example, if the events or the count equal some number, then there would be a program
    instruction to would direct the·Stamp to the proper sub-routine.

    A potential option·might be·to use a microcontroller capable of handling "interrupts".· However, from what I
    read, an interrupt, when triggered, stops the current program, drops to a pre-defined sub-routine, and then
    returns where it left off.

    That might work, but, my knowledge with this equipment is limited - - we both may need a computer to handle these kinds of activities.

    I have searched all over the web and have few articles dealing with controlling model trains solely
    with a microcontroller.· That·almost leads me to the conclusion that it simply cannot be accomplished.

    By the way, here·are a couple of interesting model train sites you might enjoy:··JLCEnterprises.com and the other is Model Electronic Railway Group, or MERG.org.uk
  • ManetherenManetheren Posts: 117
    edited 2009-04-27 18:16
    This is a very neat Idea and I would also like to complete this, but with all my HO model trains about 1300 miles away it would be hard.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Manetheren
  • DataJDataJ Posts: 23
    edited 2009-04-27 23:24
    I don't have any photos, but it is nothing more than a 12" x 60"·rectangle constructed from 1" x 4" x 60" long pieces of·lumber, with a 3/16" thick piece of tempered hardboard attached to the top for the working surface,
    or "land" area.

    The servos are mounted beneath the 3/16" hardboard top; actuaction is handled by a model aircraft·clevis fitting attached to the servo horn with a 2-56 threaded rod extending beneath the throwbar.· The throwbar has a .035" hole drilled in the throwbar,·thrrough which the .035 music wire extends.

    The·transformers·are attached along the inside·perimeter of the 1 x 4's.

    I tried sending attaching a .jpg of the trackplan that I canned, but, the website timed-out.

    By the way, Page 105 of the Stampworks Manual lists code for counting external events, however, they are
    using a pulse generator.

    This is where things began to get confusing.

    By the way, the Stampworks manual is available for downloads at Parallax, Store, Books, Stampworks Manual.
    ·
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-04-28 01:16
    DataJ
    For example, we both need a way to either count the cars or the events and then do something or go
    to a pre-defined sub-routine.
    ·
    However, as the reference manual indicates, that Stamp runs through the program, looking for whatever
    is true and responds accordingly to that input.· However, when a second event occurs on that very same
    detector there is no way I have found for it to recognize that as a second event.


    Here try these two routine and see if you can get this to work for you



    Chg··· PIN··· 0·········· You would use this instead of IN0
    cntr·· VAR··· Word


    · cntr = 0


    · DO
    ··· ' do other loop stuff
    ··· cntr = cntr + 1 * Chg············ 'If input stays HIGH· then EXIT
    ··· IF (cntr = 300) THEN EXIT······ 'The (cntr = 300) will need to be ADJ for how long it that the car to pass
    · LOOP····································
    ·'·the IR detector

    ············································· OR


    Chg··· PIN··· 0························ 'You could use this to count the pauses between cars
    cntr·· VAR··· Word


    ·cntr = 0
    · DO
    ··· ' do other loop stuff
    ··· cntr = cntr + 1 * (1 - Chg)······· 'If input stays LOW then EXIT
    ··· IF (cntr = 300) THEN EXIT
    · LOOP

    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 4/28/2009 1:37:45 AM GMT
  • Radridz3Radridz3 Posts: 49
    edited 2009-04-28 01:31
    My layout is 10x 6 and has multiple levels on it theres about 60-70 pieces of flex track so im dealing with alot of scale miles.. All the computer programs out on the market for model trains don't allow you to run more than 2 lines above or below each other so using a com wont work plus I was trying to have this layout automated without having it hooked to a com.. My layout already has 4 DIY BS2's onboard. 1 is for a emergency stop system that keeps trains from hitting each other when they get to a leadin so that way when my rfid system (BS2 #2) reads tags it changes certain switches to keep certain trains on perticular lines. So the emergency system stops 1 train before it gets to a switch ..The other bs2 runs lighting and dimmer controls and the 4th is the brain for the PIR Yard system. If you shoot me a email at radridz3@hotmail.com maybe we can conspire on getting this to be a reliable system. I am a beginner+ when it comes to coding and to tell you the truth I dont really pay attention to most of the bs2's commands. The other thing is Im using all DCC and I also use twin coil , servo, and stepper motors for switching. Just kinda trying to get away from twin coil but thats what I originally started with. So I've been slowly switching over to slow switchhing controls. Layout has 24 swithces ...My hole system runs on 3 power districts with 2 boosters and a 30 amp BK Precision Digital power system. I do not use any digitrax or any on the market over priced DCC sytem stuff. Unless I need a drop in decoder or something but most are wired in's..... My layout will run upto 100 trains but I only run 8-10 with about 200 pieces of rolling stock. The layout runs 8 flawless without me doing anything and I still have the ability to change switches manually fromm my commander and don't have to worry about wrecking expensive trains.....My Loco fleet is all (Atlas Southern Pacific Widow Makers all road numbers and models.) Im a big diesel kid as you can tell. Let me now what you come up with on the code....
  • DataJDataJ Posts: 23
    edited 2009-04-28 15:39
    Thank you sam_sam_sam for the code - - that looks like the answer to the various questions that
    Manthern, radridz and I are looking for.

    I will give it a try·- - it will probably take me quite a while to wander through this and experiment.

    Regards,
    Jim
Sign In or Register to comment.