High Beamer

From Wiki
Jump to: navigation, search
High Beamer Prototype

This project is for my Katana GSX600F motorcycle. I'm tired of never having my garage door opener handy when I need it. It's either in my backpack, in my Joe Rocket jacket, in my pocket, or in my man-purse. This device solves the problem with a small microcontroller-based device that watches the high-beam switch. When it sees it change state 3 times (3 quick flashes of the passing switch, or 3 changes from high beam to low beams), it triggers the garage door opener.

This circuit, by design, is a little more complicated than it needs to be at first glance. One could simply cut loose the passing switch from the high beam circuit, and connect it in parallel with the switch on the garage door opener. I prefer not to cut up wiring harnesses like that, and I want the passing switch to retain its functionality. One could also wire a relay in parallel with the horn, and use the horn switch. However, if I come in late, I don't want to annoy everyone with the horn beeping, particularly if I have to do it twice (garage door openers don't always work on the first press).

So what we have here is a microprocessor that counts the number of edges between the high beam and low beam state (if the high beams are on, flick to low beam three times, or if on low beams, flick high beam/low beam or passing switch three times). If three edges occur within 0.5 seconds if each other, we consider the request to trigger the garage door opener seen (there's also software support for 4 edges, but no supporting hardware is present). The switch is debounced and must remain in a stable state for 80ms to consider it an edge.

Once we've seen the request to trigger the garage door opener, an additional safety layer exists. To prevent a run-away or hung processor from holding the relay closed, a pulse train driven relay circuit is implemented. This requires a certain number of pulses from the processor before the relay will close. The output of the processor is AC coupled via capacitor C1 to diodes D1a and D1b. If a continuous DC voltage is applied, capacitor C2 will not charge. However, a 200Hz frequency will pass through C1 and D1a, charging C2. Once C2 has reached the gate threshold voltage of Q1 (which is actually a FET in our implementation), the FET will enable relay K1. An additional resistor (not shown) makes sure that C2 discharges, since unlike a transistor's base to emitter path, there's no appreciable gate to source current path. This was modeled in a simulator and works quite nicely. 200Hz is the ideal frequency, but unfortunately I don't remember the minimum and maximum frequencies.

The 200Hz frequency is established by the 5 millisecond sleep period of the processor. While this will vary somewhat over temperature, the toggling rate of the I/O pin to generate the pulse train is well inside the minimum and maximum cut-off frequencies of the pulse train circuit.

In addition to the pulse train circuitry to prevent the relay being held active, the watchdog in the processor is also enabled. This is reset every 5ms in the main loop. Should the processor hang or suffer an upset, the watchdog should reset the processor after a short period (see PIC12F629 datasheet).

Probably need to add a series diode and a zener to ground to protect the 78L05. If the prototype doesn't survive, I'll add that later.

2010/05/17 - Got the connectors, built up a wiring harness, installed in bike. Works great! Need to take some photos of the installation. The wiring adapter used Ancor 16ga wire, which has thicker than normal insulation, and it usually used in marine applications. This made it a little more difficult than normal to insert the pins into the connectors. However, it was the wire I had on hand, so it's what I used.

Headlight Connector

The connectors for the headlight/position light wiring harness to the main wiring harness are 6 pins. These are available from Eastern Beaver as part number 6P090-HM ($5.40 for a complete set with pins). The part number for the headlight side of wiring harness is 36620-08FA0 [1].

Wiring code:

  • Black w/ white strip is ground
  • Yellow is high beam
  • White is low beam
  • Black is front left turn signal
  • Brown is position light

Images & Documents

Code

The code is actually written in PIC12F629 assembly, but this is the C high-level outline. The source can be found in the highbeam629 directory in the Subversion Repository (username 'guest', password is empty).

#define SLEEP_TIME_IN_MS  5
#define HALF_SECOND (500 / SLEEP_TIME_IN_MS)
#define TWO_SECONDS (2000 / SLEEP_TIME_IN_MS)

void main (void)
{
  UINT16 switches = 0;
  UINT16 switchesLast = 0;
  UINT8  edges = 0;
  UINT16 timer = 0;
  UINT8  activeRelay = 0;

  relay_output_1_low ();
  relay_output_2_low ();

  while (1)
  {
    sleep_5_milliseconds ();

    //
    //  Sample switch
    //
    switchesLast = switches;
    switches = (switches << 1) | (switch_state () ? 0x0001 : 0x0000);

    //
    //  If timer running and it expires, reset edge count
    //
    if (timer)
    {
      if (!--timer)
      {
        if (activeRelay)
        {
          relay_output_1_low ();
          relay_output_2_low ();
          activeRelay = 0;
        }
        else
        {
          if (edges == 6)
          {
            timer = TWO_SECONDS;
            activeRelay = 1;
          }
          else if (edges == 8)
          {
            timer = TWO_SECONDS;
            activeRelay = 2;
          }

          edges = 0;
        }
      }
      else if (activeRelay & 1)
        relay_output_1_toggle ();
      else if (activeRelay & 2)
        relay_output_2_toggle ();
    }

    //
    //  Switch changed
    //
    if (!activeRelays && (switches != switchesLast))
    {
      //
      //  If debounced open or closed for 80ms
      //
      if (!switches || (switches == (UINT16) -1))
      {
        timer = HALF_SECOND;
        ++edges;
      }
    }
  }
}