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

Store 9x10bit ADC value in an effecient way

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



Joined: 14 Nov 2006
Posts: 14

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number

Store 9x10bit ADC value in an effecient way
PostPosted: Wed Jun 13, 2007 12:47 am     Reply with quote

My project is to read 9 piece of 10bit ADC value (from PIC16F690)
Store it, and send out to another PIC (HUART->RF TX module)
Then receive it (RF RX module->HUART) and store it in the same way.

Now I'm storing this 9x10bit ADC value in an int16 array.
But this is not effecient when sending out by RF!
It can contain some dummy bits, so it can by divided by 8.
(90bit + 6 dummy bits = 12Byte)

So can I define somehow an own struck that contains
9x10bit variables? (or bitfields?)

Declare a variable of that struct and send this variable out to UART.

On the receiver side the UART will store the values in the same own type.

And the channels can by accessed like: channels.ch1=channels.ch1 + 2

Thank you!
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Store 9x10bit ADC value in an effecient way
PostPosted: Wed Jun 13, 2007 8:10 am     Reply with quote

jani20 wrote:
My project is to read 9 piece of 10bit ADC value (from PIC16F690)
Store it, and send out to another PIC (HUART->RF TX module)
Then receive it (RF RX module->HUART) and store it in the same way.

Now I'm storing this 9x10bit ADC value in an int16 array.
But this is not effecient when sending out by RF!
It can contain some dummy bits, so it can by divided by 8.
(90bit + 6 dummy bits = 12Byte)

So can I define somehow an own struck that contains
9x10bit variables? (or bitfields?)

Declare a variable of that struct and send this variable out to UART.

On the receiver side the UART will store the values in the same own type.

And the channels can by accessed like: channels.ch1=channels.ch1 + 2

Thank you!

I think the key word here is efficient. What you suggest would take less RAM space and make a smaller packet at the cost of a great deal more ROM and time spent accessing the variables. What is your weak link that you wish to strengthen? Faster data transfer?

If you just want faster data transfer I suggest you make a compressed packet to speed the transfer but store the data as INT16 internally. This would keep compression and decompression as part of the data transfer process.
jani20



Joined: 14 Nov 2006
Posts: 14

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number

PostPosted: Wed Jun 13, 2007 10:05 am     Reply with quote

I need smaller packet because I cant exceed the servo T period time
20mS-2-> worst case I have 18mS to receive the data do the CRC check and process the data.

And its hard to find cheap TX/RX 433Mhz module wich have higher bandwidth han 4800bit/s or 9600 bit/s.

The whole frame is: 8 sync Bit + 9x16 channel Bit + 16 CRC16 bit

The whole frame is: 168Bit -> 21Byte long
The time to send this in worst case (without the proccess time on RX side): 15mS (max) (0.015sec)
So the minimum bandwidth needed: 11200 bps (bit/sec)

Maybe the 900Mhz TX/RX modules have higher bandwidth, but they cost more.

The Packet compression output I think is not FIX length.
So it can cause some problems.
And requires a lot of resources in the PIC.

Thank you!
Ttelmah
Guest







PostPosted: Thu Jun 14, 2007 4:24 am     Reply with quote

OK.
I would _not_ reorganise the data. The problem here is that if the data is stored in the sequential bit format, the work involved in accessing every value, will be huge, and will occur, every time the data is accessed. Instead, send the data _once_, in a better format for the radio, and rebuild it _once_ on reception.
Now, for this specific layout, I'd suggest something like:
Code:

union combine {
   int16 word;
   int8 b[2];
}

union combine data[9];
#define two_bits(x) (data[x].b[1]&3)

//Access the 16bit words, with data[x].word, to write the ADC values
//etc..
//Then to send (assuming byte transmission routine is called 'send':

int8 ctr;

for (ctr=0;ctr<9;ctr++) {
    send(data[ctr].b[0]);
    //sends the 9 LSB's
}

send(two_bits(0)+(two_bits(1)<<2)+(two_bits(2)<<4)+(two_bits(3)<<6));
send(two_bits(4)+(two_bits(5)<<2)+(two_bits(6)<<4)+(two_bits(7)<<6));
send(two_bits(8));

This will send the 9 LSB's from the data, then followed by three bytes containing the extra two bits from each word (four pairs each in the first two bytes, and just the two bits in the last byte).

Now on reception (you don't say what type of chip is involved here, so I'll assume another PIC), you simply write the first 9 bytes into the 9 LSB values, as at the transmission, and then for the extra bits, use something like (assuming the byte reception is called 'get':
Code:

int8 ctr;
int8 temp
//first retrieve 9 bytes as before
for (ctr=0;ctr<9;ctr++) {
   data[ctr].b[0]=get();
}

//Now get the extra three bytes
for (ctr=0;ctr<9;) {
   if ((ctr%4)==0) {
      temp=get();
   }
   data[ctr++].b[1]=temp&3;
   temp=temp/4;
}

What happens is that the second part reads a byte, on the first loop (0%0 is 0), and on the fifth loop, and the ninth loop. Then each time round, the bottom two bits of the last read byte, are transferred to the location required in the array (assuming it is declared with the same 'union' structure as at the transmission end).

Best Wishes
jani20



Joined: 14 Nov 2006
Posts: 14

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number

PostPosted: Thu Jun 14, 2007 5:02 am     Reply with quote

Thank you! I'll try it out.
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