' MemPot / Daniel Blackburn & Tuomo TammenpŠŠ ' Version 1.0 / June 7, 2007 ' oikosulku.blogspot.com / misusage.org ' ------------------------------------------------------------------------------ ' 10k pot with 100k resistor gives a range of 0 to ~110 ' 10k pot with 10k resistor gives a range of 0 ~600 ' PIC16F819 & digital potentiometer DS1267 ' ------------------------------------------------------------------------------ INCLUDE "modedefs.bas" 'external HS oscillator definition DEFINE OSC 20 'internal slower 8mhz definition 'define osc 8 'OSCCON = $70 ' Define ADCIN parameters Define ADC_BITS 10 ' Set number of bits in result Define ADC_CLOCK 3 ' Set clock source (3=rc) Define ADC_SAMPLEUS 20 ' Set sampling time in uS TRISA = %11111111 ' Set PORTA to inputs ADCON1 = %10000010 ' Set PORTA analog and right justify result TRISB = %00110000 ' RB5 RB4 to input, rest to outputs ' ------------------------------------------------------------------------------ ' Constants ' ------------------------------------------------------------------------------ true CON 1 ' true false CON 0 ' false ' ------------------------------------------------------------------------------ ' Variables ' ------------------------------------------------------------------------------ index VAR Byte ' loop index, buffer length counter VAR Byte ' loop counter tmp var byte ' tmp pot1 var word ' Pot result pot2 var word ' Pot rate ' ------------------------------------------------------------------------------ ' Pin variables ' ------------------------------------------------------------------------------ serial_clock var PORTB.0 ' serial clock for the digipot serial_data var PORTB.2 ' serial data for the digipot serial_reset var PORTB.1 ' reset for digipot serial comms power_led var PORTB.3 ' piezo for debug sounds set_button VAR PORTB.4 ' button for setup mode rec_button var PORTB.5 ' button to select record/playback state pc_debug var PORTB.7 ' serial output to LCD at 19,200bps ' ------------------------------------------------------------------------------ init: ' Setup code ' ------------------------------------------------------------------------------ pause 10 ' clear memory FOR index = 0 TO 255 WRITE index, index NEXT ' setup variable counter = 0 Serout2 pc_debug,16416,0,[254, 88] 'clear screen for Matrix Orbital LCD0821 Serout2 pc_debug,16416,0,[254, 67] 'wrap text ' ------------------------------------------------------------------------------ main: ' main loop ' ------------------------------------------------------------------------------ if set_button = 1 then setup pause 10 ADCIN 0, pot1 ADCIN 1, pot2 ' CHECK FOR RECORD/OVERDUB BUTTON PRESS IF rec_button = 0 THEN high power_led tmp = pot1 / 3 WRITE counter, tmp low power_led endif ' OUTPUT STORED DATA TO DIGIPOT READ counter, tmp HIGH serial_reset 'currently only the first pot is used. add extra features here SHIFTOUT serial_data, serial_clock, MSBFIRST, [0\1, tmp\8, tmp\8] LOW serial_reset ' PAUSE AN LOOP STUFF HERE if counter = index then counter = 0 else counter = counter + 1 endif pause pot2 ' set this pause based on second variable resistor Goto main ' ------------------------------------------------------------------------------ setup: ' debug pot values via serial LCD (or pc) if set_button = 0 then main high power_led ADCIN 0, pot1 ADCIN 1, pot2 Serout2 pc_debug,16416,0,[DEC3 pot1," ", DEC3 pot1/3] Serout2 pc_debug,16416,0,["buf: ", DEC3 pot2/3] index = pot2/3 ' define buffer length with pot2 (/3) value pause 30 LOW power_led goto setup End