Bike llight regulator

corblimey

New Member
Well, it's taken a little while coming but since I said I'd share to the others that have kindly helped me with my little project, here it is.

Constructive criticisms will be very much appreciated but please go gently on me since it's my first attempt at anything like this.

Basically what I've tried to build is a voltage regulator for use with a bike light system I've cobbled together. I took a couple of mr16 pond lights from B&Q added some handlebar mounts and a 18.5v Li-ion battery and although this works I thought I'd make it a little more sophisticated by adding a regulator. It comes with soft start, low battery warning, turbo mode (unregulated) and low and high regulated modes to flatten out the battery discharge curve thus providing longer runtime and consistent brightness.

In the end I went to the reactive system as suggested by Dippy (I think). When I got into it I just couldn't understand why I was so intent having feedback in the first place, it just wasn't necessary. I also found by experimentation that simply averaging ADC readings was the most reliable way of getting a stable voltage reading so no need for filtering (another advantage of measuring the battery as opposed to the bulb voltage).

Anyway, here's the code and circuit:

n.b. I can't help tinkering and modded the code (particularly the button stuff) and have yet to test it so I may have introduced a couple of errors in there.

Code:
' Battery voltage measured over 10k leg of 10k/33k divider
' ADC resolution 256 over 0 -> 5v
' To calculate measured voltage = byte value * (5 / 256)
' To calulate battery voltage = measured voltage * (43/10)

' Assign lamp and battery settings
' To simplify the maths calculate target voltages as equivalent ADC values
symbol low_power = 107 			' 9v = 107
symbol high_power = 143			' 12v = 143
symbol turbo_power = 255		' max battery voltage = 255
symbol low_batt_voltage = 179		' 15v

' Assign ports
symbol switch1 = pin3
symbol pwmport = 2
symbol battmonitor = 1

' Assign variables
symbol dutycycle = w0 ' b0, b1
symbol targetvoltage = w1 ' b2, b3
symbol battvoltage = w2 ' b4, b5

symbol power = b6
symbol button_repeat = b7

symbol tempvoltage = b8
symbol counter = b9


' Initialize
button_repeat = 0
power = 0
counter = 0
battvoltage = 0

main:
	'button switch1, 1, 100, 10, button_repeat, 1, button_pressed

	' This replacement switch code needs testing so timings and counts may need adjusting
	if switch1 = 1 then
		' debouce button
		pause 5
		
		do while switch1 = 1
			button_repeat = button_repeat + 1 max 255
			pause 5
		loop
		
		gosub button_pressed
		
		button_repeat = 0
	endif
	
	' Don't do anything until we're turned on
	if power = 0 then goto main
	
	' Read battery voltage and average over 200 readings
	readadc battmonitor, tempvoltage
	if counter < 200 then
		battvoltage = battvoltage + tempvoltage
		counter = counter + 1
	else
		battvoltage = battvoltage / 200
		
		' calculate and set the dutycycle
		dutycycle = targetvoltage * 250 / battvoltage * 4 max 1000
		pwmout pwmport, 249, dutycycle

		' Perform low battery check
		if battvoltage <= low_batt_voltage then
			for counter = 0 to 2
				pwmout pwmport, 249, 0
				pause 20
				pwmout pwmport, 249, dutycycle
				pause 20
			next
		endif

		' reset averaging vars
		counter = 0
		battvoltage = 0
	endif		
goto main

button_pressed:
	' Check for button press length
	select button_repeat
		case > 100
			' Turn off and reset vars
			pwmout pwmport, 249, 0
			power = 0
			targetvoltage = 0
					
			return
			
		else
			' Short press so carry on as normal

	endselect
	
	power = power + 1
	
	select power
		case 1 ' Soft start up to low power
			readadc battmonitor, battvoltage
			dutycycle = low_power * 200 / battvoltage * 5 max 1000

			for targetvoltage = 0 to dutycycle
				pwmout pwmport, 249, targetvoltage
				pause 10
			next
			
			' Now we're warmed up step up to low power
			power = 2
			targetvoltage = low_power
			
		case 2, 6
			targetvoltage = low_power
			
			' If we've got here cos power = 6 then we've been stepping back down
			' from high power so reset power to the beginning of the cycle again
			power = 2
			
		case 3, 5
			targetvoltage = high_power
			
		case 4		
			targetvoltage = turbo_power
			
	endselect
return
 

hippy

Technical Support
Staff member
Looks good, but one thing missing from your circuit diagram - Leg 2 of the PICAXE-08M should be connected to 0V to prevent download mode being entered and intermittent operation.
 

BeanieBots

Moderator
The important thing is, does it do the intended job?
I've not gone through your code but the circuit looks sound except:-

You have left pin 2 (serin) floating. It won't work. (well, not reliably)
This MUST be tied low.

This is just being picky but, you did ask for criticism!
(no particular order of importance)
1) I would put a lowish value resistor (~330R) between PICAXE and FET gate just for safety should the FET pop.
2) As a general rule, try to keep the more positive voltages at the top of the diagram working down to 0v and then (if used), negative voltages below 0v so that the reader can easily follow.
3) The labels for the power to the 08M are marked +ve and -ve.
You don't have a negative rail. Vcc (or 5v) and 0v would be better.
4)C1 should be between C2 and the regulator. If you draw the 0v's of C1 and C3 going to the downward line of the regulator 0v, it helps to indicate that those capacitors are to decouple the regultor rather than just caps that have just been 'slapped' across the power supply.
5) The regulator is labelled as 78L05 T0220
A 7805 is T0220, a 78L05 is T0-92
6) A few labels on the 08M pins would be nice. That would have made it much easier to spot the floating serin pin problem.

All-in-all, not a bad first effort. Thanks for sharing.
With experience, you will find that diagram layout becomes important just like good grammer and spelling is important to help convey the correct meaning.
 

corblimey

New Member
Once again, thanks for the pointers.

I'll correct th folating leg issue. Obviously, I had all that on my breadboard but didn't consider it when transfering it to paper.

I must admit I simply pinched the power supply fro the manual so I'll blame rev-ed on that one but I will admit the obvious ignorance :)

It is a 7508 not a 75L08.

I have to admit I found using Tinycad and veeCad a little frustrating at first but I'm getting there. I shall go back a revise my diagram.

And the all important, does it work? Yes! The performance is obviously down to the battery but the litle bit of added brains make the whole package much easier to use.

I'm using Osram Decostar IRC bulbs which help with performance but the extra efficency from overvotling to 18.5v is what makes them really kick butt.
 

BeanieBots

Moderator
That's a lot of overdrive! How long do they last at 18.5v?
Don't think they're specifically designed to cope with vibration either.
Would be genuinely interested to know lifespan "in the field".
 

corblimey

New Member
The 18.5 v is a new battery I've only just started running. I had a 14.8v Li-ion before that and ran it for 2 years on the same bulbs.

The Decostar IRCs are rated for 5000 hours @ 12v, I'm using a 20w 10 deg spot. The blurb states that 20w is equiv to a 35 watter but I take that with a pitch of salt.

I think the maths goes something like this:

Lumens increase = volts % increase ^ 3.4
power consumption increase = volts % increase ^ 2
bulb life = volts % increase ^ -10

so for my case a 18.5v => 54% voltage increase

Lumens increase by a factor of 4.34 :)
watts increase by a factor of 2.37
bulb life decreases by a factor of 0.013

So =>

Lumens = Sorry, haven't got any data for this.
Power consumption = 47.4 w
Bulb life = 66 hours

This is all theoretical of course and I'm sure the maths deviates as you put bigger numbers in but it does give you an idea. I'm not really worried about life span, 66 hours is a lot of night riding for me and besides I just carry a spare bulb and a little led backup to get me home.

I can tell you that my lights kick butt on the trail and blasts commercial HID systems (> £350) out of the water. In fact, I compared my setup to a Light & Motion Arc, which I believe is one of the better ones, and you could bearly tell it was on.

I'll let you know how it works out i real life.
 

KMoffett

Senior Member
Corblimey,

I've been using a MR16-ESX 12v/20w on my bike. Running it off a 12v SLA. This bulb has only a 12 degree beam angle. The narrow beam puts a lot of light out in front, with just the right amount out to the sides. I mostly ride on urban bike paths that runners and people with dogs seem to think are theirs when it's dark. Several near misses and two sprained wrists made me determined that I was going to en-lighten them. I can now see them over a block away (further if they have reflective tennies)...and they know I'm coming. Need to add a "dim" for other bikers though. Right now I'm just putting my hand over the light, so may go the PICAXE/PWM route.

BeanieBots,

I've been using mine for over a year, 1 to 2 hours a day, and it seems to hold up even on rough terrain. I'm not sure what it would do at 18v though.

Ken

Ken
 

BeanieBots

Moderator
I'm impressed. Where did you get the life expectancy deration figures from?
My concern came from running some unbranded MR16 50W units at 1v less than you and only got about 10 miutes life:mad:
Obviously 66Hrs vs 5000Hrs is one heck of a drop, but as you say, 66Hrs night riding is a long time and probably not much less than than you could hope for from a 'conventional' torch bulb.
Good luck, and keep us posted.
 

corblimey

New Member
Those figures I quoted are from a thread running over at mtbr.com http://forums.mtbr.com/showthread.php?p=2452526 but I've just looked up an article I found a coulpe of years ago and that uses a power of -12 which does start to get a little bit more significant (28 hr). This is the article from the candle power forums wiki http://www.wiki.tjtech.org/index.php/Hotwire_Math

I only intend using the turbo mode when running full chat down hill or when I'm showing off ;)

Here's an interesting little table showing how lumen output increases with voltage for several different bulb types http://nordicgroup.us/s78/wattslumens.html That would imply I'm approaching 3500 lumens but thats pretty random maths.

btw my setup is on page 7 of the mtbr.com thread if your interested.

KMoffett - I'd be intersted to hear how you get on with a regulator.
 
Top