How can I speed this code up? SHIFTOUT is slowing it down and I need a faster way.
I think what is slowing this down is the SHIFTOUT.
I am running a 16f88 @ 16MHz and I need to know the fastest way to get through this loop:
Code:
LOOP:
FOR DATA = 4095 to 0 step -1
GOSUB SUB1
GOSUB SUB2
NEXT
FOR DATA = 0 to 4095 step 1
GOSUB SUB1
GOSUB SUB2
NEXT
GOTO LOOP
SUB1:
FOR C1 = 0 TO 15
shiftout dpin,clk,1,[DATA]
NEXT
PORTB = %00100000
PORTB = %00000000
RETURN
SUB2:
PORTB = %00000100
PORTB = %00000000
FOR C3 = 0 TO 4095
PORTA = %00001000
PORTA = %00000000
NEXT
RETURN
2 Attachment(s)
How about ASM replacement for PBP Shiftout?
Hi Wolwil,
You could replace PBP SHIFTOUT with attached ASM code example and reduce time spend in SHIFTOUT + loop to ~1/8. This is kind of tested, but no promises ... Check if it is usefull for you.
PBP_shiftout execution time was around 814uS, but ASM_shiftout took only 104uS to do the same.
Files:
Attachment 4384 <- Original, copied from 1st post
Attachment 4385
(Just remove .txt from end of files)
I know that ASM version is spaghetti code but I don' really care :)
So long time since last time when I did something with ASM.
BR,
-Gusse-
I was able to get the HPWM to work but no luck on the ASM
here is the code for the PWM:
Code:
C1 var byte
For C1 = 0 to 31
hpwm 1,127,32767
next
looks like I didn't need all the extra mumbo jumbo before it as the 16f88 defaults to b0 for channel 1
The sad thing is this still is not fast enough to do what I need it to do.
I am trying to generate 4096 clock pulses as fast as possible. The chip will allow up to a 30MHz clock pulse to drive it but using the HPWM all I can get is 32,767Hz which is like paying full price for a Lamborghini that only has first gear.
Does anyone have any ideas on how I might be able to achieve this?
Thanks Bruce that last bit of Code worked like a charm!!!
I didn't have to turn off the WDT, I think its off by default but could not find where it tells me in the manual. What will happen if its on? Would I notice it?
I do have one issue but it might just be an issue with it being on a bread board but when I use the Define OSC 20 with the 20 MHz clock it freaks out and does what ever it feels like and is sensitive to the touch but when I use no Define or Define OSC 4MHz but run it with the 20MHz clock it runs fine...I don't get it haha
Thanks again everyone, I am very grateful for all your help and suggestions