View previous topic :: View next topic |
Author |
Message |
Slick05
Joined: 05 Feb 2005 Posts: 14
|
Why am I getting an error? |
Posted: Sat Feb 05, 2005 3:58 pm |
|
|
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
}
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Slick05
Joined: 05 Feb 2005 Posts: 14
|
|
Posted: Sat Feb 05, 2005 4:04 pm |
|
|
When I take out the for loop in the get_freq routine it compiles fine. What is wrong? |
|
![](templates/subSilver/images/spacer.gif) |
Slick05
Joined: 05 Feb 2005 Posts: 14
|
|
Posted: Sat Feb 05, 2005 4:17 pm |
|
|
I have done alot of testing and actually think it is a bug within CCS. How could I get around this? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sat Feb 05, 2005 4:20 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Slick05
Joined: 05 Feb 2005 Posts: 14
|
|
Posted: Sat Feb 05, 2005 4:21 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sat Feb 05, 2005 4:21 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|