CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Help with car speedo meter

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Help with car speedo meter
PostPosted: Mon Oct 16, 2006 2:24 pm     Reply with quote

Hi iam trying to make speedometer for my car
i get speed pulse from the car and then transform it to pic then lcd
i used the Ex_freqc and modified it to show the pulse on the lcd
i had measure the frequency with my fluke and i've got readings from the speed pulse like when iam at 30 km/h i got 5000 hz
so i will do some math to transform it from Hz to Km/h the weird thing that i put the lcd_init(); in the loop and the lcd was blinking and test it in vechile the counter started to go up and down according to the speed i was pleased that i got some results but as known i was putting 12V to the pin of the PIC the C0 and C1 pins gone, so i put resistor and zener to protect the pin and got no result from the car rarely i was got 1 or 3 pulses
here is my code

Code:
#include <16F876A.h>
#fuses HS,NOWDT,NOLVP
#use delay(clock=20000000)    //one instruction=0.2us
#bit t1_overflow = 0x0C.0     // Input pin
#include "LCD.c"
void main() {
   int cycles8, cycles;
   int32 freq ;
   long freqc_high;
   long freqc_low;
   lcd_init();
   while (TRUE) {
      cycles8=0;
      cycles=0;
      freqc_high=0;
      t1_overflow=0;
      set_timer1(0);
      setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
/* ___ wait one second ___  */
      while (cycles!=0xFF) { //true=3, false=4
       cycles8=0; //1 cycle
       //start inner loop
       while (cycles8!=0xFF) { //true=3, false=4
         if (t1_overflow)//true=2,false=3             //----|
            {t1_overflow=0;freqc_high++;}//6 cycles   //    |
         else                                         //    |-- 8 cycles
            {delay_cycles(5);}                        //----|
         delay_cycles(62); //x
         cycles8++; //1
  }
 delay_cycles(216);      //y
 cycles++;          ///1 cycle
}
      delay_cycles(211);   //z
/* ___ end waiting 1 second ___ */
      setup_timer_1(T1_DISABLED);   //turn of counter to prevent corruption while grabbing value
      if (t1_overflow)            //check one last time for overflow
          freqc_high++;
      freqc_low=get_timer1();      //get timer1 value as the least sign. 16bits of freq counter
      freq=make32(freqc_high,freqc_low);   //use new make32 function to join lsb and msb
     printf(lcd_putc,"\f     %LU KM  ",freq);      //and print frequency  //Here You put your formula of speed


what's the wrong ! why the freq counter dosen't count
Guest








PostPosted: Tue Oct 17, 2006 7:44 am     Reply with quote

anybody can Help me !
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 17, 2006 2:38 pm     Reply with quote

The reason no one wants to help is because the code in your post
is very poorly formatted.

1. The comments are too long and they wrap around to the next line.

2. You have several C statements on the same line.

3. You have some kind of ASCII art in there, and it's all messed up.

The code is basically unreadable.

You need to carefully re-format your code, and use the PREVIEW
button to check it, before you post it. Also, after you post, look
at the code and if the formatting is still bad, then EDIT the post
and fix it. Then people will likely help.
necati



Joined: 12 Sep 2003
Posts: 37
Location: istanbul

View user's profile Send private message

speed
PostPosted: Tue Oct 17, 2006 4:06 pm     Reply with quote

#include <16F877A.h>
#fuses HS,NOWDT,NOLVP
#use delay(clock=20000000) //one instruction=0.2us
#bit t1_overflow = 0x0C.0 // Input pin c1
#include "LCD.c"
#define use_portb_lcd
void main() {
int cycles8, cycles;
int32 freq ;
long freqc_high;
long freqc_low;
lcd_init();
while (TRUE) {
cycles8=0;
cycles=0;
freqc_high=0;
t1_overflow=0;
set_timer1(0);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
/* ___ wait one second ___ */
while (cycles!=0xFF) { //true=3, false=4
cycles8=0; //1 cycle
//start inner loop
while (cycles8!=0xFF) { //true=3, false=4
if (t1_overflow)//true=2,false=3 //----|
{t1_overflow=0;freqc_high++;}//6 cycles // |
else // |-- 8 cycles
{delay_cycles(5);} //----|
delay_cycles(62); //x
cycles8++; //1
}
delay_cycles(216); //y
cycles++; ///1 cycle
}
delay_cycles(211); //z
/* ___ end waiting 1 second ___ */
setup_timer_1(T1_DISABLED); //turn of counter to prevent corruption while grabbing value
if (t1_overflow) //check one last time for overflow
freqc_high++;
freqc_low=get_timer1(); //get timer1 value as the least sign. 16bits of freq counter
freq=make32(freqc_high,freqc_low); //use new make32 function to join lsb and msb
freq=freq/(500/3);//****************************************
printf(lcd_putc,"\f %LU kmh ",freq); //and print frequency //Here You put your formula of speed

}}
info@ckmintech.com



Joined: 16 May 2006
Posts: 39

View user's profile Send private message

PostPosted: Tue Oct 17, 2006 8:41 pm     Reply with quote

Recently we have built a very similar device for our client (the speed and mileage data is sent to a PC). I cannot give you the source code, however you should consider the following desgin hints.

1. K-value ( how many pulses you will receive for travelling 1 km)

2. connect the pulse output of the car to a 78L05 input and 78L05 output to a chip pin which has interrupt-on-change feature. The input and ouput of 78L05 should have a 0.1u cap to the ground.

3. Setup port-change-interrupt to count how many pulse received
4. setup RTCC interrupt to count number of pulse received in a fixed period, using simple calculation you can get the speed.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 17, 2006 8:58 pm     Reply with quote

Quote:

2. connect the pulse output of the car to a 78L05 input and 78L05
output to a chip pin which has interrupt-on-change feature.

That's a 5v voltage regulator.
Guest








PostPosted: Wed Oct 18, 2006 9:07 am     Reply with quote

i heard that measuring pulses by frequency
is faster than interrupt (faster update) is that right ?

and what about the interference in the car to pic ?

info@ckmintech.com : How to get the K-value

Thanks
sjbaxter



Joined: 26 Jan 2006
Posts: 141
Location: Cheshire, UK

View user's profile Send private message Visit poster's website

PostPosted: Wed Oct 18, 2006 9:13 am     Reply with quote

Quote:
How to get the K-value


Easiest way is to build a PIC that counts pulses.
Connect it to a car.
Drive ... say 10km.
See how many pulses it counted.
Divide the pulse count by the distance !!!

Gives you pulses per km !!! ... It's not rocket science Shocked
_________________
Regards,
Simon.
Ttelmah
Guest







PostPosted: Wed Oct 18, 2006 9:35 am     Reply with quote

I think you are slightly misunderstanding.
If you are measuring the frequency of pulses (which is what you are doing), there are two seperate choices. the first is to measure the interval _between_ pulses, by counting some higher frequency in this interval. The second is to count the source pulses over some longer interval of time. It is the former that is the faster updating solution.
The best way of doing this, is to count how many pulses of your master PIC crystal, occur between successive edges of the incoming pulse.
The 'k' factor in the equation given depends on the diameter of the wheels of the car, where the sensor is 'relative' to these (any gearing between), and how many pulses per revolution occur (it is common to have multiple magnets on the shaft, both to maintain balance, and to increase the number of pulses available).
As an example, if you have a PIC running at 4MHz, and a magnet on the output shaft to a wheel, with no gearing between, and 2 pulses/rev, then for a car with 15" wheels, and tires 6.2" high (225*70), the outside diameter will be 27.4", with the circumference 86.08". You will then get 1472.04 pulses/mile (((1760*36)/86.08)*2). At 10mph, you will get about 4 pulses/second ((1472.04*10)/(60*60)). If you count pulses per second, then the update rate becomes one/second, and the speed would need to increase to 12.2mph, before you reliably get an extra pulse per second (if you only have one pulse per rev, this doubles. If instead you count the pulses of the master clock/4 (available using the internal timer on most PICs), then at 10mph, the interval is 244558 clocks, and you can detect changes of tiny fractions of a mph, and update whenever a pulse arrives.

Best Wishes
info@ckmintech.com



Joined: 16 May 2006
Posts: 39

View user's profile Send private message

PostPosted: Thu Oct 19, 2006 2:02 am     Reply with quote

You can ask the k-value from your odometer supply. Our designe is using on 2 Toyota van, their k-value are 2454 and 2360. May be you can use this value to start your project as a reference and do the calibration later.

Refer to counting pules by using port-interrupt. Our design is using 18F1220 running on 8MHz and did not have any problem.

Rgd.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group