View previous topic :: View next topic |
Author |
Message |
Guest
|
Car RPM using 877A |
Posted: Sat Mar 22, 2008 9:59 am |
|
|
Hi.
I'm trying to make my own RPM for my car using PIC16F877A and timer1 with external osc. but isn't working. What am i doing wrong?
PS: i didn't tested on my car, just on PIC Simulator...the timer1 is not incrementing.
Code: |
#include <16F877A.h>
#device ADC=16
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, bits=8, parity = N, xmit=PIN_C6, rcv=PIN_C7)
#include <stdlib.h>
void main() {
long freqc_low;
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
while (TRUE) {
set_timer1(0);
setup_timer_1(T1_EXTERNAL | T1_DIV_BY_2);
/* Espera 1 segundo já que mais a frente multiplicamos por 60 */
delay_ms( 10 );
freqc_low=get_timer1(); //get timer1 value as the least sign. 16bits of freq counter
printf("Timer1: %LU\r\n",freqc_low);
freqc_low=((freqc_low * 2)*60);
printf("%LU Rpm\r\n",freqc_low); //and print frequency
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 22, 2008 11:28 am |
|
|
Quote: | enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1); |
Your program does not have an interrupt service routine for Timer1.
If you enable interrupts without an interrupt service routine, the program
will crash when an interrupt occurs.
If you don't want to use interrupts, then delete those two lines. |
|
|
Guest
|
|
Posted: Sat Mar 22, 2008 11:42 am |
|
|
Still not working. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 22, 2008 11:55 am |
|
|
You're running this on some unspecified simulator. The simulator
probably doesn't have an external clock applied to the Timer1 input.
Or, the input frequency is too high for the 10 ms delay period.
I can't make your simulator work. |
|
|
baltazar_aquino
Joined: 16 Mar 2008 Posts: 27
|
|
Posted: Sun Mar 23, 2008 11:36 am |
|
|
RPM measurement job is trivial for PIC. test it with real pulses not on simulator. By the way, what sensor/probe you are going to use? |
|
|
Guest
|
|
Posted: Sun Mar 23, 2008 9:23 pm |
|
|
I'll use coil signal from ECU. I'm newbie with PIC programming, i know PC programming (Delphi, PHP, C++).
Is there any other easy way to measure RPM?
I got this code from net and not i'm understanding. When coil pulse is generated (0-1 or 1-0, depending of my PIC configuaration), timer1 ins inecrementend. After some time (i'm using 1 second) i get the pulse count and make some calculations.
But my problem is: my PIC is used for some others tasks and i can't wait 1 second on main routine to calculate RPM. Also, if i use less time (about 50ms) i think is not enough, since car low RPM's is really LOW. |
|
|
umka
Joined: 28 Aug 2007 Posts: 99 Location: New Zealand
|
|
Posted: Sun Mar 23, 2008 9:36 pm |
|
|
no it counts the number of clock increments between pulses from the ecu.
this gives you the time between ecu pulses and therefore time taken to do one revolution. |
|
|
Will_Esan
Joined: 17 Mar 2008 Posts: 7 Location: Norcross, GA
|
|
Posted: Mon Mar 24, 2008 2:13 am |
|
|
Quote: | I'll use coil signal from ECU. I'm newbie with PIC programming, i know PC programming (Delphi, PHP, C++). |
Your programming experience counts to nothing until you have basic electronics knowledge.
Quote: | s there any other easy way to measure RPM? |
Yes there are,
1. Buy one from store
2. Learn some electronics and use free hex files users have posted on web.
3. If you really want to build your own, then learn some electronics
There r lot of examples on web you even cant count, I made my own RPM meter back in school, very basic. If you are looking for readymade solution, the answer is keep looking.
In forums generally people get a guide line how to get through from problem they are facing from other forum members not the Solution.
If you need the guide line then you must be very specific about your problem. READ CCS MANUAL you will get answer about timer1 interrupt. |
|
|
|