top of page
  • Writer's pictureAndrew Asuelime

Motorcycle Light Circuit (part 1)



For a while my only form of transportation was a motorcycle. I used it for everything: school, work, fun, travel, grocery shopping. I started with a backpack but eventually I got some hard luggage for my bike. It was far more convenient to have a trunk and saddlebags for storage. I could easily fit a weeks worth of groceries in there. The bags I got were very stylized and had reflective portions on them that resembled lights, so I thought to myself, wouldn't it be great if there actually were lights in there? And that's where this story begins....


So where to start? Well first with a system definition. There are some hard requirements

  • Inputs: Left signal, right signal, Brake, 12V power from a relay

  • Outputs: 12V automotive LED strips, one for brake, left and right signals


Then some other limits I imposed on the design to narrow the scope

  • Use Atmel atmega8 MCU for PWM and control (mainly because I had some lying around)

  • 1 amp current limit per output

  • Add brake modulation capability


For those who don't know, a brake light modulator is a simple device that will flash the brake light a few times when the brake is initially applied, then will hold a steady on state. It grabs the attention of other motorists far more successfully than a solidly illuminated light, a welcome feature to any motorcyclist. You will often see them on CHP motorcycles (though they are legal for civilian use as well)


This simple project has a few different components:

  • Schematic creation

  • PCB design

  • Firmware

  • Physical Assembly

And will be split into multiple parts to keep the posts a little shorter, and also because it's still a work in progress.


Well let's get into it...

 

System Specifications

Now that I had a few loose constraints I started thinking about how to actually implement the system. I wanted to make liberal use of timers and interrupts and reduce processor work load.. The Atmega8 has a few peripherals that made things easy notably:

  • 3 PWM wave generation modules with external pin output mapping

  • 3 Hardware timers (with effectively 4 software timers)

  • 8 Analog inputs

  • External Interrupt pins

PWM Channels/Timers

Since I planned on using LEDs I would need a way modulate their brightness, Naturally I would use the PWM channels of the MCU

TImer 1 has dual channel output channels, for me it initially made the most sense to use that with similar signals, like the left and right brake channels.

Timer 2 has a single PWM channel I would use with the brake output

Timer 0 has no outputs but can be used for brake light modulation


Input Pins


Motorcycle input circuit. These are the 5 signals coming from the motorcycle. You can see the voltage shifting resistors for the turn signals

Ideally, I would have had each of the 3 inputs dedicated to an external interrupt, but unfortunately there are only 2 external interrupt pins on this device. I decided to give one to the Brake input, as it seems like a much higher priority function than turn signals which would use standard GPIO. Since all these signals came from a 12v automotive system I would shift the voltage using a simple resistive divider.

The datasheet for the atmega8 says Vih = 0.6*Vcc to Vcc+0.5V and Vil = Vcc-0.5V to 0.2*Vcc which comes out to Vih = 3-5.5 volts and Vil=-0.5-1 Volt.

The motorcycle has output voltage anywhere between 10.8 (for a dead battery) and 14.8 when the alternator is powering the system. I decided on a 1/3 voltage divider which gives an input range of 9-16.5V for input. This worked well for both my motorcycle and the MCU.



Output Pins

well, I'd already decided to use the timer PWM pins, but since the MCU only works at 5V I would need to interface it with the 12v system. I chose some SS8050CBU ON Semiconductor N channel BJTs with a gain of 100 (worst case 1A operation, the gain was higher at lower current levels)


That would supply in excess of 1amp in open collector configuration. This would mean that at 1A draw I would be sourcing 10mA from the mcu pin, well within the 40mA limit per pin. Now there was another issue, how to assure I didn't exceed my 1 amp rating? Well I started by calculating the base resistor value to limit current flow. of the collector. Seemed simple enough, but then I thought it would be nice to have a software current monitoring. So I thought I could use a shunt, that way if the current goes high (like in a short circuit) I could disable the output from the MCU. In the end I decided to also add a hardware current limit, Placing another BJT at the collector of he output stage along wiht a 0.68Ohm resistor. The current form the output stage would go straight into the sense resistor and when it exceeded 1amp (~0.7V) the second BJT would turn on and steal current from the base of the output stage thus preventing runaway current. I tested the circuit in spice to verify it's operation. The nice thing is this also gave a shunt value for current monitoring.




Current Monitoring/analog input

I would use the shunt from the previous section to measure output current for each of the 3 lights. The voltage as it was would range from 0-0.7V a bit low for the ADC, so I added a non-inverting amplifier stage to each channel. I wanted a gain around 7 which would make the voltage swing 0-4.9V. Eventually, I would settle on Av=6.55 after selecting real resistors and trying to reduce the number of different parts in my design.


Remember that brake modulation functionality? Well, I wanted the modulator to have variable control. i've had several modulators on my various motorcycles over the years and my favorite one allowed me to set the speed of the flashes from around 3Hz-15Hz. I wanted this same functionality in my system but I wanted to go one step further and make the number of flashes variable as well.I decided to use two 10k trimmers so the user can easily adjust both the speed and number of flashes.


So at this point I had used 5 of the 8 Analog input channels.


Extra

Uart connection for debugging

I added one RGB LED to the system that I could use for system status

P channel mosfet on 12V input for polarity protection

ISP connection for downloading FW*



Unity gain non inverting op-amp to buffer brake output signal, Thus solving the ISP programming issue

The ISP connection actually complicates things a little bit. It uses the SPI interface fr programming, but the MOSI (master out Slave in) pin of the atmega8 MCU is also multipluxed with timer2 PWM pin, It seemed fine as they wouldn't be in use at the same time. However, as I later found out, the BJT would suck all the current from the programmer and the MCU wouldn't get any and thus could not program. I was able to program the MCU if I removed the base resistor to the BJT. So I had to ad a unity gain op-amp to that output pin. An (ideal) op-amp has no current draw on the inputs so this would mean I could program my board without issue but still use the pwm channel during runtime. As a side effect the extra amp also acted as a buffer and would reduce the current draw from the MCU since power was derived from the 5v rails.


Another valid fix for this issue would have been to switch from BJT to MOSFETs for the output stage since the gate doesn't draw any current. I did experiment with this but ultimately stuck with the BJTs as this discovery happened late into development and would've require a few other circuit modifications


Of course after all ideal values were calculated, I went through and tried to reduce the number of different parts. Reusing the same value caps/resistors where possible. Then redoing the math and making sure the system would still meet my initial specs.


 

PCB Layout

I ended up going through 2 PCB revisions for this board. I'll mainly be discussing the 2nd (and final) implementation.


My constraints:

  • The board should be the size of a credit card, for no particular reason except to impose constraints

  • all the inputs on one side of the board and the outputs on the other.

  • trimmer pots close to the edge of the board

  • Status LED near the inputs

The outputs would use the 12V rail directly and the MCU and opamps would get power from the 5V regulator on the board. Initially I had the 12V input near the output connectors, but in the redesign I moved it to the other side of the board. To accomodate this change I had to make a few large copper pours (top and bottom) that would ensure I would get at least 4A of current transfer with minimal temperature change (1Amp max draw for 3 channels plus spare for 5v logic). For simplicity I left the regulator in its original position, on the output side of the board. Had I redone the board I would move the regulator closer to the input power.


I nearly moved all the components to the top of the board. I had a P-channel MOSFET on the 12V input for reverse polarity protection, but when I moved the input I had a large trace on top and another on bottom. I decided to put one MOSFET on each of these traces so I had one component on the backside of the board. Adding a second MOSFET would also help to lower the current per device and keep them a little cooler.


During routing I ended up making a few changes to the pin configuration, these made routing much easier swapping some of the RGB LED pins as well as some analog channels meant a few less vias to route signals. I ended up changing a few definitions in the header file to match the updated schematic, that's one plus of having control over hardware and software.


Here's the final design files. Pretty straight forward










59 views0 comments

Recent Posts

See All

Comments


Post: Blog2_Post
bottom of page