View previous topic :: View next topic |
Author |
Message |
beaker404
Joined: 24 Jul 2012 Posts: 163
|
loop time |
Posted: Fri May 24, 2019 9:55 am |
|
|
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
|
|
Posted: Fri May 24, 2019 9:58 am |
|
|
correction, loop time is 1.05mS not 250uS. |
|
|
beaker404
Joined: 24 Jul 2012 Posts: 163
|
|
Posted: Fri May 24, 2019 10:11 am |
|
|
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
|
|
Posted: Fri May 24, 2019 10:42 am |
|
|
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: 9241 Location: Greensville,Ontario
|
|
Posted: Sat May 25, 2019 4:43 am |
|
|
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 |
|
|
|