I realized what the problem was. xprevious =x was in the movepot subroutine, so anytime either the analog pot or tempo button changed x, xprevious would change.
This seems to have fixed it.
Now I just need to make some fine adjustments so that the tempopress subroutine changes x so that the echoes are actually in time with the tempo that is tapped out. And I also need to add the division toggle switch. That's pretty simple though. It just divides x in half for double time or thirds for triplets.Code:#config __CONFIG _CP_OFF & _WDTE_OFF & _BOREN_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _IOSCFS_8MHZ #endconfig ADCON0 = %00000000 ADCON1 = %00110000 ANSEL = %00000110 define ADC_SAMPLEUS 50 define ADC_BITS 8 DEFINE ADC_CLOCK 3 CM1CON0 = %00000000 CM2CON0 = %00000000 TRISA = %00001111 TRISC = %00000000 ' Set TMR0 interrupt prescaler to 1:128 OPTION_REG = %10000110 ' Set TMR0 configuration and enable PORTB pullups INTCON = %10100000 ' Enable TMR0 interrupts On Interrupt Goto tickint ' ' Hardware connection ' =================== CS VAR PORTA.5 SCK VAR PORTC.2 SDI VAR PORTC.1 tempoLED var PORTC.0 tempobutton var PORTA.0 bypassbutton var PORTA.3 bypassLED var PORTC.4 fetA var PORTC.5 fetB var PORTA.4 fetC var PORTC.3 ;pot is on porta.2 an2 ' ' Variables definition ' =================== w var byte ' division toggle switch x var byte ' delay time knob xprevious var byte z var byte ticks var word tapcount var word LEDcounter var word LEDrate var byte trailsmode var byte trailsmodecounter var word LEDon var byte LEDoff var byte override var bit analogpot var bit footswitch var bit analogpot = 1 footswitch = 0 ' ' begin in bypass ' =============== tempoLED = 0 fetA = 0 fetB = 0 fetC = 1 bypassLED = 0 trailsmode = 0 gosub readpot gosub movepot pause 100 main: tapcount = ticks gosub potcheck if LEDcounter < 1 then tempoLED = 1 else tempoLED = 0 endif if bypassBUTTON = 0 then gosub bypasspress gosub bypassbuttonrelease ENDif if tempobutton = 0 then goto tempopress endif goto main potcheck: gosub readpot if abs (xprevious-x) > 4 then override = analogpot gosub movepot endif return tempopress: ' subroutine that occurs when tempo button is tapped if tapcount > 180 then ' if longer than 3 seconds between taps, ignore the previous tap. ticks = 0 gosub tempobuttonrelease else x = tapcount + 10 override = footswitch gosub movepot ticks = 0 gosub tempobuttonrelease endif goto main tempobuttonrelease: ' debounce subroutine for tempo button tempoLED = 1 do until tempobutton = 1 pause 10 loop tempoLED = 0 return movepot: CS = 0 shiftout SDI, SCK, 1, [00000000,x] shiftout SDI, SCK, 1, [00010000,x] CS = 1 if override = analogpot then xprevious = x endif gosub tempoLEDadjust return readpot adcin 2,x x = 1 max x ;stop led from shutting down completely return tempoLEDadjust: ' compensate for TMR0 not being 1:1 with actual delay time LEDrate = (x/2) + 6 return bypasspress: trailsmodecounter = 0 ' waits to see if you want to switch between normal or trails mode do until trailsmodecounter = 400 if bypassbutton = 1 then exit pause 10 trailsmodecounter = trailsmodecounter + 1 loop if trailsmodecounter = 400 then goto trailmodechange endif if trailsmode = 1 then gosub trailsbypass elseif trailsmode = 0 then gosub normalbypass endif return trailmodechange: ' subroutine that occurs when bypass button is held long enough to change between normal or trails mode if trailsmode = 1 then trailsmode = 0 elseif trailsmode = 0 then trailsmode = 1 endif for z = 1 to 5 tempoLED = 1 pause 100 tempoLED = 0 pause 100 next z goto main normalbypass: ' subroutine for normal bypass if bypassLED = 0 then fetA = 1 fetB = 1 fetC = 0 bypassLED = LEDon elseif bypassLED = 1 then fetA = 0 fetB = 0 fetC = 1 bypassLED = 0 endif return trailsbypass: 'subroutine for trails bypass if bypassLED = 0 then fetA = 1 fetB = 1 fetC = 0 bypassLED = LEDon elseif bypassLED = 1 then fetA = 0 fetB = 1 fetC = 1 bypassLED = LEDoff endif return bypassbuttonrelease: ' debounce subroutine when bypass button is pressed do until bypassbutton = 1 pause 10 loop return Disable ' Disable interrupts during interrupt handler tickint: ' Interrupt routine to handle each timer tick LEDcounter = LEDcounter + 1 ' add 1 to LEDcounter on every interrupt if LEDcounter > LEDrate then LEDcounter = 0 endif ticks = ticks + 1 if ticks > 300 then 'prevent overflow when long periods of time pass between taps ticks = 240 endif tiexit: INTCON.2 = 0 ' Reset timer interrupt flag Resume enable end




Bookmarks