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

Speeding up code - Assembly code using compiler

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



Joined: 09 Feb 2007
Posts: 58

View user's profile Send private message

Speeding up code - Assembly code using compiler
PostPosted: Fri Jan 09, 2015 9:18 am     Reply with quote

Hello

I need to speed up a simple code that reads data from four A/Ds connected to my PIC.

I have the following code to read from the first two A/Ds:

//*** C Code ***
signed int16 ADC_REF0, ADC_REF1;

ADC_REF0=input_d(); //Read 1st ADC
output_high(PIN_E3); //enable data from 2nd ADC
delay_cycles(2);
ADC_REF1=input_d();
//*** End of C code **

The compiled code looks like this:

.................... ADC_REF0=input_d();
1FF60: PUSH E32
1FF62: POP 62EE
....................
.................... output_high(PIN_E3); //enable data from 2nd ADC
1FF64: BSET.B E44.3
.................... delay_cycles(2);
1FF66: REPEAT #0
1FF68: CLRWDT
.................... ADC_REF1=input_d();
1FF6A: PUSH E32
1FF6C: POP 62F0


Now, I need to reduce the speed of execution of 2nd to 4th A/D read by
at least two cycles. I think this could be done by removing the "delay_cycles(2)" instruction. But for this to work properly the assembly command "BSET.B E44.3" would need to be placed, for the 2nd A/D read, between the "PUSH E32" and "POP 62EE" commands. Then, the delay in running the "POP 62EE" command would be enough for the ADC data to settle on the d register bus.

My question is, is it possible to instruct the compiler to insert the assembly
code as suggested. The issue really is how would the argument for the "POP" commands be written as they refer to variable addresses ADC_REF0, ADC_REF1,.. etc.

I would be interested to hear any suggestions.

Thanks!
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jan 09, 2015 9:48 am     Reply with quote

need to know a few things, like PIC type, compiler version,small program to show what you're doing....
1st. I have no idea why the clrwdt isnt. is there, that's odd to me...
2nd. the delay 2 cycles could be to allow the ADC to stabilze after channel selection. This is mandatory for most(all) ADC with switched inputs.
3rd. you can create your own inline ADC 'control code' and bypass what CCS does, though their code is pretty tight and conforms to the uChip recommendations.
4th. what's the overall project? How fast is fast? You might, and that's a long shot, get faster speed by using a separate ADC for each input,maybe, it's an option, you might explore as I don't have enough information.

5th. in rereading the assembler there is NOTHING about accessing the ADC! seems you're reading a digital port ( D in this case) and setting an I/O pin (E3 in this code) so now I'm confused(easy at 61 !).Perhaps you can post schematic or use text to explain what you're doing.

happy to help, just need more info
Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Jan 09, 2015 10:10 am     Reply with quote

He has specified that delays should reset the WDT. Hence the clrwdt....

and to his actual question, 'yes', just use the #ASM, and #ENDASM driectives. Look in the examples, there are a couple showing how to write assembler in the code.
nazoa



Joined: 09 Feb 2007
Posts: 58

View user's profile Send private message

PostPosted: Fri Jan 09, 2015 10:18 am     Reply with quote

temtronic, thanks for the reply.

My question is really about the CCS compiler, not really about the PIC chip or the ADC hardware. I need to find out if I can get the compiler to do the assembly code as I explained.

FYI, the ADC control is being done in a PLD. The code I showed is simply reading the AD values after the conversion has been done. Just need to squeeze a bit more speed out of the simple code as I explained.
nazoa



Joined: 09 Feb 2007
Posts: 58

View user's profile Send private message

PostPosted: Fri Jan 09, 2015 10:22 am     Reply with quote

Thanks Ttelmah

Yes, I understand #asm and #endsam is the thing to use.

My question, as I explained in my post, relates to how to specify the argument for the "POP" command. The point is that these are variables addresses that may change every time the code is re-compiled following any modifications.

Thanks again!
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jan 09, 2015 10:23 am     Reply with quote

whew ! Man it's easy to confuse me these dayze !! Yup, CCS does have a couple asm examples in the manual, btw, pressing F11 while your project is open , will open the manual...


jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Jan 09, 2015 3:54 pm     Reply with quote

You can use C variable names in CCS assembler. Then addresses will automatically change.
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