False interrupts on bike R.P.M. reading - Panda II

Before I tested on the bike I built a small simple pulse generator circuit around a 555 ic. I was able to get this up to about 350 kHz.

On the bike, being a 2 cylinder, I would get 2 pulses per revolution. The pulse generator therefore can give me an R.P.M. reading of up to about 10500 R.P.M.

With this pulse generator connected to the Panda II it gives me very stable readings with no false interrupts.

So, full of hope I went to connect it to the bike but needless to say I was quite dissapointed. Connected to the bike I got very unstable reading which indicates I’m getting lots of false interrupts.

Below is the output I get at a fairly stable idle of around 900 R.P.M.
Just look at the very first number for the R.P.M. I get. The second number incidentally is supposed to be the speed but with the rear wheel standing still it should be stable at 0 which is also not the case.

2179 - 1 - 0.00076097560975609761 - 0.00076097560975609761
2179 - 1 - 0.00076097560975609761 - 0.00076097560975609761
1487 - 1 - 0.00076097560975609761 - 0.00076097560975609761
1487 - 1 - 0.00076097560975609761 - 0.00076097560975609761
1269 - 1 - 0.00076097560975609761 - 0.00076097560975609761
1269 - 1 - 0.00076097560975609761 - 0.00076097560975609761
1339 - 1 - 0.00076097560975609761 - 0.00076097560975609761
1339 - 1 - 0.00076097560975609761 - 0.00076097560975609761
1472 - 1 - 0.00076097560975609761 - 0.00076097560975609761
1472 - 1 - 0.00076097560975609761 - 0.00076097560975609761
1431 - 1 - 0.00076097560975609761 - 0.00076097560975609761
1431 - 1 - 0.00076097560975609761 - 0.00076097560975609761
1431 - 1 - 0.00076097560975609761 - 0.00076097560975609761
1241 - 2 - 0.0015219512195121952 - 0.0015219512195121952
1509 - 2 - 0.0015219512195121952 - 0.0015219512195121952
1509 - 2 - 0.0015219512195121952 - 0.0015219512195121952
1554 - 2 - 0.0015219512195121952 - 0.0015219512195121952
1554 - 2 - 0.0015219512195121952 - 0.0015219512195121952
1562 - 2 - 0.0015219512195121952 - 0.0015219512195121952
1562 - 2 - 0.0015219512195121952 - 0.0015219512195121952
1511 - 2 - 0.0015219512195121952 - 0.0015219512195121952
1511 - 2 - 0.0015219512195121952 - 0.0015219512195121952
1133 - 2 - 0.0015219512195121952 - 0.0015219512195121952
1133 - 2 - 0.0022829268292682927 - 0.0022829268292682927
1331 - 2 - 0.0022829268292682927 - 0.0022829268292682927
1331 - 2 - 0.0022829268292682927 - 0.0022829268292682927
1525 - 2 - 0.0022829268292682927 - 0.0022829268292682927
1525 - 2 - 0.0022829268292682927 - 0.0022829268292682927
1327 - 2 - 0.0022829268292682927 - 0.0022829268292682927
1327 - 2 - 0.0022829268292682927 - 0.0022829268292682927
1489 - 2 - 0.0022829268292682927 - 0.0022829268292682927
1489 - 2 - 0.0022829268292682927 - 0.0022829268292682927
1265 - 2 - 0.0022829268292682927 - 0.0022829268292682927
1265 - 3 - 0.0030439024390243904 - 0.0030439024390243904
1453 - 3 - 0.0030439024390243904 - 0.0030439024390243904
1453 - 3 - 0.0030439024390243904 - 0.0030439024390243904
1453 - 3 - 0.0030439024390243904 - 0.0030439024390243904
1303 - 3 - 0.0030439024390243904 - 0.0030439024390243904
1499 - 3 - 0.0030439024390243904 - 0.0030439024390243904
1499 - 3 - 0.0030439024390243904 - 0.0030439024390243904
1628 - 3 - 0.0030439024390243904 - 0.0030439024390243904
1628 - 3 - 0.0030439024390243904 - 0.0030439024390243904
1590 - 3 - 0.0030439024390243904 - 0.0030439024390243904
1590 - 3 - 0.0030439024390243904 - 0.0030439024390243904
1304 - 3 - 0.0038048780487804881 - 0.0038048780487804881
1304 - 3 - 0.0038048780487804881 - 0.0038048780487804881
1540 - 3 - 0.0038048780487804881 - 0.0038048780487804881
1540 - 3 - 0.0038048780487804881 - 0.0038048780487804881
1781 - 3 - 0.0038048780487804881 - 0.0038048780487804881
1648 - 3 - 0.0038048780487804881 - 0.0038048780487804881
1648 - 3 - 0.0038048780487804881 - 0.0038048780487804881
1464 - 3 - 0.0038048780487804881 - 0.0038048780487804881
1464 - 3 - 0.0038048780487804881 - 0.0038048780487804881
1632 - 3 - 0.0045658536585365854 - 0.0045658536585365854
1632 - 3 - 0.0045658536585365854 - 0.0045658536585365854
1584 - 3 - 0.0045658536585365854 - 0.0045658536585365854
1645 - 3 - 0.0045658536585365854 - 0.0045658536585365854
1645 - 3 - 0.0045658536585365854 - 0.0045658536585365854
1639 - 3 - 0.0045658536585365854 - 0.0045658536585365854
1639 - 3 - 0.0045658536585365854 - 0.0045658536585365854
1639 - 3 - 0.0045658536585365854 - 0.0045658536585365854
1202 - 3 - 0.0045658536585365854 - 0.0045658536585365854
1682 - 3 - 0.0045658536585365854 - 0.0045658536585365854
1682 - 3 - 0.0053268292682926831 - 0.0053268292682926831
1617 - 3 - 0.0053268292682926831 - 0.0053268292682926831
1700 - 3 - 0.0053268292682926831 - 0.0053268292682926831
1700 - 3 - 0.0053268292682926831 - 0.0053268292682926831
1601 - 3 - 0.0053268292682926831 - 0.0053268292682926831
1601 - 3 - 0.0053268292682926831 - 0.0053268292682926831
1328 - 3 - 0.0053268292682926831 - 0.0053268292682926831
1328 - 3 - 0.0053268292682926831 - 0.0053268292682926831
1626 - 3 - 0.0053268292682926831 - 0.0053268292682926831
1626 - 3 - 0.0060878048780487809 - 0.0060878048780487809
1584 - 3 - 0.0060878048780487809 - 0.0060878048780487809
1584 - 3 - 0.0060878048780487809 - 0.0060878048780487809
1616 - 3 - 0.0060878048780487809 - 0.0060878048780487809
1544 - 3 - 0.0060878048780487809 - 0.0060878048780487809
1544 - 3 - 0.0060878048780487809 - 0.0060878048780487809
1630 - 3 - 0.0060878048780487809 - 0.0060878048780487809
1630 - 3 - 0.0060878048780487809 - 0.0060878048780487809
1588 - 3 - 0.0060878048780487809 - 0.0060878048780487809
1588 - 3 - 0.0060878048780487809 - 0.0060878048780487809
1741 - 3 - 0.0068487804878048786 - 0.0068487804878048786
1477 - 3 - 0.0068487804878048786 - 0.0068487804878048786
1477 - 3 - 0.0068487804878048786 - 0.0068487804878048786
1678 - 3 - 0.0068487804878048786 - 0.0068487804878048786
1678 - 3 - 0.0068487804878048786 - 0.0068487804878048786
1725 - 3 - 0.0068487804878048786 - 0.0068487804878048786
1725 - 3 - 0.0068487804878048786 - 0.0068487804878048786
1476 - 3 - 0.0068487804878048786 - 0.0068487804878048786
1476 - 3 - 0.0068487804878048786 - 0.0068487804878048786
1302 - 3 - 0.0076097560975609763 - 0.0076097560975609763
1302 - 3 - 0.0076097560975609763 - 0.0076097560975609763
1494 - 3 - 0.0076097560975609763 - 0.0076097560975609763
2381 - 3 - 0.0076097560975609763 - 0.0076097560975609763
2381 - 3 - 0.0076097560975609763 - 0.0076097560975609763
1652 - 3 - 0.0076097560975609763 - 0.0076097560975609763
1648 - 3 - 0.0076097560975609763 - 0.0076097560975609763
1648 - 3 - 0.0076097560975609763 - 0.0076097560975609763
1596 - 3 - 0.0076097560975609763 - 0.0076097560975609763
1596 - 3 - 0.008370731707317074 - 0.008370731707317074
1568 - 3 - 0.008370731707317074 - 0.008370731707317074
1568 - 3 - 0.008370731707317074 - 0.008370731707317074
1677 - 3 - 0.008370731707317074 - 0.008370731707317074
1618 - 3 - 0.008370731707317074 - 0.008370731707317074
1618 - 3 - 0.008370731707317074 - 0.008370731707317074
1331 - 3 - 0.008370731707317074 - 0.008370731707317074
1331 - 3 - 0.008370731707317074 - 0.008370731707317074
1521 - 3 - 0.008370731707317074 - 0.008370731707317074
1521 - 3 - 0.008370731707317074 - 0.008370731707317074
1213 - 3 - 0.0091317073170731709 - 0.0091317073170731709
1213 - 3 - 0.0091317073170731709 - 0.0091317073170731709
1588 - 3 - 0.0091317073170731709 - 0.0091317073170731709
1588 - 3 - 0.0091317073170731709 - 0.0091317073170731709
1265 - 3 - 0.0091317073170731709 - 0.0091317073170731709
1265 - 3 - 0.0091317073170731709 - 0.0091317073170731709
1694 - 3 - 0.0091317073170731709 - 0.0091317073170731709
1694 - 3 - 0.0091317073170731709 - 0.0091317073170731709
1539 - 3 - 0.0091317073170731709 - 0.0091317073170731709
1539 - 3 - 0.0091317073170731709 - 0.0091317073170731709
1687 - 3 - 0.0098926829268292677 - 0.0098926829268292677
1622 - 3 - 0.0098926829268292677 - 0.0098926829268292677
1622 - 3 - 0.0098926829268292677 - 0.0098926829268292677
1667 - 3 - 0.0098926829268292677 - 0.0098926829268292677
1667 - 3 - 0.0098926829268292677 - 0.0098926829268292677
1657 - 3 - 0.0098926829268292677 - 0.0098926829268292677
1657 - 3 - 0.0098926829268292677 - 0.0098926829268292677
1234 - 3 - 0.0098926829268292677 - 0.0098926829268292677
1234 - 3 - 0.0098926829268292677 - 0.0098926829268292677
1655 - 3 - 0.0098926829268292677 - 0.0098926829268292677
1839 - 3 - 0.010653658536585365 - 0.010653658536585365
1839 - 3 - 0.010653658536585365 - 0.010653658536585365
2178 - 3 - 0.010653658536585365 - 0.010653658536585365
2178 - 3 - 0.010653658536585365 - 0.010653658536585365
1362 - 3 - 0.010653658536585365 - 0.010653658536585365
1362 - 3 - 0.010653658536585365 - 0.010653658536585365
1471 - 3 - 0.010653658536585365 - 0.010653658536585365
1621 - 3 - 0.010653658536585365 - 0.010653658536585365
1621 - 3 - 0.011414634146341461 - 0.011414634146341461
1670 - 3 - 0.011414634146341461 - 0.011414634146341461
1670 - 3 - 0.011414634146341461 - 0.011414634146341461
1777 - 3 - 0.011414634146341461 - 0.011414634146341461
1675 - 3 - 0.011414634146341461 - 0.011414634146341461
1675 - 3 - 0.011414634146341461 - 0.011414634146341461
1631 - 3 - 0.011414634146341461 - 0.011414634146341461
1631 - 3 - 0.011414634146341461 - 0.011414634146341461
1585 - 3 - 0.011414634146341461 - 0.011414634146341461
1585 - 3 - 0.012175609756097558 - 0.012175609756097558
1463 - 3 - 0.012175609756097558 - 0.012175609756097558
1674 - 3 - 0.012175609756097558 - 0.012175609756097558
1674 - 3 - 0.012175609756097558 - 0.012175609756097558
1713 - 3 - 0.012175609756097558 - 0.012175609756097558

I now do not know whereto from here and must admit I do feel fairly dissapointed.

my first impression is - its probably noise that’s your issue.

First question: Wiring. How is the Panda wired to the bike, especially GND?

2nd question: how is the interrupt pin connected to the bike, do you have any pullup/down on it?

I think you’ll need to debounce the input.

I had also additional IRQ readings using a IRQpin (see http://www.tinyclr.com/forum/2/4660/)

The solution was to increase the glitch filter time.

But you should also have a look at the noise of your circuit. Having a motor connected and a generator I guess as well also the ground might have a lot of spikes. Can an opto coupler or a filter help?

@ Brett: for this test the board was running on USB. I used an optocoupler and connected it to the Negative of the tacho on the bike and to the R.P.M signal wire. Then from the transistor side of the optocoupler I used a pullup resistor and connected to Di11 and to GND.

@ Wouter: How would I debounce a signal that can vary from less than 10HZ to about 360Hz?

@ SteH: I cannot use the glitchfilter for this and especially increasing it will cause it to miss valid pulse.

There is no need to use the glitch filter. Just add the line


            Cpu.GlitchFilterTime = new TimeSpan(1000000L);

later I use an InterruptPort


            LightBarrier = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di5, [b]false[/b],
            Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

with disabled glitch filter (in bold above). But still there is a difference as I don’t get spurious IRQs when setting the time to a very high value. Don’t ask me why it behaves like that - I shouldn’t in my opinion - but it does!

[quote]Don’t ask me why it behaves like that - I shouldn’t in my opinion - but it does!
[/quote]
I would agree that it shouldn’t affect things when the filter is not in use. Personally I haven’t seen any positive impact on this (set glitch filter but not use it) for me.

Jaques, one other suggestion. Even though you’re using an optocoupler, can I suggest you test if connecting GNDs of the bike and the Fez gives you any different result? Although I still think the noise is more likely to be on the input to the opto…

SteH, thanks I’ll try that even if it doesn’t make any logical sense.

Brett, I also think the noise must be on the bike’s side but it can’t hurt to try your suggestion with connecting the GND’s

Could you try to display the time (Ticks) of the interrupts? Or is it already shown in the original data?
Do you get a signal of the form _________|-|_______|-|? If yes then you could try to invert it before connecting it to the pin of the panda.

I haven’t yet had any chance to go and test on the bike again. Been fixing my car’s waterpump and I’m also sitting with flu. So as soon as I’m feeling better again I’ll go and check things out.

No, the ticks is not in the original data…I’ll add that before doing my next test.

I don’t follow you on the form of the signal…

I managed to do a new test on the bike this time including the milliseconds between interrupts too. As you can see the interval vary greatly:

RPM: 1539
7.8686999999999996
7.1912000000000003
20.2578
22.008900000000001
7.4770000000000003
38.938899999999997
RPM: 1808
19.647500000000001
7.6805000000000003
7.0425000000000004
20.682600000000001
22.594200000000001
7.6299999999999999
RPM: 1808
32.639499999999998
20.426600000000001
8.0035000000000007
37.000300000000003
23.924499999999998
7.9672999999999998
RPM: 1687
34.815800000000003
30.055800000000001
7.8834
21.948599999999999
RPM: 1687
24.4892
8.1144999999999996
35.320700000000002
56.807499999999997
8.4616000000000007
RPM: 1342
29.6998
24.309799999999999
8.0699000000000005
35.404600000000002
21.8217
RPM: 1342
8.6120999999999999
7.9808000000000003
21.652000000000001
45.760800000000003
8.0129000000000001
35.112200000000001
RPM: 1600
21.842500000000001
8.6151
7.9847999999999999
22.034099999999999
24.635300000000001
8.1386000000000003

Is it possible to build some kind of “conditioning” circuit to filter out the noise?

A lot of them are - as in my case - values of 6 - 8 ms. Try the glitch filter settings I proposed earlier.

In my handler I checked for the last state and accepted it only when the state had changed.


   if (laststate == data2)
       return;     // return if state has not changed
...

  // set laststate to current value
  laststate = data2;
  return;

This is a tough one if you cannot see the signal on a scope.

Maybe try this… Connect the transistor side of the opto to an analog pin in parallel to your interrupt pin. In a tight loop, read the value and write it with a time stamp to the SD card. Import the data into Excel and plot it. You might see a pattern or glitches or whatever. It will not be very accurate but might help.

Also try some small capacitors, say 1uF to 47uF across the LED of the opto. It should smooth out any small glitches at different frequencies.

I guess it is also possible that the tacho signal is a triangle wave with the slope being proportional to rpm. Try the analog sample trick to see ad good luck!

That all sounds like a plan :slight_smile:

I guess you want to see if I can get some analog value which is proportional to the RPM?

The caps…do they need to be polarized or non-polarized?

I guess I won’t know what kind of signal I’m getting without a scope. I’ll keep my eyes open for a basic 2nd hand unit…not that I’ve got much money for one ???

Cap should be polarised.

The cap will charge up on a high signal and then slowly decay on a low by powering the led. The idea is to create a filter that will eat the glitches.

The idea with the analog in is to record the signal amplitudes to see what it looks like. It is a real ghetto scope but at low frequencies is could work. You will either see square(ish) pulses or a constant voltage proportional to rpm. Either way by seeing the signal you can take your next step.

Keep an eye out for the ScopeShield project. I’m making good progress in getting an el cheapo scope precisely for this kind of thing.

Try this… Poor Man's Oscilloscope

I love the poor man’s oscilloscope! Thanks for the link. Am I right in thinking that I only need to connect either the “left” or the “right” channel when I’m only checking one signal?

I’ll definitely keep an eye out for your ScopeShield. When I eventually have this project of mine working and debugged and I want to build it for other bikes too then I’ll have to have something like that.

I need to go to Communica in any case just now so will get a few capacitors too.

Get a 100k pot for the voltage divider so you can scale the signal.

You can watch the raw tacho on one channel and the opto on the other.

To be safe, first measure the voltage on the voltage divider with a multimeter and make sure it doesn’t go over 1v before you plug it into your PC.

You’ll have to connect the PC soundcard ground to the bike ground first and then to opto ground.

Also try this.

Electronics: Soundcard-Oscilloscope

You can use any general purpose op amp. Ask the guy at Communica.

Have you tried the software solution? it costs only some time.