BS1 Application advice
ssande
Posts: 23
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:
Scott
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:
- 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 cant 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).
- 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.
- 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.
Scott
Comments
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.
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
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
Here is some code to get you going.
Paul
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
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
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
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
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
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?
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
I am planning on building a board to mount the axle sensors to so I can test during development.
Great! Send me an e-mail if you need any advice. paul@romsky.com
Paul
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
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
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
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
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:
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:
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
Fortunately you had the option to remove every other tab, since your original disk had an even number of tabs!
good work so far I really like the idea
cool ride
I like your cool idea, bar on wheels that brings the drinks wherever you need them.
BTW, 1taz welcome to the forums
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.
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