How do I know if the engine is running (Auto Headlight Switch working)

Started by SK Racing, June 04, 2021, 06:51:58 AM

Previous topic - Next topic

SK Racing

The tach signal doesn't make any sense to me. It measures (varies a bit) around 6.9VDC and it is not AC - I checked. Revving the engine it comes down to about 6.2V, bit it is not consistent. It jumps around a lot. I'm measuring between the B\R (which definitely is tach signal) and GND.

Does anyone know how the tach signal works?
You don't stop riding when you get old, you get old when you stop riding!
1939 Panther 600cc Single - Stolen, 1970 Suzuki 50cc - Sold
1969 Triumph Bonneville 650 T120R - Sold, 1981 Honda CB750F - Sold
1989 Suzuki GS500E - Sold, 2004 Suzuki GS500F - Current ride

SK Racing

From what I can gather on the Internet, it could be a pulsed signal. Most probably a pulse every time there is a spark. I don't have a scope, but I'll put a circuit together on breadboard and see if I can count the pulses on the Arduino and take it from there.
You don't stop riding when you get old, you get old when you stop riding!
1939 Panther 600cc Single - Stolen, 1970 Suzuki 50cc - Sold
1969 Triumph Bonneville 650 T120R - Sold, 1981 Honda CB750F - Sold
1989 Suzuki GS500E - Sold, 2004 Suzuki GS500F - Current ride

chris900f

Damn, I expected you would get a 0/5v square wave pulse. Maybe it never drops to zero, but still has a 5v swing?

mr72

all depends on how you measure it. You need an oscilloscope. If you use a regular volt meter either set to AC (RMS) or DC it will read something like the RMS or DC equivalent voltage. A DMM is designed to measure voltage at a max of about 400 Hz so it's effectively low-pass filtered, so your >1.2kHz square wave for a running motorcycle pulsed ignition signal is going to look a lot like DC.

Someone should tell Sledge that square waves going between 0V and 12V are not DC. That's why you use a transformer, keeps you from frying your low voltage sensing circuitry. All electrical signals are analog, you can treat them as digital but internally your device uses a transistor or comparator with a trigger voltage to differentiate between 1 and 0. You have to AC couple signals from a source like this somehow to keep the reference at 0V otherwise you get baseline drift. Lots of signal quality stuff you need to deal with to do a good job of sensing. I know you are quick and dirtying this thing but to make it reliable you need to build an analog circuit that will result in a persistent steady voltage above the input threshold when it's running and consistently below the threshold when it's not running. That's an analog problem. It's a filter.

SK Racing

I have gathered that it must be a 12V square wave signal and I'm busy doing research online to measure the frequency with Arduino/ATtiny. There are a few examples that might work, but it will take some time to get a working circuit and sketch together. I'm just a hobbyist programmer/tinkerer, but I've cobbled together some amazing Arduino/ATtiny projects in the past.

The main problem is it is so far in between projects that I have to relearn a lot of stuff again every time. But I'll get there. It's just a fun project anyway.

I'm not sure if a voltage divider and zener will let me safely sense the pulses, as the Arduino can only take up to 5V signals. Logic tells me that it will be adequate and no need for a transformer.
You don't stop riding when you get old, you get old when you stop riding!
1939 Panther 600cc Single - Stolen, 1970 Suzuki 50cc - Sold
1969 Triumph Bonneville 650 T120R - Sold, 1981 Honda CB750F - Sold
1989 Suzuki GS500E - Sold, 2004 Suzuki GS500F - Current ride

chris900f

Checkout the Speeduino forums/ manual, since they also use the Arduino Mega with various conditioner circuits to take different levels/types of
input pulse voltage as the drive signal for those systems.

https://wiki.speeduino.com/en/wiring/system

mr72

The Arduino likely has some reference trigger voltage so noise doesn't result in triggering on a digital input pin. Ideally it's probably 0V  or +5V but in reality there is noise in any circuit and you wind up with some signals above 0V on the pin (like, induced noise from motorcycle ignition, which is not going to be small) and you also need to make sure it doesn't go above 5V, the application note or datasheet for the part should tell you how to correctly couple the signal. But that's assuming you already have an ordinary digital signal in the first place, and you don't.

There are a ton of ways to do this properly. In a motorcycle you need to understand that the electric field from the ignition is going to wind up putting noise on everything, which is usually not a problem except when you put digital stuff in there that will pick it up.

At a very minimum you need a buffer. But once you are building a buffer, you might as well build a filter. Look on the internet, this is a problem someone else has solved. But this isn't as simple as taking an analog reactive switching signal like the one coming from the igniter to the tach and with only resistive divider feeding it into an ardiuno. That's hardly a plain square wave. It has overshoot and undershoot and varying pulse width an duty cycle, all of which the analog tach doesn't care about but your microprocessor will hate.

Think of it this way. First, you need to create an isolated version of this tach signal, with a transformer or optocoupler or something so you don't screw up the tach. Then you need to take that square wave and turn it into a sine wave at the frequency you care about. That's because the square wave edge will fly right through any HPF you make. Then HPF that sine wave at something like 600 Hz, so the 400Hz cranking is effectively blocked. Then the resultant signal is a >600 Hz sine wave, rectify and filter that to ~5VDC. In reality, you'll have a variable DC between something less than 5V when you are cranking to near 5V at idle and probably 5V steady at above idle if you have built your regulator right. Then you can turn this into a real digital signal by running that DC signal into a comparator. You adjust the trigger voltage so that the DC you create when cranking at 400 Hz, maybe 2-3V?, is below the threshold. The output of the comparator will put out a solid 0V or 5V. Run that through a 10K or 100K or whatever resistor is called for by the Ardiuno design guide into your input and Bob's your uncle.

SK Racing

Thanks Chris900f and mr72. Most of that is over my head. Fortunately, there are some examples for Arduino rev counters online. I'll look at ideas and just wing it. I'll report back here when I have something working.
You don't stop riding when you get old, you get old when you stop riding!
1939 Panther 600cc Single - Stolen, 1970 Suzuki 50cc - Sold
1969 Triumph Bonneville 650 T120R - Sold, 1981 Honda CB750F - Sold
1989 Suzuki GS500E - Sold, 2004 Suzuki GS500F - Current ride

SK Racing

#28
Ok, this is what has transpired since my last post. I tested the tach signal from the GS igniter using an Arduino breadboard circuit. With the output displayed on the serial monitor, this is what I found:
  • There is only one signal every engine revolution. I wonder if it is typical of most bikes. I guess so, because generic tachometers are freely available.
  • The signal is a square wave (on-off). I don't have a scope, but the duty cycle typically measures very close to 50%. Only the frequency changes with engine speed.
  • There is some noise in the signal, especially at idling speed (1100 - 1200 RPM), but it is manageable with a filtering algorithm that discards bad readings that fall outside a predetermined metric. I tried a cap filter, but it didn't make things better. At 2000 RPM+ the signal is very stable – which is good, because that will be the norm while riding and I don't want the headlight to go off due to a dirty tach signal. Not that it goes off even at idle.
  • Sensing the tach signal is non-intrusive. I.o.w. the tachometer up front still works fine while measuring engine speed with this circuit.
With the Arduino sketch (program code) ported to the Attiny85 chip (top right in the picture), and the firmware behaving satisfactorily, I focused my attention on designing a circuit board. After first considering a simple stripboard (Veroboard) version, I thought, nah, let's do it properly and fired up KiCad - which I haven't used for a number of years. After a few iterations I came up with the board shown below. In order to make it as tiny as possible (within reason), some SMD components found their way onto the board. Right now, an Asian fab house is busy making the boards. By the time it arrives, the components should be here also. The pcb size is 21x41mm.




And here is the temporary setup that I used to refine the circuit and code.
The Arduino Uno is only there to get live test readings onto a laptop screen via the Arduino serial monitor.


You don't stop riding when you get old, you get old when you stop riding!
1939 Panther 600cc Single - Stolen, 1970 Suzuki 50cc - Sold
1969 Triumph Bonneville 650 T120R - Sold, 1981 Honda CB750F - Sold
1989 Suzuki GS500E - Sold, 2004 Suzuki GS500F - Current ride

SK Racing

This is a sample of the serial monitor output. It begins with the engine not started yet, and when the engine starts there is about 2.5 - 3 sec delay before the headlight comes on.

At the end, the headlight goes off as the engine speed drops below 800 RPM when I hit the kill switch.


Headlight Switch V2.0 - 8 Jun 2021

infHz   Duty: 0%   Dur: 0.00   0.00 rpm
Headlight OFF
infHz   Duty: 0%   Dur: 0.00   0.00 rpm
Headlight OFF
infHz   Duty: 0%   Dur: 0.00   0.00 rpm
Headlight OFF
infHz   Duty: 0%   Dur: 0.00   0.00 rpm
Headlight OFF
infHz   Duty: 0%   Dur: 0.00   0.00 rpm
Headlight OFF
infHz   Duty: 0%   Dur: 0.00   0.00 rpm
Headlight OFF
21.32Hz   Duty: 51%   Dur: 46906.00   373.50 rpm
19.32Hz   Duty: 51%   Dur: 51771.00   1380.50 rpm
24.36Hz   Duty: 60%   Dur: 41046.00   1360.50 rpm
20.29Hz   Duty: 51%   Dur: 49286.00   1912.50 rpm
Headlight ON
17.27Hz   Duty: 52%   Dur: 57899.00   1272.00 rpm
20.16Hz   Duty: 51%   Dur: 49604.00   1307.50 rpm
20.06Hz   Duty: 53%   Dur: 49848.00   1214.00 rpm
19.46Hz   Duty: 52%   Dur: 51382.00   1355.50 rpm
18.79Hz   Duty: 53%   Dur: 53214.00   1148.50 rpm
19.22Hz   Duty: 52%   Dur: 52035.00   1445.00 rpm
19.49Hz   Duty: 50%   Dur: 51299.00   1182.50 rpm
17.35Hz   Duty: 53%   Dur: 57639.00   1164.00 rpm
17.99Hz   Duty: 52%   Dur: 55588.00   1128.00 rpm
24.80Hz   Duty: 59%   Dur: 40321.00   1136.50 rpm
17.16Hz   Duty: 54%   Dur: 58277.00   1299.50 rpm
19.79Hz   Duty: 51%   Dur: 50524.00   1200.00 rpm
21.01Hz   Duty: 51%   Dur: 47600.00   1380.50 rpm
17.26Hz   Duty: 51%   Dur: 57945.00   1191.00 rpm
20.73Hz   Duty: 51%   Dur: 48245.00   1192.00 rpm
17.14Hz   Duty: 55%   Dur: 58358.00   1066.00 rpm
18.27Hz   Duty: 51%   Dur: 54736.00   1113.00 rpm
19.12Hz   Duty: 54%   Dur: 52288.00   1199.00 rpm
39.59Hz   Duty: 81%   Dur: 25261.00   1651.00 rpm
23.48Hz   Duty: 52%   Dur: 42591.00   1577.50 rpm
26.90Hz   Duty: 52%   Dur: 37180.00   1660.00 rpm
30.76Hz   Duty: 61%   Dur: 32515.00   1692.00 rpm
31.95Hz   Duty: 60%   Dur: 31298.00   1754.50 rpm
26.67Hz   Duty: 52%   Dur: 37500.00   2365.50 rpm
28.07Hz   Duty: 52%   Dur: 35626.00   1623.00 rpm
25.09Hz   Duty: 53%   Dur: 39854.00   1617.50 rpm
26.89Hz   Duty: 53%   Dur: 37195.00   1650.00 rpm
24.22Hz   Duty: 51%   Dur: 41289.00   1590.50 rpm
30.71Hz   Duty: 60%   Dur: 32559.00   1634.00 rpm
37.88Hz   Duty: 81%   Dur: 26396.00   1678.50 rpm
23.14Hz   Duty: 53%   Dur: 43218.00   1660.50 rpm
25.45Hz   Duty: 51%   Dur: 39291.00   1573.00 rpm
24.05Hz   Duty: 52%   Dur: 41583.00   2012.50 rpm
31.11Hz   Duty: 60%   Dur: 32144.00   1802.50 rpm
27.15Hz   Duty: 53%   Dur: 36839.00   2411.50 rpm
36.91Hz   Duty: 81%   Dur: 27093.00   2308.50 rpm
26.07Hz   Duty: 51%   Dur: 38357.00   1714.00 rpm
31.77Hz   Duty: 61%   Dur: 31480.00   1821.50 rpm
38.31Hz   Duty: 81%   Dur: 26100.00   1983.00 rpm
29.88Hz   Duty: 60%   Dur: 33470.00   1670.00 rpm
26.92Hz   Duty: 52%   Dur: 37141.00   1647.50 rpm
36.53Hz   Duty: 81%   Dur: 27375.00   1914.00 rpm
17.94Hz   Duty: 54%   Dur: 55752.00   1216.50 rpm
26.94Hz   Duty: 81%   Dur: 37124.00   1260.00 rpm
18.68Hz   Duty: 51%   Dur: 53542.00   1311.00 rpm
16.70Hz   Duty: 51%   Dur: 59889.00   1206.00 rpm
17.97Hz   Duty: 55%   Dur: 55651.00   1151.50 rpm
16.64Hz   Duty: 51%   Dur: 60113.00   1135.00 rpm
19.29Hz   Duty: 51%   Dur: 51838.00   1181.00 rpm
24.17Hz   Duty: 60%   Dur: 41382.00   1515.00 rpm
19.69Hz   Duty: 51%   Dur: 50775.00   1244.00 rpm
18.99Hz   Duty: 51%   Dur: 52652.00   1659.00 rpm
16.66Hz   Duty: 56%   Dur: 60027.00   1247.00 rpm
.
.
.
.
.
.
.
18.84Hz   Duty: 52%   Dur: 53077.00   1175.50 rpm
21.04Hz   Duty: 51%   Dur: 47536.00   1194.00 rpm
21.18Hz   Duty: 44%   Dur: 47207.00   1277.50 rpm
18.29Hz   Duty: 52%   Dur: 54675.00   1183.00 rpm
19.29Hz   Duty: 53%   Dur: 51846.00   1232.50 rpm
26.75Hz   Duty: 29%   Dur: 37380.00   1032.00 rpm
22.67Hz   Duty: 59%   Dur: 44112.00   1340.50 rpm
17.53Hz   Duty: 52%   Dur: 57049.00   1241.00 rpm
17.07Hz   Duty: 53%   Dur: 58590.00   1260.50 rpm
17.80Hz   Duty: 52%   Dur: 56195.00   1189.50 rpm
18.23Hz   Duty: 51%   Dur: 54841.00   1311.50 rpm
24.21Hz   Duty: 60%   Dur: 41312.00   1295.50 rpm
17.77Hz   Duty: 48%   Dur: 39291.00   948.33 rpm
infHz   Duty: 0%   Dur: 0.00   0.00 rpm
Headlight OFF
infHz   Duty: 0%   Dur: 0.00   0.00 rpm
Headlight OFF
infHz   Duty: 0%   Dur: 0.00   0.00 rpm
Headlight OFF
infHz   Duty: 0%   Dur: 0.00   0.00 rpm
Headlight OFF
infHz   Duty: 0%   Dur: 0.00   0.00 rpm
Headlight OFF
infHz   Duty: 0%   Dur: 0.00   0.00 rpm
Headlight OFF
You don't stop riding when you get old, you get old when you stop riding!
1939 Panther 600cc Single - Stolen, 1970 Suzuki 50cc - Sold
1969 Triumph Bonneville 650 T120R - Sold, 1981 Honda CB750F - Sold
1989 Suzuki GS500E - Sold, 2004 Suzuki GS500F - Current ride


SK Racing

Quote from: herennow on June 23, 2021, 09:55:59 PM
Nice work!

Thanks.

Some folk may be wondering why go to all that trouble just to switch a headlight on. Here are some reasons...

A stock headlight draws about 4.5 amps on low beam. On high beam it's more like 9 amps. On the GS the headlight comes on the moment you turn the key. If the battery battles to crank the engine on a cold winters morning, an additional 4.5A is a lot and can be the difference between starting, and cursing at a bike that doesn't want to start while you're running late for work.

But it can also be used to switch on spotlights, running lights, etc. Anything that you only need while riding. The MOSFET that I'm using can handle 30 amps.
You don't stop riding when you get old, you get old when you stop riding!
1939 Panther 600cc Single - Stolen, 1970 Suzuki 50cc - Sold
1969 Triumph Bonneville 650 T120R - Sold, 1981 Honda CB750F - Sold
1989 Suzuki GS500E - Sold, 2004 Suzuki GS500F - Current ride

SK Racing

Good news - the headlight switch is working. The prototype is installed on my bike and will likely stay there because it is working nicely. The pcbs took a very long time to arrive from Hong Kong, but when the package showed up yesterday, I promptly populated one board.



The fab house has a deal of ten boards (100mm x 100mm) for $5, so I had lots made in two different formats. One size and shape to suit the mounting holes that I provided under the seat of my GS500 Street Tracker, and a smaller format to hopefully selling it to a friend who has an auto-electrical shop for bikes. He showed interest, so I'll give him one built board for testing tomorrow.


You don't stop riding when you get old, you get old when you stop riding!
1939 Panther 600cc Single - Stolen, 1970 Suzuki 50cc - Sold
1969 Triumph Bonneville 650 T120R - Sold, 1981 Honda CB750F - Sold
1989 Suzuki GS500E - Sold, 2004 Suzuki GS500F - Current ride

herennow

Nice. I'd get one if they would not fail me during the "controle technique" for the light not coming on when they test it on the bench...

SK Racing

That could be a problem, but a bypass switch will solve that.

The second board is populated. Tomorrow I'll take it to my auto electrician friend for testing and evaluation and possibly selling a few to his customers. I would like to recuperate the costs incurred for the making of the PCB's at least.

You don't stop riding when you get old, you get old when you stop riding!
1939 Panther 600cc Single - Stolen, 1970 Suzuki 50cc - Sold
1969 Triumph Bonneville 650 T120R - Sold, 1981 Honda CB750F - Sold
1989 Suzuki GS500E - Sold, 2004 Suzuki GS500F - Current ride

SK Racing

The Automatic Headlight Switch unit is now installed on my bike and works flawlessly. It is wrapped in transparent heatshrink and sealed at the ends with clear nail lacquer to seal it from moisture. Mounting with rubber grommets reduce vibration.

This form factor fits the two mounting points that I have provided under the seat of my custom GS500. I also had some rectangular pcb's made like the one shown in the previous post.




You don't stop riding when you get old, you get old when you stop riding!
1939 Panther 600cc Single - Stolen, 1970 Suzuki 50cc - Sold
1969 Triumph Bonneville 650 T120R - Sold, 1981 Honda CB750F - Sold
1989 Suzuki GS500E - Sold, 2004 Suzuki GS500F - Current ride

SMF spam blocked by CleanTalk