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

PIC18f array and arguments

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



Joined: 08 Dec 2011
Posts: 15
Location: Portugal

View user's profile Send private message

PIC18f array and arguments
PostPosted: Sat Dec 10, 2011 6:12 pm     Reply with quote

Hello again

I'm using pic18f4620 and compiler 4.124, after trying to find the correct way to set the configuration register with CCS language, I found the #FUSE NOIESO, what does it do, I've read the PIC datasheet but information there is also very little.

Code:

#include <18F4620.h>
#device adc=16
#list

#FUSES INTRC_IO
#FUSES NOCPD
#FUSES NOSTVREN
#FUSES NODEBUG
#FUSES NOIESO // What is this ??
#FUSES NOWDT
#FUSES FCMEN // Uses internal clock to check if external crystal fails
#FUSES PUT
#FUSES NOBROWNOUT
#FUSES NOPBADEN
#FUSES NOLVP
#FUSES NOXINST // does not used ADDFSR, ADDULNK, CALLW, MOVSF, MOVSS, PUSHL, SUBFSR, SUBULNK
#FUSES NOLPT1OSC
#FUSES NOEBTRB
#FUSES NOCPB
#FUSES NOPROTECT
#FUSES NOWRT
#FUSES NOWRTB 
#FUSES NOWRTC
#FUSES NOWRTD
#FUSES NOEBTR



Also I think I'm coding this very very wrong, suppose that I read from the UART some bytes and store them into an array:

Code:

#define MAXMEM 3072 
unsigned int8 dataCache[MAXMEM];


Then in Main() I use a cycle to store and call sample_function to do some work on them:
Code:

   unsigned int16 dataCache_position;
   unsigned int8 tmpInt;
   for(tmpInt=0;tmpInt<8;tmpInt++)
   {
      printf("\n\r Integer 8bit n.%u:",tmpInt);
      dataCache[tmpInt]=getc();
   }
   
   dataCache_position=0;
   sample_function(dataCache[dataCache_position],
dataCache[dataCache_position+1],
dataCache[dataCache_position+2],
dataCache[dataCache_position+3]);
   
  dataCache_position=dataCache_position+4;
  sample_function(dataCache[dataCache_position],
dataCache[dataCache_position+1],
dataCache[dataCache_position+2],
dataCache[dataCache_position+3]);


So, after reading the ASM file, I've found that it's taking a lot of instructions and cycles to go from the UART to the array, and from the Main() to the void.

How can I improve this codding, maybe more than one array and only int8 indexing, maybe direct access to the array in the sample_function, just need the right direction or some suggestions please.


Last edited by edmundopt on Sat Dec 10, 2011 6:24 pm; edited 1 time in total
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Dec 10, 2011 6:19 pm     Reply with quote

IESO is listed in fuses.txt in the PICC directory. Also, see page 260 of the datasheet
_________________
Google and Forum Search are some of your best tools!!!!


Last edited by dyeatman on Sat Dec 10, 2011 6:29 pm; edited 1 time in total
edmundopt



Joined: 08 Dec 2011
Posts: 15
Location: Portugal

View user's profile Send private message

PostPosted: Sat Dec 10, 2011 6:26 pm     Reply with quote

Thank you for the reply, I was editing the post because I've forgotten the main question. I'll search for the file, thank you!
ckielstra



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

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 8:40 am     Reply with quote

Quote:
So, after reading the ASM file, I've found that it's taking a lot of instructions and cycles to go from the UART to the array, and from the Main() to the void.
The PIC processor is not efficient in handling pointer calculations, it is missing some of the more advanced hardware instructions for this. Hey, that's how this processor got so cheap to make.

If speed and memory usage are important to you then you as a programmer have to 'think' more like a PIC processor. Now you know pointer arithmetic is expensive try to redesign your code with less pointers.

Now you are passing four parameters to sample_function, each the next byte from a buffer. You could change this to just passing a pointer to the first value and then have the sample_function get all required values from the buffer. This way you move the bulky calculation from each function call to a similar calculation just once inside the called function.

Code:
   dataCache_position=0;
   sample_function(&dataCache[dataCache_position]);
   
  dataCache_position=dataCache_position+4;
  sample_function(&dataCache[dataCache_position]);

or even more optimized:
Code:
   unsigned int8* dataCache_position;

   dataCache_position = &dataCache[0];
   sample_function(dataCache_position);
   
  dataCache_position += 4;
  sample_function(dataCache_position);


And the new sample_function:
Code:
void sample_function(int8 *sample)
{
   int8 sample1, sample2, sample3, sample4;

   sample1 = sample[0];
   sample2 = sample[1];
   sample3 = sample[2];
   sample4 = sample[3];

   ... your original code here
}
edmundopt



Joined: 08 Dec 2011
Posts: 15
Location: Portugal

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 11:29 pm     Reply with quote

Thank you ckielstra!
After taking a look to the ASM, with your code it has saved a lot of instruction cycles, but looking at your idea, I though what about creating a aux array, so suppose that the maximum number of arguments is four, so that

Code:

#define MAXMEM 3072
unsigned int8 dataCache[MAXMEM];
unsigned int8 functionOptimizer[4];


I was thinking of just copy all 4 values to the functionOptimizer array , and inside the sample_function, use them directly so they will allway be in the same place, something like this:

in main()
Code:

   memcpy(functionOptimizer,&dataCache[dataCache_position],4);
   sample_function();


I'm using 16bit to some calculations so I've included them in this sample function

Code:

void sample_function()
{
   unsigned int16 var_one;
   unsigned int16 var_two;
   var_one = make16(functionOptimizer[0],functionOptimizer[1]);
   var_two = make16(functionOptimizer[2],functionOptimizer[3]);
   printf("\n\r int16: %lu, int16:%lu",var_one,var_two);
}


The full code is working very well, (this code might not work because it's just a sample) and it takes a little bit less, and that is very usefull, but since my experience with CCS is kind of none, can you spot anything wrong ?

and about #fuses NOIESO, I still have no idea what do they do
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Dec 12, 2011 8:32 am     Reply with quote

edmundopt wrote:


and about #fuses NOIESO, I still have no idea what do they do


It's in the datasheet.

Start with the config registers in the "Special Features of the CPU" section.

Then look in the section on the Oscillator.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Dec 12, 2011 4:23 pm     Reply with quote

As I said earlier:
Quote:
Also, see page 260 of the datasheet


Take the NO off the front and look for the IESO bit in section 23.3.
That tells you exactly what it does.

Adding NO to the front turns it OFF.
_________________
Google and Forum Search are some of your best tools!!!!
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