Stuck planning my turn signal module

Status
Not open for further replies.

yfx4

Member
Right now I'm planning out my turn signal controller for my motorcycle. Seems simple but I am at a loss for the best way to proceed. I will decide on the best chip after I figure out the best way to accomplish my goals.

Basically, I have 5 lamps, a turn signal lamp at each corner and a brake lamp. I want all lamps lit all the time (PWM) as running lights. The tail light should do this too so it it the same brightness as the other lamps. (Already built LED lamps with individual voltage regs that have on/off pins the PIC can control easily.)

Turn signals should function as ON/Off, not on, dim. The rear TS lamps should be brakes also but if the TS is on it should override the brake signal. Main brake lamp will use the MC feed to ensure it goes bright quickly and independent of the PIC.

Do I run 3 software PWMs and change the duty cycle for TS indicators/brake?? 1 PWM and alter the individual output pins?? I do not understand building a state machine but have read some of it. Would that be best?? Can someone provide links to more info on them--I have googled but get mostly commercial sites or dead links.

As I said, I will decide on on a PIC once the flowchart is made, then I can play with coding--will probably ask for help there too.

Thank you for your ideas/input/help.
 
If you are going to use PWM, how about just changing the PWM times to make the light bright/dim, and add a gate in the software to do on/off.
This would accomplish your running lights (dim), turning lights (bright), and EM flashers (blink bright or dim), probably could do similar with the brake light, couple of blinks then on Bright. You would probably need a chip with a couple pwm.
Are the led's a bunch of regular style bright type, or are they the High Power ones?? I was reading on the High Power (1-3 watts) that they need a constant current source for power so not sure if they would work in this setup, except for on/off.
 
LEDs are lumileds Superflux--they are rated for automotive use. 70mA@2.6V. 9V sharp regulator (PQ09DZ11J00H, it is a low dropout 1A SMD reg with a on/off pin that PWM does great to control brightness https://sharp-world.com/products/device/lineup/data/pdf/datasheet/pqxxdz51j00h_e.pdf) with several strings of 3 lamps and current limiting resistor. By the book, 6-12 is enough for a car's signal light. Since space is an issue I am uncertain how to get proper heat sinking and keep weather-tight for HP LEDs. Superflux ones have worked fine for several years so............

Binzer, What is a gate? (not the door in a fence--hehe.) Changing the PWM--that's what I want to do. Just was not sure how to control the PWM duty cycle on a per-lamp basis--should I have two PWMs at different duty cycles and select between them??. See the attached diagram and truth table for what I would like to do. Ideally I would like the TS switch (momentary) to have a 'lane change mode' where a single tap runs the flasher for, say, 3 sec, and a double tap runs it either until a single tap shuts it off or 45 sec, whichever is first. I think just getting the basic system running first is best. I envision the circuit details being dictated by the PIC I use. Then I can decide if I want to use some isolator to protect the PIC output, what kind on input protection I need, etc.

Thanks for the questions and help. As I'm sure y'all know, sometimes just answering questions leads one to the answers.
 

Attachments

  • TS Module outline.pdf
    9.4 KB · Views: 226
Last edited:
I was thinking an and gate, PWM signal and say ENABLE, so you could keep your light level and Blink the light, not sure if that could be done in the Pic itself.
I have been looking at some of the High Output led's for an aquarium light retrofit, will have to check out those regulators, fixture has an aluminum reflector (heatsink).

I did do some reading on the High Power led's and it does seem that getting rid of the heat is a problem, more so for the units with multiple led's.
I had to work on a video inspection machine a week ago that used a 3 watt led for one of the lighting setups, the led actually died, service guy thought the control board was bad, surprised as the machine was not even a year old.

2 pwm's at the duty cycle you want may work, then gate them to the specific device, or try changing the pwm on the fly. Might be good to breadboard a pic and try some experimenting with pwm. I did some a while back but don't remember what I did with the code, been changing computers.
 
I am guessing I don't understand more than I think I don't. (did I say that right??)

Does hardware PWM only output to a single pin?? If so I think I will need 4 PWMs so I can control the TS and the brake outputs for each corner lamp.

Am I understanding the PWM output correctly??
 

Check this out, pick a chip, download the chip info and read the section on pwm.

You may want to pick a chip with one pwm and breadboard something and do some testing.
**broken link removed**
 
Thank you. Already been there and did that for the 16f18299. Also read AN594. Thats where i noticed the pwm out goes to one pin. I had looked at picaxe chips where they can, on some ICs, output to 4 pins. I understand they are regular PICs with a bootloader preinstalled. Don't really want to go that route though. I think Assembly will suit me better in the long run. Anyway, if the picaxe people can get the hardware PWM to 4 pins, how can I??? I should be able to. Setting up the hardware PWM seems straightforward enough. It is the switch between different duty cycles and the TS flash that confounded me. I think your idea of an 'and' gate external to the PIC is easiest and lets me have only two PWMs. Then change the duty cycle with named calls. Or something like that anyway. I'll experiment--not sure which PIC s I have handy but i'll dig them out and plug them in. Thanks!!!
 
...
Basically, I have 5 lamps, a turn signal lamp at each corner and a brake lamp. I want all lamps lit all the time (PWM) as running lights. The tail light should do this too so it it the same brightness as the other lamps.
...

That will not be legal... It's illegal almost everywhere for turn signal lights to be fixed on, and they are only allowed to flash right/left at the same time specifically to signal a "hazard" warning to other motorists.

The brake light bulb filament (if incandescent) may risk burnout if on all the time at full power, along with the taillight filament. If the bulb does not brunout you risk cooking the plastic housing and lens.
 

You apparently do not understand what I'm doing. There is NOTHING illegal about it in Texas and the premise is used often for vehicles at the factory.

Back on topic.
 
Last edited:

Most cars have dual filament bulbs and usually one stays on, usually a lower wattage, Tail & Turn. The STOCK brake light on my motorcycle is lit all the time (lower wattage filament for lic plate) and turns on another filament with the brakes on. The STOCK front turning lights are dual filament also, one stays on (low) and the other flashes Bright during Turn, so I don't think it's illegal if it comes stock from the mfg. I did change the rear turn signal fixture from single to dual to add more light to the rear to be seen better when it's foggy, I haven't gotten a ticket. They also sell adapters to do something similar with the single bulb fixtures if you do not want to change them. They also sell adapters to use the new LED Lamps. They also have new Led Headlights for bikes. They also have Head Light Modulators to help bring attention so people "see" you. I wonder if they use microcontrollers in any of thes "off the shelf" products?I take it you don't ride??
Mike.
 
Last edited:
I think that once you set the divisor to get your Pwm Period that adjusting the Duty Cycle would accomplish what you want to do. I have not tried to adjust the Duty Cycle after the Pwm was setup and running.
 
...
The STOCK front turning lights are dual filament also, one stays on (low) and the other flashes Bright during Turn, so I don't think it's illegal if it comes stock from the mfg.
...

Interesting! Which bike? I ride and keep an eye on new bikes but have never seen that feature. It may not be allowed on the imports to Australia (ie might be a US models only feature).
 
My Honda VTX 1800. The 1300 as well. The Honda Fury. My neighbor has 2 Harleys that have that feature. It could be a US feature. Car laws are different thee than here too.
 
My Honda VTX 1800. The 1300 as well. The Honda Fury. My neighbor has 2 Harleys that have that feature. It could be a US feature. Car laws are different thee than here too.

Yup, Mine is a 1994 Harley FLSTC, front lights are on dim all the time and flash bright for turn, factory stock, I changed the rears to do the same for more visability.

There are some mfg's that sell some fancy modules to do quick flashes on the brake light before it comes on solid to catch the attention of those behind you. I wonder if they also use some sort of microcontroller for this as some have configurable flash schemes.

I have also seen an aftermarket assy that has everything in one enclosure, the turn signals are yellow or orange and are moving arrows, lights on the sides and brake light which is red. Lots of neat led stuff out there now, but it's more fun to make your own.
 
Using a 16f628A I got the CCP running along in PWM mode. I can manually change the duty cycle in CCPR1L then flashing the chip. voila! brighter and dimmer. PITA to do on the motorcycle. Kinda take the eyes off the road.

So. Next was to use a switch to insert a new value in CCPR1L while pressed, then replace it with the standard value when unpressed. I used Nigel's tutorial code with the 50ms switch delay to debounce the switch. This has worked before for me in other situations. here it is not. I know the switch works-I put a LED on it to show it is pressed. I tried setting it up as both normally high and a press pulls it low and the reverse (using btfss or btfsc commands as needed). the RA0 pin was first. did not work. I tried other pins they did not work as inputs either. I do not have the code here at work -- I did set up the PORTA as inputs moving a b'11111111' into TrisA. Got a bank warning on the build I think b/c W is in a different bank than PortA?? what else can I look at? Could the input part of the PIC be bad??

Basically I set up porta as inputs like this:

Code:
bsf 	STATUS,		RP0	;select bank 1
   	movlw 	b'11111111'		;set PortA  inputs
   	movwf 	PORTA

Then I try to use the switch to change CCPR1L value like this:

Code:
Loop	btfsc	PORTA,	0
	call	bright
	goto	Loop

bright
	MOVLW	b'11111111'	
	MOVWF	CCPR1L
               return

I know this won't return the PWM to the lower level of brightness. It's just a section of what I was experimenting with that did not work.

Further, using the .asm template from microchip P16F628ATEMP.asm as a base gave a build error. It did not like the config code. This is the way it comes from microchip:

__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT

I get an error saying that _DATA_CP_OFF is not recognized or defined. Thus the build fails. If I delete this part of the config it builds fine. Is this part of the problem or does it signify something else?? The PicKit2 recognizes the 16f628A just fine. MPLAB 8.80--I downloaded and installed it last week.

This is what I used as a basis to setup and test the PWM. It works fine. The switch code that worked before does not work now. Hmmmmmmmmm.

Any Ideas??

Code:
;*************************************
; Author  : Mike Baird
; Program : Simple Led PWM
; Date    : July 25th,2009
;*************************************


	List	P=16F628A		; F=inhx8m
	#include	"P16F628A.INC"	; Include header file
	__config	_PWRTE_ON  & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _BODEN_ON & _LVP_OFF & _CP_OFF & _MCLRE_OFF


;**************************************
	Cblock	0x20		; General purpose registers
	Count1			; For Delay
	Count2			;
	Count3			;
	Endc

;**** Start and Reset Vector ****
	Org	H'00'
	GOTO	Main		; Reset -> init

;**** Interrupt Vector ****
	Org	H'04'
	

Main	
	CLRF	PORTA		; PortA all low
	CLRF	PORTB		; PortB all low
	MOVLW	0x07		; Turn comparators off and enable pins for I/O
	MOVWF	CMCON
	
	BSF	STATUS,RP0	; Bank 1
	CLRF	TRISA		; PortA all output
	CLRF	TRISB		; PortB all output
	BCF	STATUS,RP0	; Bank 0

	MOVLW	0xFF
	MOVWF	PR2		; Compare with 255 (Step 1)

	MOVLW	0xFF		; Not neccesary
	MOVWF	CCPR1L		; bits 2-10 of 10 bit pwm

	MOVLW	0x03		; b'00000011'
	MOVWF	T2CON		; Prescaler 1:16 (bits 0-1) and postscaler 1:1 (bits 3-6)
	MOVLW	0x3C		; b'00001100' 
	MOVWF	CCP1CON		; Set Pwm Mode (bits 0-3) Bit 4 = CCP1Y (bit 0 of PWM) Least significant bits
						;						  Bit 5 = CCP1X (bit 1 of PWM)
	BSF	T2CON,TMR2ON	; Enable PWM

; PWM period = [(PR2) + 1] * 4 * Tosc * TMR2 prescale value
; PWM period = [255+1] *4 * 4 x 10^-6 * 16
; PWM period = 4.098x10^-3s or 244Hz


;The following steps should be taken when configuring the CCP module for PWM operation.
;1. Set the PWM period by writing to the PR2 register.
;2. Set the PWM duty cycle by writing to the CCPR1L register and CCP1X and CCP1Y bits of CCP1CON register.
;3. Set the TMR2 prescale value and enable Timer2 by writing to T2CON register.
;4. Configure the CCP1 module for PWM operation.

; **** Main Program ****
FADE
	
	DECFSZ CCPR1L
	CALL Delay
	GOTO FADE


; **** Delay ***
Delay	
	MOVLW	0x02
	MOVWF	Count3
d3	
	MOVLW	0x3F
	MOVWF	Count1
d1	
	MOVLW	0xFA
	MOVWF	Count2
d2	
	DECFSZ	Count2,F
	GOTO	d2
;	DECFSZ	Count1,F
;	GOTO	d1
;	DECFSZ	Count3,F
;	GOTO	d3
	RETLW	0x00

;********************

	END

; That's all folks!
 
Not sure I was clear in what I just posted. The PWM code works to fade the LED using the hardware PWM. I was inserting/replacing sections of code with snippets like what I wrote up. I did use the delay feature like in Nigel's tutorials where it delays 50ms, then rechecks too see if the button is still pressed. I was not trying to get switches to work in Baird's PWM fade code.
 

Did you ever get this working? Looks like the thread died for some reason.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…