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 support@ccsinfo.com

CCP / 24 bit timer / 1hz to 150 hz range
Goto page 1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

CCP / 24 bit timer / 1hz to 150 hz range
PostPosted: Sun Dec 30, 2007 1:23 pm     Reply with quote

Hi everyone,

Ok this subject has been discussed alot of time but nothing in the search i've made can help me :(....

It's my first time playing with CCP and i need to read pulse from 1hz to 150-200hz max.

In the fan datasheet --->Download it here
I can see that 4 rise = 1 rotation on the sense wire.

So basically what i need to do (correct me if i am wrong): CCP freq result / 4 * 60 = RPM

BUT before working on this i can't get some old code found on this topic http://www.ccsinfo.com/forum/viewtopic.php?t=906
maybe because i am running v4.057...

pic18f2550 w/ 12mhz crystal @ 48mhz

Code:

#include <18f2550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,PLL3,CPUDIV1,NOMCLR
#use delay(clock=48000000)
#define use_portb_lcd TRUE
#define BytePtr(var, offset) (char *)(&var + offset)
#include <LCD.c>
// This global variable holds the time interval
// between two consecutive rising edges of the
// input signal.   
int16 isr_ccp_delta;
int32 g32_ccp_delta;
char gc_timer1_extension;
BOOLEAN gc_capture_flag;

#int_timer1
void timer1_isr(void)
{
gc_timer1_extension++;
}

// When a rising edge occurs on the input signal,
// the CCP1 will 'capture' the value of Timer1
// at that moment.  Shortly after that, a CCP1
// interrupt is generated and the following isr
// is called.   In the isr, we read the 'captured'
// value of Timer1.  We then subtract from it the
// Timer1 value that we 'captured' in the previous
// interrupt.  The result is the time interval
// between two rising edges of the input signal.
// This time interval is then converted to a frequency
// value by code in main().
#int_ccp1
void ccp1_isr(void)
{
char timer_ext_copy;
int32 current_ccp;
static int32 old_ccp = 0;

// Set flag to indicate that we did a capture.
gc_capture_flag = TRUE;

current_ccp = (int32)CCP_CAPTURE_RE; // Read the current CCP

// Get local copy of the timer ext.
timer_ext_copy = gc_timer1_extension;

// Check if a Timer1 interrupt is pending. If so, check if
// the CCP capture occurred before or after the Timer rolled
// over. We can tell if it occurred after it rolled over, if
// the CCP's MSB is zero. ie., if the CCP is somewhere between
// 0x0000 and 0x00FF.
// We know that we can just check if the MSB = 0x00, because
// it takes about 30 us to get into this ISR. (Using a 4 Mhz
// crystal on a 16F628). The timer increments at 1 us per
// count, so 0xFF = 255 us.
// Actually, to be safer, I'll give it 2 MSB counts, which is
// 511 us. That way, if I lengthen any of the other ISR's,
// we'll still be able to detect the roll-over OK.
// If the timer did roll over after we got a CCP interrupt,
// then we need to increment the timer extension byte, that we
// save. We have to do that because the CCP interrupt has
// priority, and so it executes before the Timer isr can
// execute and increment the extension.
// (Designing the code with the priority switched doesn't help.
// You still have the same type of problem. With CCP first,
// the fix is easier).
//

// Was CCP captured after Timer1 wrapped ?
// If so, increment the copy of the timer ext.
if(INT_TIMER1)
{
if(*BytePtr(current_ccp, 1) < 2)
timer_ext_copy++;

// Since we know a timer interrupt is pending, let's just
// handle it here and now. That saves a little load off
// the processor.
gc_timer1_extension++; // Increment the real timer extension
clear_interrupt(INT_TIMER1); ; // Then clear the Timer1 interrupt
}

// Insert the timer extension into the proper place in the
// 32-bit CCP value.
// ie., Insert it into location "EE" as follows: 0x00EEnnnn
// (nnnn = the CCP).
*BytePtr(current_ccp, 2) = timer_ext_copy;

// Because we're using unsigned math, we don't have to worry
// if the current value is less than the old. The result is
// always the absolute value of the difference. The only way
// there could be a problem is if the new CCP value had rolled
// over twice. But with a 24-bit value, and a Timer
// pre-scalar of 1, that's 16.7 seconds. That's way beyond any
// practical value.

// Edited on Jan. 2, 2004: There was a bug in this routine,
// because I was promoting a 24-bit value to a 32-bit data type,
// but the upper byte was always left = 0. This caused a problem
// with the 32-bit subtraction when the 24-bit value rolled over past 0.
// Kenny spotted this error and provided a fix in a PM to me.
// I have commented out the original line, and inserted his fix, below.
//g32_ccp_delta = current_ccp - old_ccp;
g32_ccp_delta = (current_ccp > old_ccp) ? current_ccp - old_ccp : current_ccp + (0x1000000 - old_ccp);

// Save the current ccp value for next time.
old_ccp = current_ccp;

}


//=======================
void main()
{
int32 current_ccp_delta;
int16 frequency;
lcd_init();

delay_us(20);

// Setup Timer1 and CCP1 for Capture mode so that
// we can measure the input signal's frequency.
// The input signal comes from the CCP2 pin, which
// is connected to the CCP1 pin with a wire.
set_timer1(0);           
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_ccp1(CCP_CAPTURE_RE);   

// Clear the CCP1 interrupt flag before we enable
// CCP1 interrupts, so that we don't get an unwanted
// immediate interrupt (which might happen).
clear_interrupt(INT_CCP1);
enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);


while(1)
  {



   
   // Now calculate the frequency.

   // Get a local copy of the latest ccp delta from the isr.
   // We have to disable interrupts when we read a global
   // isr variable that is larger than a single byte.
disable_interrupts(GLOBAL);
current_ccp_delta = g32_ccp_delta;
enable_interrupts(GLOBAL);

   // To calculate the frequency of the input signal,
   // we take the number of clocks that occurred
   // between two consecutive edges of the input signal,
   // and divide that value into the number of Timer1
   // clocks per second.   Since we're using a 4 MHz
   // crystal, the Timer1 clock is 1 MHz (Timer1 runs
   // at the instruction cycle rate, which is 1/4 of the
   // crystal frequency).  For example, suppose the
   // the input waveform has a frequency of 244 Hz.
   // 244 Hz has a period of about 4098 usec.
   // Timer1 is clocked at 1 MHz, so between two
   // consecutive rising edges of the input signal,
   // it will count up by 4098 clocks.  To find the
   // frequency, we divide 4098 into the number of
   // clocks that occur in 1 second, which is 1000000.
   // This gives 1000000 / 4098 = 244 Hz.
   
if(gc_capture_flag == TRUE)
  {
   frequency = (int16)((12000000L + (current_ccp_delta >> 1)) /
                       current_ccp_delta);

   printf(lcd_putc,"%lu Hz", frequency);

   gc_capture_flag = FALSE;
  }
else
  {
   printf(lcd_putc,"No signal\n\r");
  }
  }

}




Again i can't found a topic which show all the code i need so i have glued together some piece of code found here too --- >
http://www.ccsinfo.com/forum/viewtopic.php?t=29963

This was looking very good since it's using the same specs as me 48mhz clock but unfortunatly PCM Programmer post only a short piece of code which he says to used the old 24 bit timer code which didnt worked for me!!
Link : http://www.ccsinfo.com/forum/viewtopic.php?p=81128

Tryied to convert abit of code to make it compile right ,, did compile but on the LCD it's says No signal always !!

Any help would be GREATLY appreciated :P

Not only me but for anybody who will be interested have a working complete code with a 24 bit timer 1 !!!

Happy holidays!
Laurent


Last edited by ELCouz on Sun Jan 06, 2008 10:27 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 30, 2007 2:43 pm     Reply with quote

Two things:

1. Which fan do you have ? The data sheet shows two different types.
One has a yellow sense wire, and the other one has a Red sense wire.

2. The data sheet shows a pull-up resistor on the sense wire.
Do you have one ? The data sheet shows a maximum of 10 ma is
allowed, so if your PIC is running at 5v, you could use a 1K ohms.
That would give a reasonably stiff pull-up with a 5 ma load.
The pullup should use the same Vdd voltage as the PIC.
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Dec 30, 2007 2:50 pm     Reply with quote

Dear PCM Programmer,

1.The one with the Yellow wire ,,, F Type ( Frequency Generator)

2. I Already have a 1k res pull up on Vdd 5v


Does my code look ok ?

I am really in doubt

EDIT: i've made these changes in order to make the code to compile

Code:


current_ccp = (int32)CCP_CAPTURE_RE; // Read the current CCP
//Before current_ccp = (int32)CCPR1_REG; // Read the current CCP

if(INT_TIMER1)
//Before f(TMR1IF_BIT)

clear_interrupt(INT_TIMER1); ; // Then clear the Timer1 interrupt
//before  TMR1IF_BIT = 0; // Then clear the Timer1 interrupt




Thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 30, 2007 3:29 pm     Reply with quote

Quote:
current_ccp = (int32)CCP_CAPTURE_RE; // Read the current CCP
//Before current_ccp = (int32)CCPR1_REG; // Read the current CCP

if(INT_TIMER1)
//Before f(TMR1IF_BIT)

clear_interrupt(INT_TIMER1); ; // Then clear the Timer1 interrupt
//before TMR1IF_BIT = 0; // Then clear the Timer1 interrupt

1. In the first one, it's refering to a "REG", which means a register.
You've put in a constant that's used in the setup_ccp1() function.
Put that one back the way it was, and add this line above main().
This defines the CCPR1 register address for the 18F2550.
Code:
#byte CCPR1_REG = 0xFBE


2. In the 2nd one, it's referring to a "BIT", which means a bit in a register.
You've put in a constant used with the enable_interrupts() function.
Put it back the way it was, and add these two lines above main():
This defines the bit address of the TMR1IF bit, within the PIR1 register.
Code:

#byte PIR1 = 0xF9E
#bit  TMR1IF = PIR1.0

If you have a recent version of the compiler, then you can use a
new CCS function to test the interrupt bit.
Instead of this:
Code:
if(TMR1IF)
  {

  }

You can now do this:
Code:
if(interrupt_active(INT_TIMER1))
  {

  }

Then you don't need the #bit statement to define TMR1IF.

3. The 3rd change is OK.
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Dec 30, 2007 4:09 pm     Reply with quote

Dear PCM Programmer,

I have modifier the code in order to debug it more accurately,,,

removed lcd code ,,, added rs232 code

Observe the following terminal output...

Code:

No signal  No signal  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz 1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  1 Hz  No signal  No signal  No signal  No signal  No signal  No signal  No signal


We can clearly see when i unplug and plug the sense wire but still 1 hz...
even when i ground the CCP pin rapidly it doesnt move and display 1 hz


I'm very clueless!

Here's the display code i have modified (the only thing i have changed since the bits and bytes you told me to add)



Code:

if(gc_capture_flag == TRUE)
  {
   frequency = (int16)((12000000L + (current_ccp_delta >> 1)) /
                       current_ccp_delta);

   printf(" %lu Hz ", frequency);

   gc_capture_flag = FALSE;
   delay_ms(1000);
  }
else
  {
   printf(" No signal ");
   delay_ms(1000);
  }


btw, int16 isr_ccp_delta; is never used

Have a nice day,
Laurent


Last edited by ELCouz on Sun Dec 30, 2007 4:14 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 30, 2007 4:13 pm     Reply with quote

Do you have an oscilloscope ? If so, look at the incoming signal
on the CCP1 pin on the 18F2550 (Pin C2). What are the voltage
levels of the signal ? What is the frequency ?

Also, is the ground wire for the fan connected to the ground on the PIC
board ? It needs to be.
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Dec 30, 2007 4:17 pm     Reply with quote

Quote:
Do you have an oscilloscope ? If so, look at the incoming signal
on the CCP1 pin on the 18F2550 (Pin C2). What are the voltage
levels of the signal ? What is the frequency ?


Unfortunately no ,,, but i have access to an oscilloscope i will check this ASAP

Quote:
Also, is the ground wire for the fan connected to the ground on the PIC
board ? It needs to be.


Of course ;) , everything has the same ground point
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 30, 2007 4:19 pm     Reply with quote

Can you give an estimate of the frequency of the incoming signal ?
What RPM are you running for the fan, during these tests ?

Can you post your current program ? It should be compilable,
if I paste it into MPLAB.
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Dec 30, 2007 4:33 pm     Reply with quote

Quote:
What RPM are you running for the fan, during these tests ?

4000 rpm but i need to read as low as 500 rpm (detect fan trouble)

Quote:
Can you post your current program ?


Sure, but i dont have a special program using this code ,,, i'm trying first to understand this example code , to get it to work you know :P

This is a CTRL+A, CTRL+V of the entire project

Code:


#include <18f2550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,PLL3,CPUDIV1,NOMCLR
#use delay(clock=48000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define BytePtr(var, offset) (char *)(&var + offset)

#byte PIR1 = 0xF9E
#bit  TMR1IF = PIR1.0
#byte CCPR1_REG = 0xFBE
// This global variable holds the time interval
// between two consecutive rising edges of the
// input signal.   
int16 isr_ccp_delta;
int32 g32_ccp_delta;
char gc_timer1_extension;
BOOLEAN gc_capture_flag;

#int_timer1
void timer1_isr(void)
{
gc_timer1_extension++;
}

// When a rising edge occurs on the input signal,
// the CCP1 will 'capture' the value of Timer1
// at that moment.  Shortly after that, a CCP1
// interrupt is generated and the following isr
// is called.   In the isr, we read the 'captured'
// value of Timer1.  We then subtract from it the
// Timer1 value that we 'captured' in the previous
// interrupt.  The result is the time interval
// between two rising edges of the input signal.
// This time interval is then converted to a frequency
// value by code in main().
#int_ccp1
void ccp1_isr(void)
{
char timer_ext_copy;
int32 current_ccp;
static int32 old_ccp = 0;

// Set flag to indicate that we did a capture.
gc_capture_flag = TRUE;

current_ccp = (int32)CCP_CAPTURE_RE; // Read the current CCP

// Get local copy of the timer ext.
timer_ext_copy = gc_timer1_extension;

// Check if a Timer1 interrupt is pending. If so, check if
// the CCP capture occurred before or after the Timer rolled
// over. We can tell if it occurred after it rolled over, if
// the CCP's MSB is zero. ie., if the CCP is somewhere between
// 0x0000 and 0x00FF.
// We know that we can just check if the MSB = 0x00, because
// it takes about 30 us to get into this ISR. (Using a 4 Mhz
// crystal on a 16F628). The timer increments at 1 us per
// count, so 0xFF = 255 us.
// Actually, to be safer, I'll give it 2 MSB counts, which is
// 511 us. That way, if I lengthen any of the other ISR's,
// we'll still be able to detect the roll-over OK.
// If the timer did roll over after we got a CCP interrupt,
// then we need to increment the timer extension byte, that we
// save. We have to do that because the CCP interrupt has
// priority, and so it executes before the Timer isr can
// execute and increment the extension.
// (Designing the code with the priority switched doesn't help.
// You still have the same type of problem. With CCP first,
// the fix is easier).
//

// Was CCP captured after Timer1 wrapped ?
// If so, increment the copy of the timer ext.
if(interrupt_active(INT_TIMER1))
  {
if(*BytePtr(current_ccp, 1) < 2)
timer_ext_copy++;

// Since we know a timer interrupt is pending, let's just
// handle it here and now. That saves a little load off
// the processor.
gc_timer1_extension++; // Increment the real timer extension
clear_interrupt(INT_TIMER1); ; // Then clear the Timer1 interrupt
}

// Insert the timer extension into the proper place in the
// 32-bit CCP value.
// ie., Insert it into location "EE" as follows: 0x00EEnnnn
// (nnnn = the CCP).
*BytePtr(current_ccp, 2) = timer_ext_copy;

// Because we're using unsigned math, we don't have to worry
// if the current value is less than the old. The result is
// always the absolute value of the difference. The only way
// there could be a problem is if the new CCP value had rolled
// over twice. But with a 24-bit value, and a Timer
// pre-scalar of 1, that's 16.7 seconds. That's way beyond any
// practical value.

// Edited on Jan. 2, 2004: There was a bug in this routine,
// because I was promoting a 24-bit value to a 32-bit data type,
// but the upper byte was always left = 0. This caused a problem
// with the 32-bit subtraction when the 24-bit value rolled over past 0.
// Kenny spotted this error and provided a fix in a PM to me.
// I have commented out the original line, and inserted his fix, below.
//g32_ccp_delta = current_ccp - old_ccp;
g32_ccp_delta = (current_ccp > old_ccp) ? current_ccp - old_ccp : current_ccp + (0x1000000 - old_ccp);

// Save the current ccp value for next time.
old_ccp = current_ccp;

}


//=======================
void main()
{
int32 current_ccp_delta;
int16 frequency;

delay_us(20);

// Setup Timer1 and CCP1 for Capture mode so that
// we can measure the input signal's frequency.
// The input signal comes from the CCP2 pin, which
// is connected to the CCP1 pin with a wire.
set_timer1(0);           
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_ccp1(CCP_CAPTURE_RE);   

// Clear the CCP1 interrupt flag before we enable
// CCP1 interrupts, so that we don't get an unwanted
// immediate interrupt (which might happen).
clear_interrupt(INT_CCP1);
enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);


while(1)
  {



   
   // Now calculate the frequency.

   // Get a local copy of the latest ccp delta from the isr.
   // We have to disable interrupts when we read a global
   // isr variable that is larger than a single byte.
disable_interrupts(GLOBAL);
current_ccp_delta = g32_ccp_delta;
enable_interrupts(GLOBAL);

   // To calculate the frequency of the input signal,
   // we take the number of clocks that occurred
   // between two consecutive edges of the input signal,
   // and divide that value into the number of Timer1
   // clocks per second.   Since we're using a 4 MHz
   // crystal, the Timer1 clock is 1 MHz (Timer1 runs
   // at the instruction cycle rate, which is 1/4 of the
   // crystal frequency).  For example, suppose the
   // the input waveform has a frequency of 244 Hz.
   // 244 Hz has a period of about 4098 usec.
   // Timer1 is clocked at 1 MHz, so between two
   // consecutive rising edges of the input signal,
   // it will count up by 4098 clocks.  To find the
   // frequency, we divide 4098 into the number of
   // clocks that occur in 1 second, which is 1000000.
   // This gives 1000000 / 4098 = 244 Hz.
   
if(gc_capture_flag == TRUE)
  {
   frequency = (int16)((12000000L + (current_ccp_delta >> 1)) /
                       current_ccp_delta);

   printf(" %lu Hz ", frequency);

   gc_capture_flag = FALSE;
   delay_ms(1000);
  }
else
  {
   printf(" No signal ");
   delay_ms(1000);
  }
  }

}



EDIT: since i dont have an oscilloscope , i will build a fixed freq generator so i hope this will help !

Thanks for helping me Smile

Laurent
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 30, 2007 5:36 pm     Reply with quote

Quote:
current_ccp = (int32)CCP_CAPTURE_RE; // Read the current CCP

This isn't correct. The orginal code had a register in there.
You put in a constant that used in the setup_ccp1() function.

You need to change that line to this:
Code:
current_ccp = (int32)CCP_1;



Also, because you're using a Timer1 prescaler of 8, you need to
divide the numerator by 8, in the frequency formula:
Quote:

frequency = (int16)(((12000000L/8) + (current_ccp_delta >> 1)) /
current_ccp_delta);


I tested it with those changes and it basically works. However, it gets
an incorrect result occasionally. I think there may be with the "fix" that
was added to the code. I have to look at it some more. I might not do it until tomorrow.
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Dec 30, 2007 5:55 pm     Reply with quote

wow we've got some major improvement !!!

Code:
0 Hz  97 Hz  0 Hz  106 Hz  0 Hz  106 Hz  0 Hz  0 Hz  0 Hz  0 Hz  105 Hz  0 Hz 106 Hz  106 Hz  107 Hz  106 Hz  107 Hz  106 Hz  106 Hz  106 Hz 107 Hz  106 Hz 106 Hz  106 Hz  106 Hz  0 Hz  0 Hz  0 Hz  0 Hz  0 Hz  0 Hz  0 Hz  0 Hz  0 Hz  0 Hz  107 Hz  106 Hz  107 Hz  106 Hz  107 Hz  107 Hz


However its still display erroneus value such as 0 hz.

Thank you very much !

Laurent
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Mon Dec 31, 2007 8:55 am     Reply with quote

Meanwhile,

Any one have experienced this issue with an extended 24-bit Timer for ccp capturing?

EDIT: Better question formulation: Anyone who have successfuly used the code that PCM Programmer had submitted in his topic please give an advice Mr. Green

I'm still looking why the CCP display 0 hz sometimes.... would capturing falling edge instead of rising would be better ?

Any advice?

Happy new year everyone !

Laurent
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

PostPosted: Tue Jan 01, 2008 11:57 pm     Reply with quote

Yes, I have successfully used this code many times. Thanks to PCM programmer for posting it.

Another problem is that the timer 1 interrupt is not enabled.
Add the following lines in main()
clear_interrupt(INT_TIMER1);
enable_interrupts(INT_TIMER1);

Tried it on an 18F2520 at 40MHz (CCS version 3.249) and it worked fine over a very wide range (just looking at the delta value).

It doesn't matter whether rising or falling edge is captured.
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Wed Jan 02, 2008 2:02 am     Reply with quote

Dear Kenny,

I have added your code in the main section,,, still give 0hz values :(

Code:
 79 Hz  90 Hz  0 Hz  0 Hz  93 Hz  0 Hz  0 Hz  0 Hz  0 Hz  0 Hz  0 Hz  0 Hz 93 Hz  0 Hz  0 Hz  0 Hz  93 Hz  93 Hz  0 Hz  93 Hz  92 Hz  93 Hz  92 Hz  92 Hz 92 Hz  92 Hz  92 Hz  92 Hz  92 Hz  91 Hz  91 Hz  92 Hz  91 Hz  91 Hz  91 Hz


Tried with 3 fans ,, the ccp seems to have trouble reading pulses , PCM Programmer have the same problem too... maybe its a pic model issue with this code??


EDIT:

Now this can be a clue for PCM Programmer....

I have tryed to decrease clock speed by not using any PLL and running straight from my crystal speed (12mhz)
So with the pic running at 12mhz instead of 48mhz i get very good result see by yourself

Code:
77 Hz  91 Hz  93 Hz  0 Hz  93 Hz  93 Hz  93 Hz  93 Hz  0 Hz  93 Hz  93 Hz 93 Hz  93 Hz  93 Hz  93 Hz  93 Hz  93 Hz  92 Hz  93 Hz  93 Hz  93 Hz  93Hz  93 Hz  93 Hz  93 Hz  93 Hz  0 Hz  93 Hz  93 Hz  93 Hz  93 Hz  93 Hz  93 Hz 93 Hz 93 Hz  93 Hz  93 Hz  93 Hz  93 Hz  93 Hz  93 Hz  93 Hz


Only 3 bad reading but still that problem must be correct since 3 bad reading per minute is a no win.

Now i think its timer related,,, now with 12mhz system clock i get a low 3mhz timer1 with a huge 174ms before overflow (timer1 div by 8)

Happy new year everyone ! Smile

Laurent
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 02, 2008 2:20 am     Reply with quote

I don't have the same problem. The problem I had with your code
was caused by the missing lines that Kenny pointed out. I can test
it tomorrow and see if I can duplicate your "0 Hz" problem somehow.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3, 4, 5, 6  Next
Page 1 of 6

 
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