Jump to content
Sign in to follow this  
alanaxis

msp430: how to wait one second in assembly?

Recommended Posts

New to msp430. I trying to make it buzz a tone through a piezo speaker I have plugged into 1.4. I want it to change pitch a few times but can't figure out to control the duration. How can I make the tone hold for one sec before incrementing?  Here's the code I've written so far. I'm trying to do the increment in a loop. 

 

 

 

#include "msp430.h"                     ; #define controlled include file

        NAME    main                    ; module name

        PUBLIC  main                    ; make the main label vissible
                                        ; outside this module
        ORG     0FFFEh
        DC16    init                    ; set reset vector to 'init' label

        RSEG    CSTACK                  ; pre-declaration of segment
        
        ;define all notes as global constants
        

        
        RSEG    CODE                    ; place program in 'CODE' segment

init:   MOV     #SFE(CSTACK), SP        ; set up stack

main:   NOP                             ; main program
        MOV.W   #WDTPW+WDTHOLD,&WDTCTL  ; Stop watchdog timer
        BIS.B   #LFXT1S_2, &BCSCTL3     ; enable Very Low Frequency Oscillator (VLO)mode
      
        BIC.B   #OFIFG, &IFG1           ; clear flags for IFG1
        BIS.W   #(SCG0+SCG1), SR        ; TURN OFF DCO, AND SMCLK
        BIS.B   #SELM_3, &BCSCTL2       ;SELECT VLO TO SOURCE MCLK
        MOV.W   #CCIE, &TACCTL0         ;
        MOV.W   #40, &TACCR0            ;
        MOV.W   #TASSEL_1+MC_1, &TACTL  ;
        
        BIS.B   #1h, &P1DIR
        BIS.B   #10h, &P1DIR            ; p1.4 ouT
        
;LOOP: 

        MOV.W   &TACCR0+10, &TACCR0        ;NEW PITCH
        jmp    LOOP ; Again   
    
  
                                                       ;DELAY ONE SECOND
        
            
  
       
            
                                         
        BIS.W   #CPUOFF+GIE,SR          ;CPU OFF, INTERRUPTS ENABLED
        JMP LOOP                                  ; jump to current location '$'
    
TA0_ISR: 
        XOR.B   #001h, &P1OUT
        XOR.B   #10h, &P1OUT
                                          ;NEED TO CLEAR FLAG
        RETI
        
        COMMON  INTVEC
        ORG     TIMER0_A0_VECTOR
        DW      TA0_ISR
        
                                        ; (endless loop)
        END

Share this post


Link to post
Share on other sites

thanks, I've been trying to do a second loop and can't seem to get it to work properly. I think the second timer option may be a bit outside my scope until i get a few more weeks of tinkering in.

Share this post


Link to post
Share on other sites

MOV.W   &TACCR0+10, &TACCR0        ;NEW PITCH

 

You cannot increment register values like this; what actually happens is that the CPU reads a register at another address.

 

As for your second loop: from what you have shown so far, I can deduce that it's missing

Share this post


Link to post
Share on other sites

thanks, i took the loop out just to make sure i could create a tone change. I feel like if I can get it to change once, then looping it afterwards shouldn't be that difficult. 

 

 

 

#include "msp430.h"                     ; #define controlled include file

     NAME    main                    ; module name

        PUBLIC  main                    ; make the main label vissible
                                        ; outside this module
        ORG     0FFFEh
        DC16    init                    ; set reset vector to 'init' label

        RSEG    CSTACK                  ; pre-declaration of segment
        
        ;define all notes as global constants
       

        
        RSEG    CODE                    ; place program in 'CODE' segment
DelayOneSecond:                         ; define branch target
        mov.w   #10000, R10
Cont:   nop
        dec   R10
        
     ;   br #FreqUp                      ; branch to freq if r10>10k   12kopsinasec
        jnz Cont                        ; branch to delay
        ret
        
init:   MOV     #SFE(CSTACK), SP        ; set up stack

main:   NOP                             ; main program
        MOV.W   #WDTPW+WDTHOLD,&WDTCTL  ; Stop watchdog timer
        BIS.B   #LFXT1S_2, &BCSCTL3     ; enable Very Low Frequency Oscillator (VLO)mode
      
        BIC.B   #OFIFG, &IFG1           ; clear flags for IFG1
        BIS.W   #(SCG0+SCG1), SR        ; TURN OFF DCO, AND SMCLK
        BIS.B   #SELM_3, &BCSCTL2       ;SELECT VLO TO SOURCE MCLK
        MOV.W   #CCIE, &TACCTL0         ;
        MOV.W   #40, &TACCR0            ;
        MOV.W   #TASSEL_1+MC_1, &TACTL  ;
       ; mov.w   #10000, R10                 ;prep counter
        BIS.B   #1h, &P1DIR
        BIS.B   #10h, &P1DIR            ; p1.4 ouT
        
        
        call #DelayOneSecond
              


        MOV.W   #80, &TACCR0        ;NEW PITCH
        
        call    #DelayOneSecond
        jmp    $   ; Again   
    
  
                                                       ;DELAY ONE SECOND
        
            
  
       
            
                                         
        BIS.W   #CPUOFF+GIE,SR          ;CPU OFF, INTERRUPTS ENABLED
        JMP  $                                 ; jump to current location '$'
    
TA0_ISR: 
        XOR.B   #001h, &P1OUT
        XOR.B   #10h, &P1OUT
                                          ;NEED TO CLEAR FLAG
        RETI
        
        COMMON  INTVEC
        ORG     TIMER0_A0_VECTOR
        DW      TA0_ISR
        
                                        ; (endless loop)
        END

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...