Hi All
Im just playing around with some code that im trying to use to look at incoming pulses, write them to an array and then output them with a specific delay (ie an offset in the array)
Pulses are coming in from a PWM signal (which i want to delay to the output) at around 600hz
my code on a 16f1847 roughly as follows:
Code:DEFINE OSC 4 OSCCON = %01101010 ' Oscillator internal 4 mhz PLL disabled CM1CON0.7 = 0 ' Comparator 1 off CM2CON0.7 = 0 ' Comparator 2 off CPSCON0.7 = 0 ' Capsense module off MDCON = %00000000 ' Disable the Modulator ANSELB = %00000000 ' Select no analog TRISA=%00000000 ' Port A all output TRISB=%00001001 ' Port B all output except 3 ,1 PulseArray var WORD [40] ' 40 words, 640 bits total if we can run at 1khz this will allow delay of upto 640ms ArrayBit var word ArrayBit=0 RunController: PulseArray.0[0] = PortB.0 'set the new 0 bit in the array as per b.0 For ArrayBit = 1 to 639 PulseArray.0[ArrayBit] = PulseArray.0[ArrayBit-1] ' move them all over 1x Next ArrayBit 'Go do next count toggle portb.4 ' use p4 to check loop time on scope PortB.5 = PulseArray.0[250] ' output this bit ~ 250ms delay goto RunController
the problem im seeing is my loop time on p4 is around 3hz, whereas the loop time within the for..next loop is around 3khz
so even if i up my clock speed to 20mhz it looks like its still not going to be fast enough to do this?
Does anyone have any better solutions or advise?


						
					
				
				
				
				
			

Bookmarks