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

loop time

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



Joined: 24 Jul 2012
Posts: 163

View user's profile Send private message

loop time
PostPosted: Fri May 24, 2019 9:55 am     Reply with quote

working on a high speed ADC project. checking my loop time by using a toggle of a pin. In this case J5. just running the toggle the loop time is 500nS.
when I add a call to this code the loop time goes to 250uS:

Code:

int ADS8584S_START_ACQ() {
// This function starts the ACQ process on the ADS8584S
// CONVSTA and CONVSTB are tied together, use CONVSTA for control.


   
   

    int loop_control = 1;                      // used to control while loop.
   int status = 0;
   int16 t1_start = 0;
    int16 t1_difference = 0;
    int16 t1_end = 0;                   // Timer1 running at 20KHz (50uS per count)

   
   
   output_high(ADC_CONVSTA);
    //delay_us(ADC_DELAY);                     // 2uS delay
    output_low(ADC_CONVSTA);
}


as noted in the comments, I am running timer1 at 20KHz roll rate. but have that code commented out at this time.
ADC_CONVSTA is on PIN_J1
I am surprised that the calls to output_high and output_low take so long.

any ways to speed it up?

18F87K22 running at 60MHz.

CCS 5.061
MPLAB 8.91
windows 10
beaker404



Joined: 24 Jul 2012
Posts: 163

View user's profile Send private message

PostPosted: Fri May 24, 2019 9:58 am     Reply with quote

correction, loop time is 1.05mS not 250uS.
beaker404



Joined: 24 Jul 2012
Posts: 163

View user's profile Send private message

PostPosted: Fri May 24, 2019 10:11 am     Reply with quote

well scrubbed the code and found a random delay_ms(1) call that I forgot to take out.
code runs much faster now. still interested in how to speed code up specifically if there are tricks with the digital I/O to make the output_high output_low calls faster as I am banging pins for CS control of the ADC.

also, using a crude way to build my data word from the 16 bit parallel output of the ADC. the data pins are going to I/O pins on the pic and using the following code for that, interested if there are faster ways to do this without redoing my hardware.
Code:

int16 ADS8584S_BUILD_CHANNEL_VALUE() {

int16 value=0;

if(input(ADC_D15) == 1) {      // 32768

   value = value + 32768;

}

if(input(ADC_D14) == 1) {

   value = value + 16384;

}

if(input(ADC_D13) == 1) {

   value = value + 8192;

}

if(input(ADC_D12) == 1) {

   value = value + 4096;

}

if(input(ADC_D11) == 1) {

   value = value + 2048;

}

if(input(ADC_D10) == 1) {

   value = value + 1024;

}

if(input(ADC_D9) == 1) {

   value = value + 512;

}

if(input(ADC_D8) == 1) {

   value = value + 256;

}

if(input(ADC_D7) == 1) {

   value = value + 128;

}

if(input(ADC_D6) == 1) {

   value = value + 64;

}

if(input(ADC_D5) == 1) {

   value = value + 32;

}

if(input(ADC_D4) == 1) {

   value = value + 16;

}

if(input(ADC_D3) == 1) {

   value = value + 8;

}

if(input(ADC_D2) == 1) {

   value = value + 4;

}

if(input(ADC_D1) == 1) {

   value = value + 2;

}

if(input(ADC_D0) == 1) {

   value = value + 1;

}

return value;

}  // end BUILD_CHANNEL_VALUE()
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Fri May 24, 2019 10:42 am     Reply with quote

You can use the FAST_IO directive as well as a union.

with FAST_IO and union
Code:
value_test.val0 = input(PIN_A0);
010A:  BCF    40.0
010B:  BTFSC  0C.0
010C:  BSF    40.0

with FAST_IO and your method
Code:
................... if(input(PIN_A0) == 1) {      // 32768
00A8:  BTFSS  0C.0
00A9:  GOTO   0AC
....................    value = value + 32768;
00AA:  MOVLW  80
00AB:  ADDWF  43,F

without FAST_IO and union
Code:
.................... value_test.val11 = input(PIN_C1);
012E:  MOVLB  01
012F:  BSF    0E.1
0130:  MOVLB  00
0131:  BCF    41.3
0132:  BTFSC  0E.1
0133:  BSF    41.3

without FAST_IO and your method
Code:
.................... if(input(PIN_C0) == 1) {
00D4:  MOVLB  01
00D5:  BSF    0E.0
00D6:  MOVLB  00
00D7:  BTFSS  0E.0
00D8:  GOTO   0DD
....................    value = value + 32;
00D9:  MOVLW  20
00DA:  ADDWF  42,F
00DB:  MOVLW  00
00DC:  ADDWFC 43,F
temtronic



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

View user's profile Send private message

PostPosted: Sat May 25, 2019 4:43 am     Reply with quote

I'm wondering if instead of adding to'value', you bitset 'value' bits based on the testing, if it'd be faster?
I recall a uChip app note or tips 'n tricks about doing that....
Though it's been decades since I read that in a real book.....

hmm...raining cats, dogs and giraffes here so I cut some code...
got this which looks like it shaves off some time and space !
Code:

190:               if(input(ADC_D15) == 1) bit_set(value,15);
  0662    8292     BSF 0xf92, 0x1, ACCESS
  0664    B280     BTFSC 0xf80, 0x1, ACCESS
  0666    8E1B     BSF 0x1b, 0x7, ACCESS

though someone can test, I've got a leaky gutter to fix...arrgh

Jay
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