Workshop 4: Data Storage and Retrieval

Purpose: Using the embedded controller to produce a sine and ramp function that is display on an Oscilloscope.

Objective: This workshop is designed to familiarize the student with elements of the embedded microcontroller.

Real world application: Modeling a synthesizer

Requirements: Hardware: Picstic-3, Digital to analog converter (AD558), Oscilloscope

Software commands: eeprom, read, asm, endasm

Procedure: Create a sine and ramp function. Based on the input to pa3, output the desired function to an digital to analog converter (DAC). Visually display the function by connecting the output of the DAC to an oscilloscope. The sine function must be created by filling 32 eeprom addresses with data points and then outputting each point to the DAC. The ramp function shall be software generated. Use an assembly subroutine to clear and take input on pa3. If pa3 has a logic 0 then the sine function shall be displayed, if a logic 1 is present then the ramp function shall be outputted.

Circuit Drawing for Workshop #4

PicBasic Code for Workshop #4

'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

'A program to generate, store and retrieve data
'Herb Wagner

'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

dirs = %11111111 'Set PB0-7 as outputs

'Store the following sine wave data points into
'onboard EEPROM
eeprom 0,(254,252,244,233,217,198,176,152,127)
eeprom (102,78,56,37,21,10,2,0,2,10,21,37,56)
eeprom (78,102,127,152,176,198,217,233,244,252)

begn:
         call clr_pa3 'Clear pa3
         call tst_pa3 'Test pa3
          if bit0 = 0 then sine 'if pa3 has a 0
                                     'on it jump to sine
         goto generate

'****************************************************

'Create a sine wave function 1000 times from data
'stored in EEPROM
sine:
     for w10 = 1 to 1000
     for b1 = 0 to 31
                 read b1,b2
                 pins = b2
     next b1
next w10
goto begn

'****************************************************

'Generate a ramp function 1000 times generate:

for w10 = 1 to 1000
              for b1 = 0 to 24
      b3 = b1 * 6
             pins = b3
         next b1
for b1 = 25 to 31
      b3 = b3 - 30
      pins = b3
   next b1
next w10
goto begn

'****************************************************

'Assembly subroutine to use pa3 as input to direct
'which function will be run

asm
_tst_pa3
         bsf status,5
         bsf trisa,3
         bcf status,5
         bcf _b0,0
         btfsc porta,3
         bsf  _b0,0
         goto done

_clr_pa3
        bcf porta,3
        bsf status,5
        bcf trisa,3
        bcf status,5
        goto done
endasm

'******************************************************