View previous topic :: View next topic |
Author |
Message |
Redmond Guest
|
What should be an easy 16bit read - apparently not ? |
Posted: Mon Sep 10, 2007 6:24 pm |
|
|
Helo,
I am trying to read from a table array which is set up as 80 individual bytes, stored at every 9th and 10th byte is a single 16bit value
So, my plan was to read and write bytes 0-7 normally then when I get to the 8th byte just read it as an int16. I'm kind of used to asm where I can just use MOV.w
The idea was to do something like this:
Code: |
value = table[current_entry+8]; //or something with *&table
|
And thus capture [8] and [9] but obviously this doesn't work. And I have to do it quiet a bit so I looking for something more effecicent then grabbing [8] and shifting over 8 bits then adding [9]
Is there a good way to do this in CCS ? I know I could maybe set up unions but I'm not sure how that would work with my indexing (current_entry is multiples of 10)
Thank You! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Redmond Guest
|
|
Posted: Tue Sep 11, 2007 9:46 am |
|
|
Cool, I'll try that.
Is make16 fast ? I was really hoping for something quick, but the quickest I can think of would be pointers and I can't seem to get that working correctly
I can get 1 byte no problem, but no matter what I do I can't seem to get it and its next byte. |
|
|
Ttelmah Guest
|
|
Posted: Tue Sep 11, 2007 9:51 am |
|
|
Make16, is very fast.
Pointers are actually relatively slow (as is the actual access to the array). However you are only talking a handful of instructions for the array access, and the make16, is done in effectively just two instructions, just transferring the bytes (once read), into the required byte in the output variable.
Best Wishes |
|
|
Redmond Guest
|
|
Posted: Tue Sep 11, 2007 11:43 am |
|
|
I read that part in the manual about 2 ins right after I posted that. Thats cool, wish I would have know that earlier
One quick follow up about arrays being slow, it that a treat from CCS, PIC or just a general truth about all micros ? |
|
|
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Wed Sep 12, 2007 7:12 am |
|
|
Some micros are better than others - to access an array element (for 1-d case) you need a scaled offset from the start address of the array. So if the micro has indexed addressing then it's better, and if it has left shift capability even better (then it can address bytes, 16 bits, 32 bits etc with a simple 'add shifted index to base' to get the address).
IIRC PIC18's have some sort of extended addressing, but the CCS compiler does not use this extended mode? |
|
|
|