Shop OBEX P1 Docs P2 Docs Learn Events
BS1 Application advice — Parallax Forums

BS1 Application advice

ssandessande Posts: 23
edited 2012-03-07 11:49 in BASIC Stamp
Hello, this is my first post and first Basic Stamp project so please forgive me if some of my terminology or understanding is a bit out of whack. I am using a BS1 to develop a very basic traction control unit for a custom vehicle I made. I selected the BS1 due to its longer “no-pulse” timeout of .65535 seconds. The vehicle is slow moving with a top speed of 12mph so this does not raise any concerning safety issues. This vehicle is driven by the left and right rear tires each using a hydraulic motor (connected in parallel). This allows for some differential action while turning (i.e. one wheel can spin faster than the other), however it also creates a situation if one tire loses traction it will spin freely while the other remains stationary resulting in loss of forward motion (basically an open differential condition).

What I need the traction control to do is recognize when one tire speed exceeds the others by 31% and activate a flow valve which will force hydraulic fluid to both wheel motors (essentially creating a locked differential). I have installed four magnets 90 degrees apart in both the left and right axles so I can monitor the speed of each tire. I have calculated the minimum turning radius and inner and outer tire rotations and found the ratio to be a maximum of 26%. If the speed difference of the left and right tire exceeds 26% I know it is due to tire slippage. I am adding an additional margin of 5% to the 26% as an added buffer. Once the flow valve is triggered it will remain on for X seconds after the tire speed ratio is <31%. So with this background here are my questions:
  1. When comparing the initial values of each tire speed the values will not populate at the exact same time and one will be a zero. Ideas on how to handle so I do not get a false trigger each time I start rolling? I can’t wait for values greater than zero since one wheel may really not be moving or moving under the threshold of .65535 seconds between pulses (approx 1.26mph in my case).
  1. I plan to use a counter in the program where it must see the >31% condition X number of times in a row before activating the flow valve to reduce any false triggering due to erroneous data.
  1. The .65535 second timeout on the pulsin input is a limitation since this is a slow moving vehicle. Any speed under 1.26mph it will timeout and return zero speed. Would it be possible to incorporate a routine that repeats 2-3 times at .6553 seconds (just before the timeout) and add .6553 seconds to my time variable each time it repeats? Seems like this might be a work around to the short timeout limitation and still retain the timeout functionality.
Has anyone done anything like this? Any code examples, ideas, and help debugging would be appreciated. Thanks in advance!

Scott
«1

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-01-04 17:12
    1) You have an additional bit variable that is 1 if the corresponding tire speed is valid. This is initially zero and is set to 1 by the measurement routine.

    2) Good idea. You would increment the counter each time a >31% value is measured and reset it to zero if the value is <32%.

    3) You can't interrupt the PULSIN operation. The Stamp basically hangs when it's doing a PULSIN until it times out or the pulse ends. You could use the timeout itself as a "tick" and repeat the PULSIN until it doesn't time out. This isn't perfect in that a pulse could start between one PULSIN and another and you'd miss the new pulse. You could program the PULSIN process and have a loop that would wait for the leading edge of a pulse, then wait for the trailing edge. You'd use a PAUSE 50 or PAUSE 100 as a time "tick" and increment a counter with each loop checking for your own timeout (count) limit.
  • ssandessande Posts: 23
    edited 2012-01-09 11:54
    Mike, thanks for your reply!
    Regarding your comment on item 3, I assume there are no timing issues when using a single BS1 module with two pulsin inputs that may be timing out? I am trying to read two different pulsin inputs and comparing the RPMs to each other.

    Scott
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-09 17:08
    Scott,

    Are you using a hall effect sensor on the wheels? If this is going to work, you cannot have any glitches, so you will need solid state detection (like a hall effect) and you may need some hysteresis (but we can talk about that later).

    Let me get this straight:

    You are monitoring two wheels - one on the left and the other on the right. This is not a 4 wheel drive, correct?

    The BS1 sounds like a good fit for this function. Give me some time and I will throw some code ideas your way.

    Paul
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-09 18:40
    Scott,

    Here is some code to get you going.

    Paul
  • ssandessande Posts: 23
    edited 2012-01-09 19:56
    Paul, many thanks for the sample code! It may take me a while to sort through it. Since I have some unused pins I planned on incorporating some LED's on the case that illuminate at 10% 20% 30% 40% 50%, Also a LED to indicate when the differential lock has been activated. In the event something flakes out I will have some status information. Below is the graphic I came up with.
    TCU.JPG
    470 x 350 - 33K
    TCU.JPG 32.6K
  • ssandessande Posts: 23
    edited 2012-01-09 20:11
    If anyone is interested, here is a pic of the vehicle I made that the traction control is going on. It is self-powered, power steering, driveable from either front left or right side, lights, sound system with 4 sub-woofers. Party machine!

    Bar2.jpg
    1024 x 1231 - 155K
    Bar2.jpg 155.5K
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-09 20:18
    Scott,

    I like your level of details in your documentaion! Nice work!

    Remember, the BS1 only has 8 IO pins.
    1 for Left Monitor
    1 for Right Monitor
    1 for Traction Control
    5 for Status
    Total 8 (no spare)
    If you ever need an IO for something you can lose a LED or two. Parallax has a multi color LED that can generate thousands of colors and it only takes 1 IO

    With 1 IO you can do the same thing and only one LED.
    For example: Bright Green 10% ........Light Green 20% White 30% Pink 40%......Red 50%

    All too often BStamp newcomers hook up a few LEDs and can't figure out why their Bstamp resets on its own - it is because to much current on the IO pins causes ints internal voltage to sag and that causes it to reset.

    Remember, BS1s and BS2s can only drive roughly about 50mA total on the IOs, so you would need to add transistors to drive the LEDs. More later on that.

    If you run out of program space, variables, or IO, you can switch over to a BS2 (my PStamp of choice). But for now try to get it all to fit in the BS1. I can help you convert to BS2
    if the need arises. (which has a similar but more powerful and flexible command language)

    I'm off to bed.
    Let me know how its going tomorrow.

    Paul
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-09 20:21
    Scott,

    Hey! Its a Rolling Bar!!!! Now that is a worthy project.

    I'll have a shot of "Polish" - Very Sweet Blackberry Brandy made by Leroux.

    Ask me sometime about my 2011 Fatboy Low that I had for a day - long story.

    Paul
  • ercoerco Posts: 20,256
    edited 2012-01-10 09:08
    Sweet ride, Scott!
  • ssandessande Posts: 23
    edited 2012-01-10 11:11
    Paul, looking over your example code I "think" I am using a simpler method for calculating the RPM difference between the left and right wheels (I say I think because I am still sorting through and learning the coding). It really doesn't matter if we use rpm, mph, time, etc, it is the ratio between them that triggers the differential lock. I picked RPM since it is a unit I have a feel for when testing. Looking past all the syntax and errors, below is the logic I used. The serial routine (not show) displays the RPM for the left and right wheel and the percentage (simply a terminal tool for debugging/validation phase). The Check routine checks for ratios larger than the setpoint and turns on the flow valve, and the LED routine drives the 10% 20% 30% 40% 50% and differential lock LED's. Made these sub routines so that I could easily bypass them in the main code by making that line a comment during testing. I know I need an adjustment to the calculations to get RPM since I am using 4 magents per wheel. Thoughts on this logic approach?

    tcu.bs1
    ' The BASIC Stamp uses pulsin to read left and right axle rpm.
    ' Pulses in on pin 7 and 8; data out via 2400-baud serial on pin 0.
    input 7
    output 0
    input 8
    output 0
    Monitor:
    pulsin 7,1,L1 ' Take left axle pulse sample.
    if L1 > 6553 then Timeout ' Avoid overflow when L1 is multiplied by 10.
    pulsin 8,1,R1 ' Take right axle pulse sample.
    if R1 > 6553 then Timeout ' Avoid overflow when R1 is multiplied by 10.
    let PCT=L1/R1 ' Calculate percentage.
    If PCT>1 then ' If left axle rpm is greater than right inverse percentage
    PCT=1/PCT
    let L1 = L1/100 ' Dividing L1/100 into 60,000 is the same as dividing
    let L1 = 60000/L1 ' L1 into 6,000,000 (60 seconds in 10us units).
    let R1 = R1/100 ' Dividing R1/100 into 60,000 is the same as dividing
    let R1 = 60000/R1 ' R1 into 6,000,000 (60 seconds in 10us units).
    gosub Serial
    gosub Check
    gosub LED
    goto Monitor
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-10 19:06
    Scott,

    Nice work! This looks sound to me, but I have not looked at the math in detail - that can be worked out later.

    Your code compiles and I included some tips as comments.

    You will need to drive the LEDs with a transistors (2N2222A is a old standby transistor for this).

    You will also need to drive the Differential Lock solenoid (or whatever it may be). I can help you with that if you need it.

    Paul
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-11 19:18
    Scott,

    There are a few ways to "emulate" multitasking in a PStamp. I find the best way to do this is to "time slice" each task for a short peroid of time.
    The PULSOUT command (to flash the LED for a short time for example) stays at that command until it is done (it is not a concurrent process). PStamps are very simple microcontroller devices - they don't have the architecture of a modern microprocessor that can multi-task very well.

    Attached is some code that will compile for the BS1. I am not sure if it works but it should demonstrate the concept of time slicing to give the psuedo effect of multi-tasking.

    If you need true multi tasking, the Propeller series from Parallax is the way to go - the programming language is a little lower level then PBasic but it is more powerful - and some code has to be written in assembly code (if you have never written assembly code before, the learning curve is a bit longer then PBasic).

    In the mean time you still may be able to do what you need in the BS1 (or the BS2 if need be). The PBasic command set is a little more robust for the BS2 than the BS1.

    For example: The BS2 supports IF...THEN... ELSE, the BS1 only supports IF...THEN "goto label"

    Paul
  • ssandessande Posts: 23
    edited 2012-01-12 07:07
    Ok, I see what you are doing in the code. After gaining a little more understanding of how the pulsin function works I think I may need to re-evaluate my wheel sensor setup. Currently I am planning on using 4 magents on the axle that are even spaced (90 degrees apart). Because of the pulsin limitation of .655 seconds this gives me a minimum speed sensitivity of 23 rpm (1.26 mph). Since this is a slow moving vehicle I will likely be hitting the timeout on the pulsin function which to my understanding will basically hang the basic stamp until it gets a pulse or times out. Using the same basic stamp for both wheel inputs compounds this issue.

    So, I came up with a rotor design I can slip onto the axle which has 64 segments. This would give me a minimum sensitivity of 1.43 rpm (.08 mph) at 0.655 sec between pulses. The maximum speed of 218 rpm (12mph) would yield 0.069 sec between pulses. This seems like a much better approach. The Basic Stamp will spend less time waiting for the pulsin signal and free up some computational cycles. Below is my proposed rotor design, however I am not sure of the hall sensors pickup limitations? The arc length of each segment is about .107" with a simialr sized gap. Thoughts?
    rotor for sensor.jpg
    374 x 350 - 16K
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-12 12:19
    Scott,

    I was thinking the same thing. You may have to make each node pointed (like a triangle) and find the sweet spot for the Hall sensor.

    You should do this before you try it on a axel. A wooden jig could be cobbled up. Your peaks and troughs may closer than if you were using the 4 nodes as you originally intended, but an Op Amp with a lot of gain (and a little low pass) should get things back to TTL levels.

    If the Hall sensors won't work with the 64 node ring (even after conditioning the signal). You could try optical (but that may not be the best choice for your environment).

    Another trick is to go back to 4 magnets (nodes) and use two sensors a little more or less than 90 degrees apart and measure the time between the pulses. Another way is using your 64 node ring and another 64 node ring outside of it and wrapped with a coil around it. When the nodes line up you get the biggest peak (but this would be inductive and the Hall sensor would not work well in this case). There are all sorts of ways to solve this.

    Paul
  • ssandessande Posts: 23
    edited 2012-01-12 16:06
    I can make the sensor ring any shape or size needed. Pointed tips or small flats are no problem. I would like to use a threaded cylinder type sensor so it is easy to mount and adjust the distance.

    I am planning on building a board to mount the axle sensors to so I can test during development.
  • ssandessande Posts: 23
    edited 2012-01-20 10:26
    Just a quick update. Still working on the Traction Control Unit. Have the code mostly done and am just setting up the circuits and prototyping the sensors for testing. Created some logic to check for "out of bounds" data conditions and revised the LED indicators.

    TCU Faceplate.jpg
    468 x 347 - 34K
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-21 13:44
    Scott,

    Great! Send me an e-mail if you need any advice. paul@romsky.com

    Paul
  • ssandessande Posts: 23
    edited 2012-01-27 06:37
    A quick question... I am making a sensor ring as pictured below to be used with a 3 wire inductive proximity switch. The trigger faces will have equal distances as the gaps so my line of thinking is that I do not need any type of flip flop circuit to give me a reasonably square wave input. Is this reasonable? This application will be measuring under 250 rpm, so I do not think any timing error would be significant.

    Also, the sensors I am using have a voltage range of 6-36v. If I run the sensors at 12-14.5 volts is there anything special I should be doing to the sensor output to ensure a 5v signal to the BS1? Is a simple voltage divider adequate?

    Thanks,
    Scott
    rotor for sensor.jpg
    374 x 350 - 16K
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-29 18:12
    ssande,

    Yes, a resistor divider network will work but 12V to 14.5V sounds a lot like a automotive application (an electrically noisy environment). You should use a 5.1V zener diode just in case the voltage goes up to 36 V (very narrow noise spikes can reach this level and weaken and/or destroy a TTL input - like a PStamp's I/O). A resistor divider will work but as the vehicle voltage varies, your noise margin to the TTL input changes. Also, if the voltage goes higher for any reason, a resistor divider will not limit the voltage, and if 5.2V or more makes it to the I/O pin, the PStamp will be damaged.

    See attached for a typical Zener Limiter circuit used for TTL inputs.

    Paul
  • ssandessande Posts: 23
    edited 2012-02-02 07:28
    Paul, as usual THANKS!
  • ssandessande Posts: 23
    edited 2012-02-02 10:58
    Next question.....
    I am using a PIN out on the BS1 to switch on a 2N222 transisitor which in return triggers an adjustable timer module. This is a purchased 12v timer module which uses a relay to control a higher load. It is triggered by an input wire going to ground. My question is how do I size the base resistor for the transistor without knowing the load of the input line on the timer module? I could use trial and error, but would prefer not to have an issue down the road if I pick a marginal resistor value. I don't have much information on the timer module except a wiring diagram.

    Scott
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-02-02 17:38
    Scott,

    Do mean a 2N2222 transistor?

    To determine the Base resistor for any biploar transistor, you start by looking at the data sheet.

    Think of the Base-Emitter (B-E) junction like a regular diode. If you don't limit the current, you will blow out the diode (just like my slide for LED series resistors - it's the same concept) thus destroying your transistor. But you don't want the resistor on the Emitter because it will also limit the current that will flow from the Emitter to the Collector. So in the Common Emitter configuration of the transistor (I can talk about that later), the current limiting resistor for the B-E junction should be on the Base (just like you are doing).

    In the transistor's datasheet, look for Vbefwd (Base-Emitter Foward Voltage), and for Ibsat (Base Saturation Current).
    The 3rd parameter you need is the Voltage to the transistor's Base before the resistor - you know this already, it is 5V, the BS1 Voh (Output High Voltage).

    Example: Let's say that a transistor (not the 2N2222 in this example) has:
    Vbefwd = 1.2V
    Ibsat = 800mA

    and your BS1 has:
    Voh = 5V

    Since the B-E junction drops 1.2V, then the Base Resistor must drop 3.8V.
    And since 800uA must flow through the Base to fully turn on the transistor into saturation (C-E juntion resistance is lowest - conducting), calculating the Base Resistor is simple:

    The Base Resistor and the B-E junction of the transistor form a simple series circuit, so...

    Kirchoff's Law:
    In a series circuit, current is the same through each point in the circuit.

    If 800uA (800 micro amps) flows through the B-E junction (the diode), then 800uA will flow through the Base Resistor.

    From Ohm's Law:

    R = E / I
    R = 3.8 / 0.0008
    R = 4750 Ohms (4.75K)
    Since your data sheet will tell you that your Ibmax (Base Max Current) is something like 2mA, you can use a standard 4.7K Ohm resistor (a little lower resistance than you need but you can over-saturate the Base and not damage the transistor).

    Now what size (Wattage) resistor would you need:

    Watt's Law:
    P = I * E
    P = 0.0008 * 2.8
    P = 0.003 W (3 mW)

    So a 1/4 W (0.250 W or 250 mW if you will) resistor can handle the load.

    In this case (for this imaginary transistor), I would use a 4.7K 1/4W 10% Tolerance Resistor (costs about 10 cents).

    Look in the datasheet for Icemax (Collector-Emitter Max Current) to see if your transistor can meet the demand of your load (100% duty cycle).

    I need to add a slide for this.

    Paul
  • ssandessande Posts: 23
    edited 2012-02-10 07:04
    Just a quick update on my progress. I have completed the coding for the BS1 and have run several different sets of data through the program to simulate different conditions. This data was hard coded into the program and not from the sensors via the Pulsin command. All seem to work as desired. Added some Debug commands in the routine to see different values and such to verify.

    Now onto the sensors... I had a few sensor rotors laser cut for testing. My initial design was to make the rotor segments and gaps equal so that I would get an approximate square wave output of high and low as pictured below:
    IMG_1339.jpg

    Unfortunately this did not work out as planned. The sensor pickup field is larger than the gap, so it sees the raised tabs on either side of the gap and never changes state. So with that sensor limitation I removed every other tab to create a larger gap:
    IMG_1342.jpg

    This setup does provide enough gap to allow the sensor to change state from high to low. The downside is that I raise the minimum speed that the sensors start to record data because of the Pulsin timeout feature. So my next steps will be to write a program that reads the high and low times and compares their times. Ideally looking for a 50% split between high and low signal to approximate a square wave time interval. Depending on those results I may need to redesign the sensor rotor with different spacing. Then verify the sensor output at the min and max rpm range and finally put the live sensor data into the Traction Control program and verify the operation. I will have two test fixtures with motors driving the sensor rotors using an adjustable speed control. I have a hand held tachomoeter to verify the speed of each motor and compare to the data in the program.

    Scott
    1024 x 768 - 85K
    1024 x 768 - 102K
  • ercoerco Posts: 20,256
    edited 2012-02-10 09:37
    Scott: It might be more productive to find a smaller sensor than cut tabs out of your disk.

    Fortunately you had the option to remove every other tab, since your original disk had an even number of tabs! :)
  • ssandessande Posts: 23
    edited 2012-02-10 09:47
    Agreed, that is also an option. I need to do some research to see how the pickup field area is quantified in the proximity sensor specifications. I had a handful of the rotors laser cut, so I have extras that have been unaltered.
  • 1taz1taz Posts: 2
    edited 2012-02-11 21:18
    could you get ABS sensors out of a car thet are about 1/2 to 3/4 " dia. they pick up down word of 1/32 in between each tooth on the gear have seen some with around 180 teeth on the gear, & vary cheep in salvige yards

    good work so far I really like the idea
    cool ride
  • bsnutbsnut Posts: 521
    edited 2012-02-12 23:03
    Since you have extra rotors that have been unaltered, you may want to try a smaller proximity sensor like a 8mm. This size of proximity sensor is able to give you the pulse train that you need. I also have another idea for you that you can try and that is a serial display to display the info about how much slip and other status info and it only needs one I/O pin.

    I like your cool idea, bar on wheels that brings the drinks wherever you need them.

    BTW, 1taz welcome to the forums
  • ssandessande Posts: 23
    edited 2012-02-14 12:54
    I am using 6 LEDs to indicate slippage in 10% increments, data error, data recieved, and posi traction activated. My thought is that these are quite visible in the field. However, I do like the idea of having actual values displayed on an LCD screen. One benefit is that it would free up some pins that I could use to adjust the slippage percentage in the field by using some switches instead of reflashing the BS1 with new values. How many lines would this LCD display?
  • ssandessande Posts: 23
    edited 2012-02-16 10:56
    ssande,

    Yes, a resistor divider network will work but 12V to 14.5V sounds a lot like a automotive application (an electrically noisy environment). You should use a 5.1V zener diode just in case the voltage goes up to 36 V (very narrow noise spikes can reach this level and weaken and/or destroy a TTL input - like a PStamp's I/O). A resistor divider will work but as the vehicle voltage varies, your noise margin to the TTL input changes. Also, if the voltage goes higher for any reason, a resistor divider will not limit the voltage, and if 5.2V or more makes it to the I/O pin, the PStamp will be damaged.

    See attached for a typical Zener Limiter circuit used for TTL inputs.

    Paul

    What are your thoughts on using a opto-isolator instead of teh zener diodes? This would keep 12v on one side and 5v on the other. Just asking because I think I have some opto-isolators left over from a different project.
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-02-20 19:44
    ssande,

    Yes,

    Opto-isolators are a better way to go, just more circuity involved. Zeners are quick, easy, and effective. Since you already have the isolators and know how to hook them up, then go for it!

    Paul
Sign In or Register to comment.