Can clever coding achieve this?

Shafto

Senior Member
I'm sure most of you know about my project already, if not here's a brief summary:

I'm using a 28X1 to create a controller for automotive LED tail lights that use sequentially flashing signal lights and PWM controlled marker lights that go to full brightness when brakes are pressed.

Here's the code:

Code:
main:
	
	readadc 0,b0		   'signal fade in time

	readadc 1,b1		   'signal fade out time

	readadc 2,b2		   'PWM duty cycle for marker lights
	  b3 = 4
	  w1 = b2 * b3

  	
	  If pin4 = b4 Then	   'No change in pin 4 (marker lights off)
  	  If b4 = 1 Then		   'Pin 4 is high      
  	    PwmDuty 1, w1		   'Update duty only   (adjust duty cycle if marker lights are on)
  	  End If
  
 	 Else				   'Pin 4 changed
    	b4 = b4 ^ 1                'Update b4 to reflect pin 4
   	 If b4 = 1 Then   	   'Pin 4 went high ...
   	   PwmOut 1, 255, w1  	   'Start PWM
   
 	 Else                 	   'Pin 4 went low ...
 	     PwmOut 1 off      	   'Turn off PWM
		 low portc 1
    
 	 End If
 	 End If


	if pin0 = 1 and pin3 = 1 then flashhazard

	if pin0 = 1 then flashleft

	if pin3 = 1 then flashright

	if pin0 = 0 and pin3 = 0 then main



goto main

flashleft:

	high portc 7		     'turn v.regs on for left side  

	high 0			     'first bank of LEDs high
	  pause b0			     'pause for fade in time
	high 1			
	  pause b0
	high 2
	  pause b0
	high 3
	  pause b0
	high 4
	  pause b0
	high 5
	  pause b0
	high 6
	  pause b0
	high 7
	  pause b1			     'keep last bank high for fade out time
	
	low 7				     'last bank to turn on now goes off
	  pause b1			     'pause for fade out time
	low 6
	  pause b1
	low 5
	  pause b1
	low 4
	  pause b1
	low 3
	  pause b1
	low 2
	  pause b1
	low 1
	  pause b1
	low 0
	  pause b1

	low portc 7			     'turn left side regs off

	goto main

flashright:

	high portc 6		     'turn v.regs on for right side  

	high 0			     'first bank of LEDs high
	  pause b0			     'pause for fade in time
	high 1			
	  pause b0
	high 2
	  pause b0
	high 3
	  pause b0
	high 4
	  pause b0
	high 5
	  pause b0
	high 6
	  pause b0
	high 7
	  pause b1			     'keep last bank high for fade out time
	
	low 7				     'last bank to turn on now goes off
	  pause b1			     'pause for fade out time
	low 6
	  pause b1
	low 5
	  pause b1
	low 4
	  pause b1
	low 3
	  pause b1
	low 2
	  pause b1
	low 1
	  pause b1
	low 0
	  pause b1

	low portc 6			     'turn right side regs off

	goto main

flashhazard:

	high portc 7		     'turn v.regs on for left side
	high portc 6		     'turn v.regs on for right side  

	high 0			     'first bank of LEDs high
	  pause b0			     'pause for fade in time
	high 1			
	  pause b0
	high 2
	  pause b0
	high 3
	  pause b0
	high 4
	  pause b0
	high 5
	  pause b0
	high 6
	  pause b0
	high 7
	  pause b1			     'keep last bank high for fade out time
	
	low 7				     'last bank to turn on now goes off
	  pause b1			     'pause for fade out time
	low 6
	  pause b1
	low 5
	  pause b1
	low 4
	  pause b1
	low 3
	  pause b1
	low 2
	  pause b1
	low 1
	  pause b1
	low 0
	  pause b1

	low portc 7			     'turn left side regs off
	low portc 6			     'tuen right side regs off

	goto main
If you look at my schematic seen here:
http://www.picaxeforum.co.uk/showthread.php?t=8189

You'll see that the PWM is send to switching voltage regulators.. when brakes are applied this is completely separate of the picaxe.. the signal just goes straight to the switch on the regulators and overrides the PWM signal switching them on full and giving the LEDs 100% duty.

What I would like to do is be able to also control the brightness of the brakes by PWM so I can perfectly match them to stock brightness.. unfortunately I don't know of a way I can code this.

Using an interrupt command doesn't work because if the signals are flashing and the brakes are applied the signals would stop flashing... but obviously the brakes coming on needs to be instantaneous.. so I can't wait for execution of code...

...hmm Funny how sometimes writing something out sometimes give you your own solution.. I just thought about using a PWMout command under an init: header for the brakes using the other PWM pin and then use a opto isolator or a transistor to switch on the PWM signal to the switching pin of the regulator...

That may work well.. maybe not an opto isolator though.. because then I would need to wait for the LED in there to light up.. I want the fastest switching possible.. that's one advantage of LEDs.. the fast on time can save you 20m stopping distance at highway speeds compared to incandescent.. I don't want to negate that advantage.

So maybe that's the way I'll do it.. suggestions?
 

kevrus

New Member
Well you could always use the PWM output of an 08m to control brakelight brightness, this would be totally seperate to the 28x and then the coding is simple to play about with, even using a potetometer on ADC input to vary the PWM to suit. Not much more hardware to add.
 

Shafto

Senior Member
response time of an LED is only 20nS, so 3uS is adding quite a bit... but I can't find any info on how fast a transistor switches... doesn't seem to be in the data sheets.

I don't think I need another 08, I just rigged up another POT on the last ADC input and used the other PWM out pin to the switch on the reg.. it works great manually connecting the second PWM pin that's just going all the time to the give the LEDs more duty cycle... I just need to electronically switch that on now.. odd I never thought about doing it like this until I started writing the thread.. I suppose I've figured this out myself without much ado.

...now I'm thinking there's probably a relay for the brakes.. when you hit the pedal it switches power to the brakes? that would take up lots of time... since the brake wire will only be a signal wire now I could eliminate that relay.. if there is one.. maybe it's just a high amp switch.. I'm not really sure.
 
Last edited:

hippy

Technical Support
Staff member
response time of an LED is only 20nS, so 3uS is adding quite a bit
I think you're losing your grasp on real world scale [1]. Even at 120mph/190kph, 3uS only equates to a stopping distance of 0.16mm, the width of two to three human hairs [2].

While LED switching is faster than filament bulbs and relay combinations, translates to a stopping distance of some 5 metres ( at 120mph/190kph), it really only gives a few tenths of a second extra time for a driver to react in. If their destiny is to crash, I doubt that will save them or you. Faster switching time does not make anyone a better driver; if they were driving safely they would be able to stop in time regardless.

Even so, saving 200 milliseconds of switching time does make sense. Trying to save a further ten millionth of that does not.

[1] Reminds me of the story recounted in Tracy Kidder's The Soul of a New Machine ( well worth reading ) where an engineer dealing with sub-nanosecond timings of the computer finally threw it all in, leaving a note which read; "I'm going to a commune in Vermont and will deal with no unit of time shorter than a season".

[2]As any decent driver knows; they can stop from any speed under any conditions to within that tolerance ( usually at that tolerance ) and avoid a collision whether awake or half asleep, but more often subconsciously. When that tolerance cannot be achieved it is the fault of the diver in front.
 

moxhamj

New Member
Re: "but I can't find any info on how fast a transistor switches" the info in transistor data sheets is listed as the maximum frequency "FT". As an example a BC547 has an FT of 300Mhz. 1Mhz is 1us and 1Ghz is 1ns and 300Mhz is 3.33ns. Light travels an appreciable distance in that time but not your average motorist. LEDs and transistors and even picaxes will be easily fast enough compared with human reaction times (and incandescent lights which I agree are slower than leds, though they come on a lot quicker than they turn off).

I pulled up behind someone the other day who had one of those "baby on board" signs except that instead it said "Warning, I drive like you".
 
Last edited:

Katzenjammer

New Member
In a driving simulator, responding to an emergency requiring braking or turning, the average time for a male in peak physical condition to start reacting is on the order of 700msec.
 

manuka

Senior Member
High level "eye height" LED based brake lights improve the response times of following driver(s), & car makers are progressively adopting LED lighting due to both this & greatly improved reliability. See the likes of => www.msnbc.msn.com/id/9516937/ Aside from enhanced brightness, LED efficiency & ruggedness is most appealing too, & of course they can readily be distinctively driven.

It's sobering to ponder that a driver's "cocoon" is linked to fragile filaments that may fail at any time. Rough roads in many lands make this even more of a daunting prospect...
 

Shafto

Senior Member
700ms? maybe if you're 90...

Here's a study of incandescent bulbs vs LED for reaction time:

http://www.visteon.com/utils/whitepapers/2002_01_0379.pdf

Some great info there... I must have confused my 20 meter claim with 20 feet I saw somewhere.. as 20 feet (or just over 3m) is the actual distance that can be saved on the highway.... now that I actually think about the distance 20m would be ridiculous..

The advantage of LEDs is clear.. they prevent accidents and increase reaction times significantly.

Thanks Acula for explaining that to me, I understand now... I'll be using a transistor then.. I figured they must switch quite quickly.... So I HAD everything figured out... BOO for me, I think I burnt out the second PWM pin.. I was fussing with an alligator clip that was plugged into pwm pin 2 and I dropped the clip onto the board while it was on. = ( pwm 1 still works but no pwm 2.... oh well.. I just ordered a 40X1 to replace this 28.. I was running out of pins anyway and I want to be able to add cool effects later on.. like the sequential arrays pulsing out with music or something for showy stuff.... I'll use this half broken 28x for my front signals when I do them... they'll only need the 1 pwmout.
 
Last edited:

andrewpro

New Member
Interesting paper. However, I see a number of flaws int he test.

1) they only measured the time for the person to process the light comming on, essentially.

2) they did not measure the whole chain of reactions that need to take place in order for that to make any difference.


In the test, it was "see light, hit button". Ok, tha'ts great. However, if all I had to do was hit a button to stop the car life sure would be a lot different.

Now lets take a look at real life.

1) brake lights light on car in front of you.
2) you realize the lights have lit.
3) you process that this means the car is stopping.
4) you process that you need to do something to keep from smacking into them.
5) you process that you need to lift from the gas and apply the brake.
6) you lift your right foot from the gas.
7) you move your right foot over so that it's above the brake pedal.
8) you begin to apply the brake.
9) the brakes begin to engage and slow the car.
10) you process the feedback from your eyes and eustacian scillia as to whether or not you are stopping fast enough.
11) you adjust brake pressure accordingly so that you slow at a needed rate.
12) you again process your bodys feedback and decide whether evasive action is required.
13a) evasive action is required: You make a decision as to which direction to go. You glance at your mirrors (hopefully!) and pray nobody is in your blind spot. You initiate evasive maneuvers.
13b) No evasion is necessary, you continue to modulate the brake as required.
14) you process whether you need to continue braking at your current rate, or whether you can let up.
15) return to step 10 until you no longer need to slow the car.



Do you see the difference between real life and "see the lights, hit a button". With all that it going to go on, microseconds are not going to matter.


As a side note: Professional drag racers had to completely change thier staging and reactions when the NHRA moved to LED lights rather than Incandescent ones. They had thier launches so dialed that the length it took for the bulbs to come on at various temperatures, and the reaction times in various ambient lighting situations was factored into whether or not they would win a race.

I'm not saying there is no difference. It's quite obvious to anyone who has driven behind a car with LED stop lamps. All I'm saying is that a few microseconds, or even miliseconds, is not going to make much of a difference int he grand scheme of things for a normal every day drive in a safe, proper, and legal manner.

--Andy P
 

papaof2

Senior Member
I don't know how accurate human time difference perception can be (that's one way we determine the location of a sound) but we know that some people are better judges of speed, sound locations, etc than others. I think most people can see the difference in on/off times between an LED and an incandescant bulb. The speed of illumination probably won't make a difference in an accident occuring - the driver behind you either is paying attention and is prepared to respond or he/she is not.

"a normal every day drive in a safe, proper, and legal manner" - if your "every day drive" only encounters "safe, proper and legal drivers", I'm sure you haven't driven in the Atlanta area, where you'll often find the following:

1. Drivers read the numbers on the red, white, & blue Interstate highway signs as the minimum speed limit - the highways through Atlanta are I-75, I-85, and I-285 (vehicles have been clocked at over 150MPH on I-285).
2. Drivers assume that any distance between their vehicle and the vehicle ahead of them means that they are not going fast enough; thus there's someone behind you at 70MPH and you can't see the front bumper of their vehicle in your mirror.
3. If there's more than one car length between you and the vehicle ahead of you, the driver behind you will go to the "right turn only" lane long enough to go around you and catch up with the other vehicle (which is now stopped at a traffic light).

John
 

BeanieBots

Moderator
I'd be interested to know if any studies have done with to regard to the use of PWM vs continuous.
Certainly the human POV will make it appear continuous at those frequencies, but what about strobe effects with a car going over slightly rough terrain.
Is PWM LEGAL for use as a car break light?

@papaof2, it's the same in the UK
 

Shafto

Senior Member
I must disagree with your last statement andy pro... It's well proven they make a big difference... I'll try to find some more papers on it.. I've read quite a few.

There are already enough studies that relate to human reaction times behind the wheel.. that's well documented.. so the faster you see brake lights in front of you.. the sooner you can start your human reaction.

Interesting info about drag racing.. I hadn't thought about that.

Beanie as for PWM it's perfectly legal.. acutally it's commented on in that paper as one of the advantages of LED.. being able to achieve the perfect amount of light intensity. All of the high end OEM tail lights use PWM for marker light dimming... cheaper vehilcles with LED or the aftermarket LED truck modules you can get just use different resistors.. but PWM is the best way to go.
 
Last edited:

leftyretro

New Member
700ms? maybe if you're 90...

Here's a study of incandescent bulbs vs LED for reaction time:

http://www.visteon.com/utils/whitepapers/2002_01_0379.pdf

Some great info there... I must have confused my 20 meter claim with 20 feet I saw somewhere.. as 20 feet (or just over 3m) is the actual distance that can be saved on the highway.... now that I actually think about the distance 20m would be ridiculous..

The advantage of LEDs is clear.. they prevent accidents and increase reaction times significantly.

Thanks Acula for explaining that to me, I understand now... I'll be using a transistor then.. I figured they must switch quite quickly.... So I HAD everything figured out... BOO for me, I think I burnt out the second PWM pin.. I was fussing with an alligator clip that was plugged into pwm pin 2 and I dropped the clip onto the board while it was on. = ( pwm 1 still works but no pwm 2.... oh well.. I just ordered a 40X1 to replace this 28.. I was running out of pins anyway and I want to be able to add cool effects later on.. like the sequential arrays pulsing out with music or something for showy stuff.... I'll use this half broken 28x for my front signals when I do them... they'll only need the 1 pwmout.
"I'll use this half broken 28x for my front signals when I do them... they'll only need the 1 pwmout."

What, you only make right hand turns :D

Lefty
 

andrewpro

New Member
@ Papaof2: By you're statement, if someone said "African villiages are terrified of US Marines because they firmly believe that Marines eat babies", it's logical to conclude that "US Marines eat babies". You took the last 1/3 of the sentance and ran with it.

What I said was : All I'm saying is that a few microseconds, or even miliseconds, is not going to make much of a difference int he grand scheme of things for a normal every day drive in a safe, proper, and legal manner.

You chose to ignore the bold part. If you're not involved in a safe driving situation, a few miliseconds is not going to make any difference what so ever. That is what I was getting at with the statement.



@Shafto: I was referring only to THAT PARTICULAR REPORT, the flaws in using the reports information, and how it pertained to your claim that every microsecond counted. Not any other report or statistic or research. You're in a search for an insignificant amount of switching time, and it makes no difference what so ever.

--Andy
 

Shafto

Senior Member
Well you would be wrong then sir... every millisecond does count... why do you think there's such a big choke up about even having 1 beer and driving? (here anyway) because even that minuscule amount of alcohol can slow your reaction time by 25%, what's 25% of your reaction time? a few milliseconds.. enough not to crash is some circumstances.

Don't get me wrong here.. I'm not Mr. Safety. This was born from a brewing obsession I have with LEDs, love of my car, and the obvious aesthetic benefits of the merging of the two.. but extra safety is a great built in side effect.

So maybe the 3uS of an opto isolator doesn't make much difference compared to 3nS of a transistor.. but why wouldn't I got for the faster switching? faster the better...
 

Mycroft2152

Senior Member
andypro;55326@Shafto: I was referring only to THAT PARTICULAR REPORT said:
Since the human reaction time is on the order of 200 milliseconds (see google) your whole argument about 3 microseconds versus 3 nanseconds is absurd. You are talking of a3 and 6 orders of magnitude faster than humanly possible!

This is similar to the novice who is confused about acuracy and significant figures.

You may as well start dsicussing how many angels can fit on the head of a pin.

Stop wasting your time and just built it.
 

leftyretro

New Member
Since the human reaction time is on the order of 200 milliseconds (see google) your whole argument about 3 microseconds versus 3 nanseconds is absurd. You are talking of a3 and 6 orders of magnitude faster than humanly possible!

This is similar to the novice who is confused about acuracy and significant figures.

You may as well start dsicussing how many angels can fit on the head of a pin.

Stop wasting your time and just built it.
Or as they say, don't let perfect be the enemy of good. Or something like that ;)
 

Ralpht

New Member
I guess that in the real world, if 3uS makes the the difference between hitting the car in front or not, boy that car behind is too close for comfort.

How much damage will 3uS do to a car anyway. The bumper bent an extra 1/3 mm! Once you hit, you hit and it won't matter.

I was always taught that at any speed, if you keep a minimum of 2 seconds behind the car in front, with average reflexes, you can stop a car with plenty of space to spare. (assuming your car is roadworthy)

They even teach that in all the pre-driving classes and whilst learners are getting driving lessons, at least here in Victoria Australia.

So ultimately, it does not matter, just build it for the fun of it.
 

Shafto

Senior Member
I think the point was missed....

I didn't know the reaction time of opto isolator compared to a transistor.. I wanted to make sure that I wasn't negating the safety effects of the LEDs.. now I know that either way it's doesn't really matter... but I'll say it again.. why not got with the faster switching option?

The thread wasn't made to compare reaction time.. that just kind of came up..

About the 28X.. for the front, the amber LEDs will perform marker function and blinking, 1 array, not 2 different ones like the back. I'll only need to use pwm 1 for hpwm to dim the signals for marker function.. then full brightness as they blink.
 
Last edited:

hippy

Technical Support
Staff member
I think there's an entirely good argument for getting the lights on quicker, and especially if that gives reasonable extra time of advanced warning.

How effective that is I think depends more on the driver behind. Anyone who drives and is honest will admit that the first thought is often not to brake but think, "what's that &%£$%$ doing ?". What the LED intent is, is to wake the dopey sod behind up sooner, but whether it works in practice is debatable. The numbers all sound marvellous in terms of distance travelled, but just a few mS is nothing. Hundreds of mS is worthwhile, but may still not be effective. There's a good degree of hype from those with a self-interest in selling LED's and the safety message is always a good one. If they could argue it would protect against terrorism, cancer and hair loss I'm sure they would. Carlsberg don't make brake lights but if they did they would probably be the best in the world.

The big problem is that one's trying to protect from other's incompetance and that's never guaranteed to work, just like road deaths will never be eliminated until we turf over them and smelt down our vehicles ( and then we need to ban lamposts, baths, stairs, food ... ).

One theory I have is - remove the air bag and seatbelts and put a damned big spike on the steering wheel centre and everyone will suddenly start to drive a lot more safely. And we'll soon be rid of those who don't.

( And by safely I don't mean with any lack of speed. )
 
Last edited:
Top