Richard,
Thanks so much! That helped a lot. I made a few tweaks. I changed x = 8 max x to x = 1 max x in the readpot sub because that gave it a shorter minimum delay time. I added 7 to the LEDrate variable in the LEDtempoadjust sub because it was blinking just a slightly faster than the echoes. Then, of course I added back some of the variables and subs that pertain to the bypass switching.
So now everything works perfectly with the switching, the delay time pot, and the blinking tempo LED. There is still another hurdle for me (and hopefully, this is the last one). The last feature I need to implement is the tap tempo button. This allows the user to tap out the rate of the echoes with the button rather than using the delay time knob. So that when the end user taps out the rate with the tempo button, it overrides the delay time pot....until the pot is actually moved again. That might be why some of the things in my previous code seemed weird.
As it is now in the code below, the checkpot sub is constantly writing to the digital potentiometer. If I use the tap tempo button, it will change the tempo for a split second, but then the analog potentiometer immediately overwrites it. The checkpot sub is only supposed to check and see if the pot has been moved. I thought that by adding the if xprevious != to x and abs (xprevious - x) > 4 statement would do the trick, but it doesn't.
The way your code handles the pot is obviously way more efficient since you've pared what used to take up 1024+ words to down to 682, but it's also a little over my head. How would I make the check pot sub just check the pot to see if the pot has been moved, and move the digital pot only when the pot has been moved?
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
'
' begin in bypass
' ===============
tempoLED = 0
fetA = 0
fetB = 0
fetC = 1
bypassLED = 0
trailsmode = 0
gosub readpot
gosub movepot
main:
tapcount = ticks
if (LEDcounter // LEDrate) > (LEDrate>>1) then
tempoLED = 1
else
tempoLED = 0
endif
gosub potcheck
if bypassBUTTON = 0 then
gosub bypasspress
gosub bypassbuttonrelease
ENDif
if tempobutton = 0 then
goto tempopress
endif
goto main
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
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
potcheck:
gosub readpot
if xprevious != x and abs (xprevious-x) > 4 then
gosub movepot
endif
return
movepot:
CS = 0
shiftout SDI, SCK, 1, [00000000,x]
shiftout SDI, SCK, 1, [00010000,x]
CS = 1
xprevious = x
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) + 7
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
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