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

Passing ptr to array of Unions

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



Joined: 02 Jul 2005
Posts: 1

View user's profile Send private message

Passing ptr to array of Unions
PostPosted: Sat Jul 02, 2005 2:55 pm     Reply with quote

Trying to create a buffer for a multi chan ADC. The single chan union code works fine. I want to create a function that takes a rolling average of each ADC chan. Ideally it would pass a pointer to each chan of ADCBuf, that is ADCBuf[0] then ADCBuf[1].... The function would then average the number of samples in each chan and then return the averged value. Note: the return has not been added yet!

When a multichan version is added and a function as well, it does not compile. I have done this sort of thing in asm in the past using "pointers" without a problem.

Using CCS ver 3.222, on a PIC16F767. Any problems? The basic code is sumitted for clarity.
[code]

#Define ADCBUFSAMPLESIZE 8 //ADC buffer (byte)size
#Define ADCMAXCHAN 2

void AvgADCChan(union ADCBufSample *ADCBuf);
//////////////////////Global Variables////////////////////////

unsigned char ADCSample=0;
unsigned char ADC_Chan=0;

union ADCBufSample{
unsigned char ADCBytes[ADCBUFSAMPLESIZE];
int16 ADCWords[ADCBUFSAMPLESIZE/2];
}ADCBuf[ADCMAXCHAN];//, *ADSample=ADCSample;



////////// INTERUPTS ///////////////////////////

///// ADC Int ////

#int_AD
void ADCISR( ) {
ADCBuf[ADC_Chan].ADCBytes[ADCSample++]=ADRESL;
ADCBuf[ADC_Chan].ADCBytes[ADCSample--]=ADRESH;
PIR1=PIR1& 0b10111111; //clear ADC int flag
}//end ADC it


AvgADCChan(ADCBuf); //basic fn call in main

/////////////////////////////////////////////////////////////////////

void AvgADCChan(union ADCBufSample *ADCBuf){
int16 Temp; //test code
Temp=0;
Temp=Temp+1;

}

It seems to complain on the function itself with the following errors:

[code]
Executing: "C:\Program files\Picc\CCSC.exe" "SerialLCDStringTestMulti ADC chan ver D.c" +FM +DF +LN +T -A +M +Z +Y=9 +EA
*** Error 33 "E:\pic\C Projects\New Folder\SerialLCDStringTestMulti ADC chan ver D.c" Line 68(36,48): Expecting a {
*** Error 48 "E:\pic\C Projects\New Folder\SerialLCDStringTestMulti ADC chan ver D.c" Line 68(37,43): Expecting a (
*** Error 43 "E:\pic\C Projects\New Folder\SerialLCDStringTestMulti ADC chan ver D.c" Line 68(44,45): Expecting a declaration
*** Error 58 "E:\pic\C Projects\New Folder\SerialLCDStringTestMulti ADC chan ver D.c" Line 147(12,18): Expecting a close paren
*** Error 29 "E:\pic\C Projects\New Folder\SerialLCDStringTestMulti ADC chan ver D.c" Line 397(37,43): Function definition different from previous definition
*** Error 43 "E:\pic\C Projects\New Folder\SerialLCDStringTestMulti ADC chan ver D.c" Line 397(44,45): Expecting a declaration
*** Error 48 "E:\pic\C Projects\New Folder\SerialLCDStringTestMulti ADC chan ver D.c" Line 399(1,5): Expecting a (
*** Error 43 "E:\pic\C Projects\New Folder\SerialLCDStringTestMulti ADC chan ver D.c" Line 399(6,7): Expecting a declaration
*** Error 43 "E:\pic\C Projects\New Folder\SerialLCDStringTestMulti ADC chan ver D.c" Line 399(7,8): Expecting a declaration
*** Error 48 "E:\pic\C Projects\New Folder\SerialLCDStringTestMulti ADC chan ver D.c" Line 400(1,5): Expecting a (
*** Error 48 "E:\pic\C Projects\New Folder\SerialLCDStringTestMulti ADC chan ver D.c" Line 400(6,10): Expecting a (
*** Error 43 "E:\pic\C Projects\New Folder\SerialLCDStringTestMulti ADC chan ver D.c" Line 400(11,12): Expecting a declaration
*** Error 43 "E:\pic\C Projects\New Folder\SerialLCDStringTestMulti ADC chan ver D.c" Line 400(12,13): Expecting a declaration
*** Error 43 "E:\pic\C Projects\New Folder\SerialLCDStringTestMulti ADC chan ver D.c" Line 402(1,2): Expecting a declaration
14 Errors, 0 Warnings.
[/code]

When I remove the function and it's caller, it compiles and the union is created as normal,8 bytes of 2 chans>Actually only 4 samples/chan, will change wording later!
Ttelmah
Guest







PostPosted: Sat Jul 02, 2005 3:05 pm     Reply with quote

Declare the union, before you declare the prototype function.

Best Wishes
PIC1000



Joined: 02 Jul 2005
Posts: 1

View user's profile Send private message

PostPosted: Sat Jul 02, 2005 5:47 pm     Reply with quote

Yes that was it! Silly me.

Tankx
Ttelmah
Guest







PostPosted: Sun Jul 03, 2005 9:59 am     Reply with quote

This is the sort of area, where the poor 'error reporting' by the compiler, is really annoying. You'd think that if it does not know what the union 'is', it should post an error message that actually says something about this, but unfortunately it doesn't!... :-(

Best Wishes
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