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

Why am I getting an error?

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



Joined: 05 Feb 2005
Posts: 14

View user's profile Send private message

Why am I getting an error?
PostPosted: Sat Feb 05, 2005 3:58 pm     Reply with quote

Hi, I have a program to determine the frequency of an incoming analog signal. The main program builds and runs fine, but when I insert the simple subroutine "get_freq", I get all these errors popping up. Why is this happening?

Code:

//Frequency determination

#include <18F458.h>
#device ADC=8   //set for 8 bit A/D
#use delay(clock=40000000)   //40Mhz
#fuses HS, OSCSEN, BROWNOUT, BORV20, STVREN, DEBUG //High Speed, Oscillator switching enabled, Brownout reset at 2.0V, Stack full causes rest, Low Voltage programming
int i = 0;
int sig[1300];   //array for signal data
int test=0;      //To test if input is above voltage threshold
int freq=0;      //Global variable for the frequency of the incoming signal
int peaks=0;   //Global vairables for number of peaks counted

void get_freq(void)
{
   freq=0;   //reset previous values
   peaks=0;
   for(i=2;i<1298;i++)      //take 1300 samples (.325 seconds worth))
    {
         
      if(sig[i]>=sig[i-1] && sig[i]>=sig[i-2] && sig[i]>=sig[i+1] && sig[i]>=sig[i+2])
      {
         peaks=peaks+1;   //Tests to see if current sample is greater that the 2 before and after   
      }
   {
}

void main()
{
enable_interrupts(INT_AD);
enable_interrupts(global);
setup_adc_ports(RA0_ANALOG);   //Set A0 for analog input
setup_adc(ADC_CLOCK_DIV_32);   //clock frequency
set_adc_channel(0);   //Use PORT A0 to read incoming signal
while (1)
   {
   test = 0;   //initialize test
   test = read_adc();
   if(test>=150)    //Wait until input signal is above certain threshold (So noise isn't "tuned")
      {
      output_d(0b00000000);   //"Tuning"
      for(i=0;i<1300;i++)      //take 1300 samples (.325 seconds worth))
             {
         sig[i] = read_adc();
         output_c(sig[i]);      //Dsiplay sampled value
         delay_us(250);      //4kHz sampling frequency   
         }
      get_freq();   //obtain frequency of digital signal

      //setup_adc( ADC_OFF );         More A/D options
      //read_adc(ADC_START_ONLY);
      //value=read_adc(ADC_READ_ONLY);
      }
   else
      {
         output_d(0b00000001);   //Output "ready" light
      }
   }
}
Slick05



Joined: 05 Feb 2005
Posts: 14

View user's profile Send private message

PostPosted: Sat Feb 05, 2005 4:04 pm     Reply with quote

When I take out the for loop in the get_freq routine it compiles fine. What is wrong?
Slick05



Joined: 05 Feb 2005
Posts: 14

View user's profile Send private message

PostPosted: Sat Feb 05, 2005 4:17 pm     Reply with quote

I have done alot of testing and actually think it is a bug within CCS. How could I get around this?
Ttelmah
Guest







PostPosted: Sat Feb 05, 2005 4:20 pm     Reply with quote

Slick05 wrote:
When I take out the for loop in the get_freq routine it compiles fine. What is wrong?

Remember an integer in the CCS C, is only 8bits. 255max. You are trying to count up to 1298....

Best Wishes
Slick05



Joined: 05 Feb 2005
Posts: 14

View user's profile Send private message

PostPosted: Sat Feb 05, 2005 4:21 pm     Reply with quote

Actually don't worry about it, I'm an idiot. One of the braces was the wrong way ;P. I just spent hours trying to figure that one out. What a good waste of time
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat Feb 05, 2005 4:21 pm     Reply with quote

Quote:

int i = 0;


In CCS C Cross Compiler, integer size is 8 bit by default.

When define a variable and to ovoid mistakes, I use int8, int16, etc

Code:

void get_freq(void)
{
int16 i;
   freq=0;   //reset previous values
   peaks=0;
   for(i=2;i<1298;i++)      //take 1300 samples (.325 seconds worth))
    {
    }
}


Hope this help.

Humberto
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