View previous topic :: View next topic |
Author |
Message |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
passing pin define |
Posted: Mon Mar 07, 2011 4:49 pm |
|
|
Hi There,
I wanna build a function that i can call and it will return me a low pass filtered analog value.
I wanted to do it like this:
Code: | void GetFilteredAnalog(int16 adconv, int16 *value, int16 filter){
//Read ADC value
int16 adcval=0;
setup_adc_ports(adconv); |
but the compiler for some reason tells me A numeric expression must appear here and points to setup_adc_ports(adconv) but adconv is defined as int16. I'm not quite sure what the compiler wants from me. I'm using 4.119 and an 18f87k22.
Thank you |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 07, 2011 5:07 pm |
|
|
It's simple enough to test. Just make a test program with a constant
and a variable as the parameter. In the program below, the compiler
gives an error for the variable. Therefore, it can't accept a variable
as the parameter for this particular function.
Code: |
#include <16F877.H>
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//==========================================
void main()
{
int8 temp;
setup_adc_ports(NO_ANALOGS);
setup_adc_ports(temp); // This line gives an error
while(1);
}
|
The CCS manual says this:
Quote: |
setup_adc_ports( )
Syntax:
setup_adc_ports (value)
setup_adc_ports (ports, [reference])
Parameters: value - a constant defined in the devices .h file |
|
|
|
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
|
Posted: Tue Mar 08, 2011 10:57 am |
|
|
uhm, I found a do_pin_io(PIN) function example for digital IOs but nothing for analog. Tried around a bit but couldn't figure it out and const-casts are only possible in C++ - any clues?
Thank you! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 08, 2011 12:19 pm |
|
|
You can look at the .LST file (in Symbolic mode) and see how CCS does
the setup_adc_ports() function. Then use #byte statements to define
the PIC registers used by that function. Use getenv() to easily get the
register addresses. Then you can either write directly to the ADC
registers in your posted function, or you can create your own
setup_adc_ports() function and call it from your posted function.
In other words, make a substitute function that can accept a variable
as the parameter.
Another way to do it would be to pass a numeric index to your posted
function (in adconv) and use a switch-case statement to select the
configuration for setup_adc_ports(). In other words, each 'case' would
have its own line for setup_adc_ports(), with different parameters in
each one. This method would be the least amount of work, but would use
more ROM space. |
|
|
|