Problems with audio controller

Discussion in 'Embedded Systems and Microcontrollers' started by NSCC_EETN, Mar 8, 2011.

  1. NSCC_EETN

    Thread Starter New Member

    Oct 6, 2010
    17
    0
    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.

    Code ( (Unknown Language)):
    1.  
    2. ;********************** Header ***************************************************
    3.  
    4.   LIST R=DEC                   ; list directive to define processor
    5.  INCLUDE "p16f887.inc"           ; processor specific variable definitions
    6.  
    7.     __CONFIG  _CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOR_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF & _DEBUG_OFF
    8. __CONFIG _CONFIG2, _BOR40V & _WRT_OFF
    9. ;************* DEFINING VARIABLES ************************************************
    10.  
    11.        cblock      0x20            ; Block of variables starts at address 20h
    12.        w_temp                      ; Variable at address 20h
    13.        pclath_temp                 ; Variable at address 21h
    14.        status_temp                 ; Variable at address 22h
    15.        endc                                
    16.        
    17. ;************************ PROGRAM START ******************************************
    18.        org         0x0000          ; Address of the first program instruction
    19.        goto        setup            ; Jump to label "setup"
    20.  
    21. ;************************ INTERRUPT ROUTINE **************************************
    22.  
    23.        org         0x0004          ; Interrupt vector
    24.        movwf       w_temp          ; Saves value in register W
    25.        movf        STATUS          ; Saves value in register STATUS
    26.        movwf       status_temp
    27.        movf        PCLATH          ; Saves value in register PCLATH
    28.        movwf       pclath_temp
    29.        
    30.      
    31.        
    32.        movf        pclath_temp,w   ; PCLATH is given its original content
    33.        movwf       PCLATH
    34.        movf        status_temp,w   ; STATUS is given its original content
    35.        movwf       STATUS
    36.        swapf       w_temp,f        ; W is given its original content
    37.        swapf       w_temp,w
    38.        
    39.        bsf         INTCON,GIE      ; Global interrupt enabled
    40.  
    41.        retfie                      ; Return from interrupt routine
    42.        
    43.  ;*********************************setup**********************************************      
    44. setup
    45.  banksel ANSEL
    46.    clrf ANSEL                           ;set PORTA as digital
    47.    clrf ANSELH  
    48.  banksel TRISA                            
    49.    bsf   TRISA, 0
    50.    bsf   TRISA, 1
    51.    bsf   TRISA, 2
    52.    bcf   TRISB, 7                  
    53.    bsf OSCCON,0                           ;make program clock internal
    54.    bcf OSCCON,6
    55.    bcf OSCCON,5
    56.    bcf OSCCON,4                           ;make frequncy 31Khz
    57.    clrf PORTD
    58.    clrf PORTC
    59.    clrf PORTB
    60. ;************************ MAIN PROGRAM *******************************************
    61. main                               ; Start of the main program
    62.  
    63.    btfsc PORTA, 0                    ;check to see if the C key is pressed
    64.    call noteC                        ;if so start note
    65.    
    66.    btfsc PORTA, 1                    ;check to see if the D key is pressed
    67.    call noteD                        ;if so start note
    68.      
    69.    btfsc PORTA, 2                    ;check to see if the E key is pressed
    70.    call noteE                        ;if so start note
    71.  
    72.    goto main
    73.  
    74.  
    75. ;*********************************subs**********************************
    76. noteC
    77.    banksel     OPTION_REG      ; Bank containing register OPTION_REG
    78.    bcf         OPTION_REG,T0CS ; TMR0 counts pulses from oscillator      
    79.    bcf         OPTION_REG,PSA  ; Prescaler is assign to timer TMR0
    80.        
    81.    bsf         OPTION_REG,PS0  ; Prescaler rate is 1:256
    82.    bsf         OPTION_REG,PS1
    83.    bsf         OPTION_REG,PS2
    84.  
    85.    banksel     INTCON          ; Bank containing register INTCON
    86.    bsf         INTCON,5     ; TMR0 interrupt overflow enabled
    87.    bsf         INTCON,GIE      ; Global interrupt enabled
    88.  
    89. Loop
    90.  
    91.    btfss       INTCON,2
    92.    goto $-1
    93.    bsf           PORTB, 7
    94.  
    95.    banksel     OPTION_REG      ; Bank containing register OPTION_REG
    96.    bcf         OPTION_REG,T0CS ; TMR0 counts pulses from oscillator      
    97.    bcf         OPTION_REG,PSA  ; Prescaler is assign to timer TMR0
    98.        
    99.    bsf         OPTION_REG,PS0  ; Prescaler rate is 1:256
    100.    bsf         OPTION_REG,PS1
    101.    bsf         OPTION_REG,PS2
    102.  
    103.    banksel     INTCON          ; Bank containing register INTCON
    104.    bsf         INTCON,5     ; TMR0 interrupt overflow enabled
    105.    bsf         INTCON,GIE      ; Global interrupt enabled
    106.  
    107.    btfsc       INTCON,2
    108.    goto $-1
    109.    bcf         PORTB, 7
    110.  
    111.    goto Loop
    112.  
    113.  
    114. noteD
    115.   banksel     OPTION_REG      ; Bank containing register OPTION_REG
    116.    bcf         OPTION_REG,T0CS ; TMR0 counts pulses from oscillator      
    117.    bcf         OPTION_REG,PSA  ; Prescaler is assign to timer TMR0
    118.        
    119.    bcf         OPTION_REG,PS0  ; Prescaler rate is 1:2
    120.    bcf         OPTION_REG,PS1
    121.    bcf         OPTION_REG,PS2
    122.  
    123.    banksel     INTCON          ; Bank containing register INTCON
    124.    bsf         INTCON,5   ; TMR0 interrupt overflow enabled
    125.    bsf         INTCON,GIE      ; Global interrupt enabled
    126.  
    127. Loop1
    128.  
    129.    btfss       INTCON,2
    130.    goto $-1
    131.    bsf           PORTB, 7
    132.  
    133.    banksel     OPTION_REG      ; Bank containing register OPTION_REG
    134.    bcf         OPTION_REG,T0CS ; TMR0 counts pulses from oscillator      
    135.    bcf         OPTION_REG,PSA  ; Prescaler is assign to timer TMR0
    136.        
    137.    bcf         OPTION_REG,PS0  ; Prescaler rate is 1:2
    138.    bcf         OPTION_REG,PS1
    139.    bcf         OPTION_REG,PS2
    140.  
    141.    banksel     INTCON          ; Bank containing register INTCON
    142.    bsf         INTCON,5   ; TMR0 interrupt overflow enabled
    143.    bsf         INTCON,GIE      ; Global interrupt enabled
    144.  
    145.    btfsc       INTCON,2
    146.    goto $-1
    147.    bcf         PORTB, 7
    148.  
    149.    goto Loop1
    150.  
    151.      
    152. noteE
    153.    banksel     OPTION_REG      ; Bank containing register OPTION_REG
    154.    bcf         OPTION_REG,T0CS ; TMR0 counts pulses from oscillator      
    155.    bcf         OPTION_REG,PSA  ; Prescaler is assign to timer TMR0
    156.        
    157.    bsf         OPTION_REG,PS0  ; Prescaler rate is 1:16
    158.    bsf         OPTION_REG,PS1
    159.    bcf         OPTION_REG,PS2
    160.  
    161.    banksel     INTCON          ; Bank containing register INTCON
    162.    bsf         INTCON,5   ; TMR0 interrupt overflow enabled
    163.    bsf         INTCON,GIE      ; Global interrupt enabled
    164.  
    165. Loop2
    166.  
    167.    btfss       INTCON,2
    168.    goto $-1
    169.    bsf           PORTB, 7
    170.  
    171.    banksel     OPTION_REG      ; Bank containing register OPTION_REG
    172.    bcf         OPTION_REG,T0CS ; TMR0 counts pulses from oscillator      
    173.    bcf         OPTION_REG,PSA  ; Prescaler is assign to timer TMR0
    174.        
    175.    bsf         OPTION_REG,PS0  ; Prescaler rate is 1:16
    176.    bsf         OPTION_REG,PS1
    177.    bcf         OPTION_REG,PS2
    178.  
    179.    banksel     INTCON          ; Bank containing register INTCON
    180.    bsf         INTCON,5   ; TMR0 interrupt overflow enabled
    181.    bsf         INTCON,GIE      ; Global interrupt enabled
    182.  
    183.    btfsc       INTCON,2
    184.    goto $-1
    185.    bcf         PORTB, 7
    186.  
    187.    goto Loop2
    188.  
    189.    return
    190.  
    191.   end                         ; End of program
    192.                                  
     
Loading...