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

A numeric expression must appear here

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



Joined: 21 Mar 2010
Posts: 37

View user's profile Send private message Yahoo Messenger

A numeric expression must appear here
PostPosted: Thu May 20, 2010 8:10 am     Reply with quote

Why keep getting "numeric expression must appear" ?
Code:

#include <16F877A.h>
#device *=16 ADC=8

#fuses XT,NOLVP,NOWDT,NOPROTECT,NOPUT
#use delay(clock=4000000)
#use rs232(uart1,baud=9600,xmit=PIN_C6,rcv=PIN_C7,stop=1,parity=N,bits=8)
#use fast_io(D)

void main(void)
{
int16 V1;
set_tris_d(0x00); // d all output
setup_adc(ADC_CLOCK_DIV_64);
setup_adc_ports(RA0_ANALOG);

for(;;)
{

set_adc_channel(0);
read_adc(adc_start_only);
V1=read_adc(ADC_START_ONLY);
output_d(V1);
delay_ms(1000);
}

}
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu May 20, 2010 8:54 am     Reply with quote

Where ?

Please post the full compiler error.

I also think this : V1=read_adc(ADC_START_ONLY); should be

V1=read_adc(ADC_READ_ONLY);

And you need a delay, sleep or loop to check the completion flag between the start and a read of the ADC.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu May 20, 2010 3:32 pm     Reply with quote

I'm not sure if this is the issue but, you have defined V1 as int16 yet you are trying to output it to an 8bit port. Not sure if the compiler is complaining about that.

Ronald
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Thu May 20, 2010 4:00 pm     Reply with quote

Code:
set_adc_channel(0);
read_adc(adc_start_only);
V1=read_adc(ADC_START_ONLY);



why do you call read_adc(); twice with no delay in between and the first time you don't save the value?

.... off the top of my head... but to me that looks weird. might want to take a look at it.


g.
_________________
CCS PCM 5.078 & CCS PCH 5.093
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri May 21, 2010 6:56 am     Reply with quote

The error is caused by the read_adc function not returning a value when you provide it with the parameter ADC_START_ONLY.
Change to:
Quote:
read_adc(adc_start_only);
V1=read_adc(ADC_READ_ONLY);


These two lines are the same as the shorter and easier to read:
Code:
V1=read_adc();
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri May 21, 2010 7:04 am     Reply with quote

Because you have a 1 second delay in your routine you could improve the performance by:-

Code:

set_adc_channel(0);
read_adc(ADC_START_ONLY);
delay_ms(10);

for(;;)
{
  V1=read_adc(ADC_READ_ONLY);
  read_adc(ADC_START_ONLY);
  output_d(V1);
  delay_ms(1000);
}


There is no need to keep calling set_adc_channel(0); as you are only using 1 channel.
Using V1=read_adc(); is good but it does the start and then waits for it to finish and does a read. During this time you could have done something else. It would have been better if they made it do a READ and then a START and still leave the delay up to you!
feitanx



Joined: 21 Mar 2010
Posts: 37

View user's profile Send private message Yahoo Messenger

PostPosted: Sat May 22, 2010 4:13 am     Reply with quote

What if I use multiple channel?
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon May 24, 2010 2:58 am     Reply with quote

Then you will need to switch channels within your loop.
Now, depending on how fast your loop runs, what your sampling rate needs to be and how long it takes I would proberbly do the following:-

Code:

int8 state = 0;

set_adc_channel(0);
delay_ms(10);

for(;;)
{
  switch(chan)
  case 0:
    V0 = read_adc(ADC_READ_ONLY);
    set_adc_channel(1);
    read_adc(ADC_START_ONLY);
    chan++;
    break;
  case 1:
    V1 = read_adc(ADC_READ_ONLY);
    set_adc_channel(0);
    read_adc(ADC_START_ONLY);
    chan = 0;
    break;
  }

  read_adc(ADC_START_ONLY);
  output_d(V1);
  delay_ms(1000);
}


or something like that
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