graham7

This is my first post on here. I have hit some problems with my first serious project on Arduino and would appreciate some advice.

The device I am working on is to be mounted in a competition vehicle used for sprints and hillclimbs. These consist of a timed run over a course lasting up to 2 minutes. The objective is to get some feedback on performance during the run by dividing the course into 4 and comparing the time for each section to the previous best time. If it is better a green LED will light. The time difference to the best run will also be shown on an LCD.

The hardware consists of strip board Arduino with a green LED connected to pin 7 and a red LED on pin 13. There is also 16X2 LCD. I am using an A1120EUA-T Hall Effect Switch which senses a magnet glued to the wheel rim. This has a 10K pull up resistor connected across the positive and signal pins. It is connected to pin 2 and I am using an interrupt. There is also a button to change the course length on pin 8.

Everything is working fine when I spin the wheel on the car with it jacked up in the garage or when I drive very slowly, so the logic of my sketch would appear to work. When I drive at faster speeds the sector times will often miss being recorded resulting in nonsense results.

The maximum speed of the wheel is about 1800 RPM. It stops working at speeds well below this. Is the problem likely to be in that I have too much code in the sketch for the Arduino to process between interrupts or should I be using a different sensor? Perhaps a reed switch? I have run a test with the code to light the LED's commented out but this seems to make no difference.

I hope that I have explained this adequately. Any advice would be much appreciated.

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.Do not send technical questions via personal messaging - they will be ignored.I speak for myself, not Arduino.

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.Do not send technical questions via personal messaging - they will be ignored.I speak for myself, not Arduino.

Are you missing pulses from the wheel sensor? or are you not moving from one sector to the next? If you are missing pulses you probably have a mechanical problem. At speed things are moving or vibrating.

I definitely agree that you should use if (wheelrevs >= xxx). If you get 2 pulses in the time it takes the Arduino to loop around you will miss the transition from one sector to another. 1800 RPM is 30 Hz, which means 33 mS between pulses. Arduino's are not very fast. You could very easily miss a pulse and the fact that it works at low speed, but not at high speed would support that theory.

You can correct for the extra pulses by keeping a running average of pulse time and subtracting out the extra pulses to get closer to your actual sector time.

Hi, Arduino is not slow, 1800 rpm is only 30 events per second, which means that your Arduino can perform roughly 500,000 operations between revolutions this is several hundred times more than you need.

Its nice to see that you have a motor sports application, its close to my own interest. I don't know that you are taking the best approach.

Have a look at my RC/Kart lap timer, its uses infra red to time laps, you can create infra red beacons for about 2 dollars that you could position on the track for taking split times automatically.

Its small enough to strap to a steering wheel of a kart, but as I have found that I cannot always look at the wheel the most useful feature is a very loud buzzer. One buzz to confirm a lap/split has been captured and two pips if its a new best, it makes a huge difference to my RC driving, I cannot believe how much harder I work on a lap to get those two pips.

I am working on the project right now and plan to finish it within a few days at which point I will write it up in full, in the meantime check out the relevant blog posts here -

graham7

Thanks very much to both of you for your comments. You seem to disagree about the speed of Arduino. Being quite new to this I would have thought that 1800 RPM is relatively slow. The idea of a running average is a good one. I will need to get my head around how to code it.

Duane, your work with your lap timer looks really interesting. My problem is that at the venues I compete at it will not be easy to place beacons around the course. The organisers use an infra red timing system at the start and finish. Your idea of a buzzer sounds good. My objective is the same, to get immediate feedback on the part of the course I have just driven. I will spend some time looking at your work and get some ideas. You are at a much more advanced stage than me.

One other thought I have had is to build a test rig using a magnet mounted on an electric drill and use serial print to analyse what exactly is being missed at higher speeds.

Steve, I take your comment about looking at lights and displays while racing. I already have a shift light which is easy to see in my peripheral vision, I don't think another couple of LED's would be a problem. The display might be.

Thanks again both of you for your help. I haven't given up and will report how I get on here.

1800 RPM (30 Hz) is slow for a microprocessor. My concern was that the the Arduino boot loader takes time and performs a lot of error checking. It's not a lot, but it can add up. If you are doing a lot of things with standard Arduino functions it might take more than 30 mS to complete the loop. I don't know if that's what's happening to you, but it could be.

You can check for this with some test code that logs the time at the beginning of the loop for a few cycles and either displays it or spits it out on a serial link.

If the code never misses a pulse then wheelrevs == xxx should work. If changing to >= fixes the problem then there is not much else it could be.

graham7

Thanks Steve for your further input. I have not had much spare time over the last few weeks to work any further on this as I have started my sprint competitions. Had a win last week without the help of Arduino!

But today I have done a couple of tests:

As per your suggestion I put a time log at the start of the main loop and guess what it is taking 100ms to get round the loop.This is what it looks like on the serial monitor:

time=7535time=7636time=7737time=7837time=7938

So that is where my problem is.

I also wrote a simple sketch to check the sensor which displays the number of wheel revs on the lcd. I then drove the car at various speeds over the same distance. The wheel revs where the same for each drive. So now I know that the sensor is working correctly.

Now I have to work on modifying the sketch so that the loop takes less than 33ms. I don't think that using >= will work any better as won't it exit the loop as soon as the next pulse is detected?

33ms is forever in micro processor terms. My guess without seeing your latest code or giving more than a cursory glance to your previous code posted earlier in the topic is that the first problem is writing to the EEPROM, thats slow, you might be better off writing to an external SD Card which I believe is a lot faster.

Secondly the floating point maths is going to be slow.

I think I mentioned this project of mine to you before, I have made a lot more progress on it in the last few weeks -

graham7

A little more work and I think I have found the problem in my code, the delay in my button debounce. The code is such that it will go through one of the loops to check the button state every time. I took the delay out and the time to go round the loop is reduced to 10ms. Now it should catch every pulse.