View previous topic :: View next topic |
Author |
Message |
Johan_H
Joined: 13 Nov 2005 Posts: 19
|
Posted: Sun Nov 13, 2005 10:18 am Post subject: Car speedo with ABS pulses? |
|
|
Hello,
I'm a bit new to the AVR & Bascom, recently bought a Mavric 1B card från BDMicro (Mega 128).
I would like the AVR to act as a Speedometer in my car.. I know that my ABS wheel sensor gives 32 pulses / rotation. That, with my tire dimension, would be around ~65000 pulses @ a driven kilometer. With that info, one should be able to calculate the cars kilometers per hour speed.
Any ideas of the best way to do this? |
|
Back to top |
|
|
Frankeman
Joined: 11 Aug 2004 Posts: 948 Location: the Netherlands
|
Posted: Sun Nov 13, 2005 11:09 am Post subject: |
|
|
Hi,
Is your question about the hardware or the software.
The software is just a simple calculation.
Frank. |
|
Back to top |
|
|
Johan_H
Joined: 13 Nov 2005 Posts: 19
|
Posted: Sun Nov 13, 2005 11:18 am Post subject: |
|
|
I need ideas about the software solution.
I think I have the hardware solution ready, the pulses from the ABS is 12 v, I use a optocoupler to isolate it from the AVR and connect it to a port input. |
|
Back to top |
|
|
Frankeman
Joined: 11 Aug 2004 Posts: 948 Location: the Netherlands
|
Posted: Sun Nov 13, 2005 11:42 am Post subject: |
|
|
Hi,
The port pin where you put the pulses on must have an interrupt, like int0 or int1.
Set up a 1 second timer.
Count the pulses in the interrupt routine.
If the circumference of the tire is 1 meter and you count 32 pulses then the car speed is 1 meter/second.
Frank. |
|
Back to top |
|
|
Johan_H
Joined: 13 Nov 2005 Posts: 19
|
Posted: Sun Nov 13, 2005 4:23 pm Post subject: |
|
|
I don't have the skills yet to write such a routine, , beginner I know - but I have not worked with interrupts before. I've just converted to AVR from Basic Stamp.
Does that mean the the AVR will be busy for 1 second and the other part of the program will temporarly halt executing? *willing to learn* |
|
Back to top |
|
|
Frankeman
Joined: 11 Aug 2004 Posts: 948 Location: the Netherlands
|
Posted: Sun Nov 13, 2005 5:07 pm Post subject: |
|
|
Your program runs trough his loop where it can do anything you want.
But when there comes a pulse the interrupt routine is called.
In this routine the pulses are counted.
After one second the timer interrupt routine is called.
Within there you calculate the speed and reset the pulse counter.
From there the whole story begins again. |
|
Back to top |
|
|
Johan_H
Joined: 13 Nov 2005 Posts: 19
|
Posted: Sun Nov 13, 2005 5:27 pm Post subject: |
|
|
So...
32 pulses @ every wheel rotation.
One wheel rotation = 1,8 meter.
320 pulses in one second
320/32 = 10
10 * 1,8 = 18
18 * 3,6 = 64,8 km/h
967 pulses in one second
961/32 = 30
30 * 1,8 = 54
54 * 3,6 = 194,4 km/h
The hard part is the timer interrupts, I'm not sure how to write that.
Assume the "PULSIN" is the command to use. Well, maybe I can find any example file on the internet to learn from.
Last edited by Johan_H on Wed Nov 16, 2005 6:45 am; edited 1 time in total |
|
Back to top |
|
|
tomi
Joined: 22 Feb 2005 Posts: 155 Location: Universe
|
Posted: Sun Nov 13, 2005 10:04 pm Post subject: |
|
|
Johan_H wrote: | I need ideas about the software solution.
I think I have the hardware solution ready, the pulses from the ABS is 12 v, I use a optocoupler to isolate it from the AVR and connect it to a port input. |
One note, are you sure what are you doing ? Playing with ABS system is not funny, you must know how it work and you must calculate with problems like : ABS stop working, you can get lot of errors stored in ECU .... ABS control unit are very sensitive to correct pulses and when you make load on one of sensors, control unit can make problems ! Next thing is pulses from ABS sensor, try look here : http://www.sjmautotechnik.com/trouble_shooting/brake.html or http://www.sjmautotechnik.com/trouble_shooting/misc_waveform.html .
I am not sure if with optocoupler you get right signal.
You not has classic speed sensor in gearbox ? I know about cars what has ABS and pulses for tachometer is taking from ABS control unit (not direct from sensors !) but still has sensor in gerabox but is not connected.
For your safety I recommend you found another solution than ABS sensors.
Take care ! _________________ Best regards,
/Tomi |
|
Back to top |
|
|
Frankeman
Joined: 11 Aug 2004 Posts: 948 Location: the Netherlands
|
Posted: Sun Nov 13, 2005 10:33 pm Post subject: |
|
|
connect a 32.768 khz crystal to pin 18 and 19
And try the example.
Code: |
$regfile "m128def.dat"
$crystal = 12000000
config Clock = Soft
config PinD.0 = input 'this is the int0 pin, put the wheel pulses in here
config int0 = Rising
const WheelCircumference = 1.8
dim Second as byte
dim PulseCounter as word
dim RotationsPerSecond as single
dim MeterPerSecond as single
dim KilometerPerHour as single
Second = _Sec
PulseCounter = 0
on int0 PulseInt
enable int0
enable interrupts
do
if Second <> _Sec then
RotationsPerSecond = PulseCounter / 32
MeterPerSecond = RotationsPerSecond * WheelCircumFerence
KilometerPerHour = MeterPerSecond * 3.6
print Fusing(KilometerPerHour, "#.##")
PulseCounter = 0
end if
loop
end
PulseInt:
incr PulseCounter
return
|
|
|
Back to top |
|
|
Johan_H
Joined: 13 Nov 2005 Posts: 19
|
Posted: Mon Nov 14, 2005 6:56 am Post subject: |
|
|
tomiOne wrote: | note, are you sure what are you doing ?
|
Thank you for your concern. I may be a bit newbe at programming AVR's, but I think I know what I'm doing when it comes to the hardware.
I'm already using the ABS pulses to an VDO aftermarket speedo, so it works fine. I'm not getting the pulses directly from the sensors, I use the outputs on the ABS ECU that used to be connected to the ETC (Electronic Traction Control). The ETC has been removed as I'm running with an programable aftermarket fuel/ignition ECU. |
|
Back to top |
|
|
Johan_H
Joined: 13 Nov 2005 Posts: 19
|
Posted: Mon Nov 14, 2005 7:05 am Post subject: |
|
|
Frankeman wrote: | connect a 32.768 khz crystal to pin 18 and 19
And try the example.
|
I'll will test this when I get home from work.
I really appriciate your help, thank you!
(I'm running a DS1307 hardware RTC, so I use that for timing) |
|
Back to top |
|
|
tomi
Joined: 22 Feb 2005 Posts: 155 Location: Universe
|
Posted: Mon Nov 14, 2005 12:29 pm Post subject: |
|
|
Johan_H wrote: | tomiOne wrote: | note, are you sure what are you doing ?
|
Thank you for your concern. I may be a bit newbe at programming AVR's, but I think I know what I'm doing when it comes to the hardware.
I'm already using the ABS pulses to an VDO aftermarket speedo, so it works fine. I'm not getting the pulses directly from the sensors, I use the outputs on the ABS ECU that used to be connected to the ETC (Electronic Traction Control). The ETC has been removed as I'm running with an programable aftermarket fuel/ignition ECU. |
Oki From your first post it looks like you want use pulses direct from sensor and not from ABS CU ( ,,I know that my ABS wheel sensor gives 32 pulses / rotation.,,) _________________ Best regards,
/Tomi |
|
Back to top |
|
|
ATIU
Joined: 15 Oct 2004 Posts: 534
|
Posted: Mon Nov 14, 2005 12:52 pm Post subject: |
|
|
I would strongly suggest using Timer/Counter 1 (16 bit counter) rather than Int0/Int1. My experience is using soft counter via intrrupts will loose count or intrrupt occurs too often. Since you cannot exceed 1,000 pulse per second, then you don't have to worry about timer/counter1 to overflow, just when the soft clock 1 second interrupt occurs (timer2), then you can check the value of timer/counter1, calculate your speed and reset timer/counter1 back to zero. |
|
Back to top |
|
|
Johan_H
Joined: 13 Nov 2005 Posts: 19
|
Posted: Mon Nov 14, 2005 12:56 pm Post subject: |
|
|
ATIU wrote: | I would strongly suggest using Timer/Counter 1 (16 bit counter) rather than Int0/Int1. My experience is using soft counter via intrrupts will loose count or intrrupt occurs too often. Since you cannot exceed 1,000 pulse per second, then you don't have to worry about timer/counter1 to overflow, just when the soft clock 1 second interrupt occurs (timer2), then you can check the value of timer/counter1, calculate your speed and reset timer/counter1 back to zero. |
Okey.. Program example?
I will exceed 1000 pulse per second as the actuall car has a top speed of more than 200 km/h. |
|
Back to top |
|
|
ATIU
Joined: 15 Oct 2004 Posts: 534
|
Posted: Mon Nov 14, 2005 11:37 pm Post subject: |
|
|
1.8 meter x 3.14 (PI) = 5.652 meter per revolution
5.652 / 32 = 0.176625 meter per pulse
0.176625 x 60 (sec/min) x 60 (min/hour) = 635.85 meters per hour
635.85 / 1000 = 0.63585 Km/hr/pulse
or
1 / 0.63585 = 1.5727 pulses/km/hr
Hookup your pulse input to T1 (Timer1/Counter1 input)
Hookup 32.768 KHZ xtal T2 source, no need for the dallas external clock
Hookup LCD
Program lines below:
Dim Speed as Word
Dim Speed_$ as String * 5
Config Timer1 = Counter, Edge = Falling, Prescale = 1
Config Timer2 = Timer, ASYNC=ON, PRESCALE = 128
On TIMER2 Timer2_ISR
ENABLE INTERRUPTS
ENABLE TIMER2
'Main Program
Cursor Off NoBlink
Cls
Do
Speed_$ = STR (Speed)
Speed_$ = Format (Speed_$, " 0.0") 'There are two space between the double quote and the first zero
Locate 1, 1
LCD "Speed is " ; Speed_$ ; " Km/hr"
Wait 1 'Do nothing for 1 second
Loop
End
'ISR
Timer2_ISR:
Speed = Counter1
Counter1 = 0
Speed = Speed * 6.3585 'x 10 km/hr
Return |
|
Back to top |
|
|
|