PDA

View Full Version : Reading a speed sensor best method?



davewanna
- 23rd January 2012, 10:58
I apologise in advance for the stupid questions, but I'm pretty green and haven't been able to find an example of what I want to do in the search.

I am trying to read a speed signal coming from a gearbox on a car, this is a very siml

davewanna
- 23rd January 2012, 11:12
Apparently I hit enter before I should have before, then I took too long to edit the post. So here is what it was meant to be.....

I apologise in advance for the stupid questions, but I'm pretty green and haven't been able to find an example of what I want to do in the search.

I am trying to read a speed signal coming from a gearbox on a car, this is a very simple reed switch in the gearbox that has a magnet on the output shaft. I have a 5V pullup on that line, and have tried a few methods for reading the pin.

I have tried COUNT but haven't been able to get a consistant result. Not one that increases with the speed of the car anyway.

I currently use PULSIN to read the tacho squarewave, which works well, but only as I don't have to wait very long. With the car going at slow road speeds, the speedo signal frequency is quite slow, and slows down the whole program. Not to mention, it doesn't seem to give consistant results.

I feel I should be trying to use the CCP capture command to count pulses in the background, but I have no real experience with the CCP side of things yet, and despite reading the datasheet, and some notes about the CCP, I haven't yet got a grasp on it.

Does anyone know of a sample of CCP being used in the type of situation I am chasing? I just need to see it working to grasp it I think.


Thanks in advance...

Dave

mackrackit
- 23rd January 2012, 11:18
Read this thread
http://www.picbasic.co.uk/forum/showthread.php?t=9037&highlight=tach+for+tired+eyes

davewanna
- 24th January 2012, 10:11
Cheers for that Dave, looks like it will help me out a lot. It's pouring rain here so haven't had a chance to jack the back wheels up and test the car out yet.
But no doubt I will have more questions soon.

Looking at my post history, I found I originally asked this question in 2009, but didn't really have the time to sort it out, so I programmed the car to change gear based on RPM, not on speed, and then pretty much forgot about it. There was helpful posts in that thread also. Surely I have enough to make some progress now, if only this rain would stop.

Cheers

Art
- 26th January 2012, 03:43
Did you put the sensor there yourself? or is it part of the vehicle?
There should be a logic signal at the ECU.

But, yeah, anyway, external interrupt on the rising edge of the signal.

((variable pulses counted in a second X 3600) / constant pulses per km) X 3600 = Kilometers per hour!

davewanna
- 26th January 2012, 12:41
It's a factory sensor in the gearbox, but there is more than one. There is also two ECU's, one for the engine, one for the gearbox, that I am replacing, as the engine has been replaced with something more powerful, and now changes gear too soon.

I haven't been able to work out interrupts yet, do I have to use the CCP1 pin? I haven't used interrupts at all, is there a "dummy's guide" anywhere? haha

I programmed it today to read with PULSIN. I am reading the tacho, and the speedo now with PULSIN, but the reults are average. There is some 'contact bounce' with the speed sensor, that gives me erratic readings. I have programmed it to take two readings, and only use them if they are similar which is working. But with the PULSIN_MAX @ 10000, reading the RPM, and the SPEEDO, and sometimes having to re-read the speedo, the whole program runs fairly slow until the car speed, and the RPM increase. I would still like to get the capture interrupts working.

Also, I have run out of program space. It's a project that has grown over time, and now it handles the auto gearbox, monitors engine specs, and does climate control. Also has a setup menu where sensors can be calibrated, and gearbox and air-con settings can be changed. Current pic is a 16F877A.

From what I can tell, the 18F452 is pin compatible, and has twice the program space. Would it be viable for me to port my code over to the 18F452? I have only used 16F devices before.

Thanks...

Jumper
- 26th January 2012, 13:10
Hi,

If you plan to change from the 877A to something else I recommend 18F4620 (which is also pin-compatible). That will give you 64K Flash and alot more RAM. The only reason the 452 would be an option is if you cant get the 4620.

Do not worry about changing from the 877A, the 4620 is still easy to handle and has multiple INT inputs that you will find really useful.

Art
- 26th January 2012, 16:09
I have had a 16F877A (@4MHz) working in a hot car cab for two months without a reset. That is a plug for the hardware.

Some of the goodies that come with basic block execution of your program (and PULSIN will be one of them) where interrupts will not.
All I can say is search for Darrel Taylor instant interrupts or study Microchip datasheets to do it yourself, (but you'll probably need an example anyway).
The effect a bit like multitasking, your program does not appear to be held up while pulses are being counted.

davewanna
- 27th January 2012, 02:37
Jumper: Thanks for the info on the 4620, looks like the 452 will do, but the 4620 will be better.

Art: I had a quick look at your projects, and you might be interested to know this auto controller is actually in a Surf. And I am doing a digital speedo type of arrangement for my hilux ute also, except instead of numbers, I am using the motors out of a motorcycle dash to move the factory needles.

I will look through your other projects later.

Thanks!

Dave