Problems with audio controller

Thread Starter

NSCC_EETN

Joined Oct 6, 2010
17
We are having an issue with our audio controller and we are looking for some assistance. We're using a configuration of 10 keys with a speaker output using a PIC16f887. For some reason we are not getting any sound out of the speaker when a button is pressed.

What we are trying to do is have one key output a particular frequency using Timer0 to the speaker. For some reason the code is not working as it should and we are stumped as to find a solution.

We think it might have to do with the interrupt routine at the top of the programming, but are not 100% sure. If someone could help us that would be appreciated as we are behind schedule trying to work this tiny kink out of our project.

Rich (BB code):
;********************** Header ***************************************************

  LIST R=DEC                   ; list directive to define processor
 INCLUDE "p16f887.inc"           ; processor specific variable definitions

    __CONFIG  _CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOR_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF & _DEBUG_OFF
__CONFIG _CONFIG2, _BOR40V & _WRT_OFF
;************* DEFINING VARIABLES ************************************************

       cblock      0x20            ; Block of variables starts at address 20h
       w_temp                      ; Variable at address 20h
       pclath_temp                 ; Variable at address 21h
       status_temp                 ; Variable at address 22h
       endc                                
       
;************************ PROGRAM START ******************************************
       org         0x0000          ; Address of the first program instruction
       goto        setup            ; Jump to label "setup"

;************************ INTERRUPT ROUTINE **************************************
 
       org         0x0004          ; Interrupt vector
       movwf       w_temp          ; Saves value in register W
       movf        STATUS          ; Saves value in register STATUS
       movwf       status_temp
       movf        PCLATH          ; Saves value in register PCLATH
       movwf       pclath_temp
       
      
       
       movf        pclath_temp,w   ; PCLATH is given its original content
       movwf       PCLATH
       movf        status_temp,w   ; STATUS is given its original content
       movwf       STATUS
       swapf       w_temp,f        ; W is given its original content
       swapf       w_temp,w
        
       bsf         INTCON,GIE      ; Global interrupt enabled

       retfie                      ; Return from interrupt routine
       
 ;*********************************setup**********************************************      
setup
 banksel ANSEL
   clrf ANSEL                           ;set PORTA as digital
   clrf ANSELH  
 banksel TRISA                            
   bsf   TRISA, 0
   bsf   TRISA, 1
   bsf   TRISA, 2
   bcf   TRISB, 7                   
   bsf OSCCON,0                           ;make program clock internal
   bcf OSCCON,6
   bcf OSCCON,5
   bcf OSCCON,4                           ;make frequncy 31Khz
   clrf PORTD
   clrf PORTC
   clrf PORTB
;************************ MAIN PROGRAM *******************************************
main                               ; Start of the main program
 
   btfsc PORTA, 0                    ;check to see if the C key is pressed
   call noteC                        ;if so start note
   
   btfsc PORTA, 1                    ;check to see if the D key is pressed
   call noteD                        ;if so start note
      
   btfsc PORTA, 2                    ;check to see if the E key is pressed
   call noteE                        ;if so start note
 
   goto main


;*********************************subs**********************************
noteC
   banksel     OPTION_REG      ; Bank containing register OPTION_REG
   bcf         OPTION_REG,T0CS ; TMR0 counts pulses from oscillator       
   bcf         OPTION_REG,PSA  ; Prescaler is assign to timer TMR0
       
   bsf         OPTION_REG,PS0  ; Prescaler rate is 1:256
   bsf         OPTION_REG,PS1
   bsf         OPTION_REG,PS2

   banksel     INTCON          ; Bank containing register INTCON
   bsf         INTCON,5     ; TMR0 interrupt overflow enabled
   bsf         INTCON,GIE      ; Global interrupt enabled

Loop

   btfss       INTCON,2
   goto $-1
   bsf           PORTB, 7

   banksel     OPTION_REG      ; Bank containing register OPTION_REG
   bcf         OPTION_REG,T0CS ; TMR0 counts pulses from oscillator       
   bcf         OPTION_REG,PSA  ; Prescaler is assign to timer TMR0
       
   bsf         OPTION_REG,PS0  ; Prescaler rate is 1:256
   bsf         OPTION_REG,PS1
   bsf         OPTION_REG,PS2

   banksel     INTCON          ; Bank containing register INTCON
   bsf         INTCON,5     ; TMR0 interrupt overflow enabled
   bsf         INTCON,GIE      ; Global interrupt enabled

   btfsc       INTCON,2
   goto $-1
   bcf         PORTB, 7

   goto Loop


noteD
  banksel     OPTION_REG      ; Bank containing register OPTION_REG
   bcf         OPTION_REG,T0CS ; TMR0 counts pulses from oscillator       
   bcf         OPTION_REG,PSA  ; Prescaler is assign to timer TMR0
       
   bcf         OPTION_REG,PS0  ; Prescaler rate is 1:2
   bcf         OPTION_REG,PS1
   bcf         OPTION_REG,PS2

   banksel     INTCON          ; Bank containing register INTCON
   bsf         INTCON,5   ; TMR0 interrupt overflow enabled
   bsf         INTCON,GIE      ; Global interrupt enabled

Loop1

   btfss       INTCON,2
   goto $-1
   bsf           PORTB, 7

   banksel     OPTION_REG      ; Bank containing register OPTION_REG
   bcf         OPTION_REG,T0CS ; TMR0 counts pulses from oscillator       
   bcf         OPTION_REG,PSA  ; Prescaler is assign to timer TMR0
       
   bcf         OPTION_REG,PS0  ; Prescaler rate is 1:2
   bcf         OPTION_REG,PS1
   bcf         OPTION_REG,PS2

   banksel     INTCON          ; Bank containing register INTCON
   bsf         INTCON,5   ; TMR0 interrupt overflow enabled
   bsf         INTCON,GIE      ; Global interrupt enabled

   btfsc       INTCON,2
   goto $-1
   bcf         PORTB, 7

   goto Loop1

     
noteE
   banksel     OPTION_REG      ; Bank containing register OPTION_REG
   bcf         OPTION_REG,T0CS ; TMR0 counts pulses from oscillator       
   bcf         OPTION_REG,PSA  ; Prescaler is assign to timer TMR0
       
   bsf         OPTION_REG,PS0  ; Prescaler rate is 1:16
   bsf         OPTION_REG,PS1
   bcf         OPTION_REG,PS2

   banksel     INTCON          ; Bank containing register INTCON
   bsf         INTCON,5   ; TMR0 interrupt overflow enabled
   bsf         INTCON,GIE      ; Global interrupt enabled
 
Loop2

   btfss       INTCON,2
   goto $-1
   bsf           PORTB, 7

   banksel     OPTION_REG      ; Bank containing register OPTION_REG
   bcf         OPTION_REG,T0CS ; TMR0 counts pulses from oscillator       
   bcf         OPTION_REG,PSA  ; Prescaler is assign to timer TMR0
       
   bsf         OPTION_REG,PS0  ; Prescaler rate is 1:16
   bsf         OPTION_REG,PS1
   bcf         OPTION_REG,PS2

   banksel     INTCON          ; Bank containing register INTCON
   bsf         INTCON,5   ; TMR0 interrupt overflow enabled
   bsf         INTCON,GIE      ; Global interrupt enabled 

   btfsc       INTCON,2
   goto $-1
   bcf         PORTB, 7

   goto Loop2

   return

  end                         ; End of program
 
Top