18X/8 MHz Loop and ADC Timing

Tom2000

Senior Member
I was curious about loop termination test time and someone in here was curious about ADC timing recently. I set up an 18X, running at 8 MHz, and measured loop timing under different conditons using my oscilloscope.

In each loop, I included a toggle 0 instruction. I connected my 'scope to Out0 and measured the period of the positive half of the square wave.

Take the timing figures as a guide. My 'scope is an old Tek 2235, of unknown calibration state. But the numbers should be "close enough for government work," I guess.

I re-ran the ADC tests at 4 MHz, and, as expected, found that an ADC measurement at 4 MHz costs about twice as much as one performed at 8 MHz.

The results are included as comments in the code below.

Some costs:

--Adding a loop termination test to a do..loop until structure costs 160 uSec. This is true for either a pin state test or a variable calculation.

--A do..loop until structure is much cheaper than a for..next structure, by 360 uSec.

--An ADC measurement, either 8 or 10 bit, costs about 250 uSec. At 4 MHz, an ADC test costs approx 500 uSec.

HTH,

Tom


Code:
#rem

   Picaxe 18X v8.6 Speed Test - tjl 10/5/07
   
   Timing obtained by monitoring Out0 with an oscilloscope
   
**********************************************   
   
   Costs at 8 MHz:
   
      Loop termination test: do..loop until structure
      
         160 uSec
         
      For..next structure vs do..loop until structure:
      
         360 uSec
         
      ADC measurement, 8 or 10 bit:
      
         approx 250 uSec (or 500 uSec at 4 MHz)
      
**********************************************      
         

#endrem





Main:

  setfreq m8
  
  

#rem
; Case 1:  Maximum speed loop
  
  ;  Result: 540 uSec / loop 

  ;  4 MHz spot check:  1.08 mSec / loop
     
  do
  
     toggle 0
     inc w0
     
  loop
#endrem


#rem
; Case 2:  Loop with pin state test
  
  ;  Result:  700 uSec / loop 
     
  do
  
     toggle 0
     inc w0
     
  loop until pin1 = 1
#endrem  
  

#rem
; Case 3:  Loop with termination test
  
  ;  Result:  700 uSec / loop
     
  do
  
     toggle 0
     inc w0
     
  loop until w0 = 0
#endrem  
 

#rem
; Case 4:  Loop incorporating ADC measurement
  
  ;  Result:  780 uSec / loop

  ;  4 MHz spot check:  1.59 mSec / loop
  
  do
  
     toggle 0
     readadc 1,b0
     inc w0
     
  loop
#endrem  


#rem
; Case 5:  Loop incorporating ADC10 measurement
  
  ;  Result:  790 uSec / loop
  
  do
  
     toggle 0
     readadc 1,w1
     inc w0
     
  loop
#endrem  
 

#rem
; Case 6:  Loop incorporating ADC measurement and loop termination test
  
  ;  Result:  940 uSec / loop
  
  do
  
     toggle 0
     readadc 1,w1
     inc w0
     
  loop until w0 = 0
#endrem  

 
#rem
; Case 7:  For/next loop
  
  ;  Result:  900 uSec / loop 
     
  for w1 = 0 to 65535
  
     toggle 0
     inc w0
     
  next
#endrem  


#rem
; Case 8:  For/next loop with ADC measurement
  
  ;  Result:  1.15 mSec / loop 
     
  for w1 = 0 to 65535
  
     toggle 0
     readadc 1,b0
     inc w0
     
  next
#endrem  
  
 
  
  low 0
  
  do
  loop 
     
         
  
end
 
Last edited:

Dippy

Moderator
450 nanoseconds for an ADCing?


And:-
#rem
; Case 6: Loop incorporating ADC measurement and loop termination test
; Result: 940 nSec / loop

do

toggle 0
readadc 1,w1
inc w0

loop until w0 = 0

940 nanoseconds, 0.94 microseconds... 1Msps. Wow!
That's faster than I can get an 18F2520 @20MHz to do an ADC read in compiled C!
Amazing :)
 

Tom2000

Senior Member
940 nanoseconds, 0.94 microseconds... 1Msps. Wow!
That's faster than I can get an 18F2520 @20MHz to do an ADC read in compiled C!
Amazing :)
Uhhhh... would you believe about 1063 sps?

You're correct, though. Replace nanoseconds with microseconds. (I shouldn't do this stuff late at night...)

Also, your sarcasm is noted.
 
Last edited:

Dippy

Moderator
I'd have blamed it on the 'scope! I prefer to call it 'irony' :)

Seriously though, that's useful info.

PS. I make mistakes on an hourly basis so don't worry.
 
Last edited:

Tom2000

Senior Member
Yeah, it goes that way. I did the 18X experiment as a break from reading the 18F2431 data sheet. My eyes were crossing.

I'm trying to do 2 simultaneous ADC conversions at 44.1 kHz, and can't figure out how the interrupts are supposed to work. I know the answer is in the data sheet somewhere, but I'll be darned if I can find it.

Back to the data sheet.
 
Top