This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/MSP430FR2111: An example code for the comparator /assembly

Part Number: MSP430FR2111

Tool/software: TI C/C++ Compiler

Dear All,

I need a comparator example code  written in assembly. MCU is msp430fr2111.

  • The example code package has msp430fr211x_eCOMP_01.asm/.s43.
  • Hi Clemens,
    Sorry,I missed something.
    The code I need is waking up the MCU with a comparator interrupt.
  • The CPU automatically wakes up when an interrupt handler is to be executed.

    For how to configure the registers, see msp430fr211x_eCOMP_03.c. For how to write an interrupt handler, see msp430fr211x_WDT_01.asm/.s43.
  • Hi Clemens,

      • I wrote it with reference to this example code by assembly,but it can't be used.Can you help me to correct it?

      SetREF      mov.b   #PMMPW_H,&PMMCTL0_H      ; Unlock the PMM registers
                  bis.w   #INTREFEN,&PMMCTL2       ; Enable internal reference
      PollREF     bit.w   #REFGENRDY,&PMMCTL2      ; Poll till internal reference settles
                  jz      PollREF

                   mov.w   #CPPSEL0+CPNSEL1+CPNSEL2+CPPEN+CPNEN, &CPCTL0
                                                  ; Select C1 as input for V+ terminal
                                                  ; Select DAC as input for V- terminal
                                                  ; Enable eCOMP input
                  bis.w    #CPIIE + CPIE, &CPCTL1
                  bis.w    #CPDACREFS + CPDACEN, &CPDACCTL
                  bis.w    #0x2b, &CPDACDATA
                  bis.w    #CPEN, &CPCTL1
      sleep   
                  clr.w    &CPINT
                  nop
                  bis.w    #LPM3 + GIE, SR    
                  nop
                  jmp    sleep
                  
                  
                  
                  
                  
      ecomp_interrupt_service_function    ;
      Comparative interrupt function


      ;============================================
                  add.w    &CPIV,    PC
                  reti
                  jmp    wf1_interrupt_pending
                  jmp    wf2_interrupt_pending
                  
                  
      wf1_interrupt_pending
                  bis.b    #BIT2, &P1DIR
                  bic.b    #BIT0, &P2DIR                                                    ; Comparator output off
                  bic.b    #BIT2, &P1DIR
                  bis.w    #CPIE, &CPCTL1                                                    ; Close comparative interrupt
                  bic.w    #LPM3 + GIE, 0(SP)                                                ; Modify stack areas (wake up)
                  reti


      wf2_interrupt_pending
                  bis.b    #BIT2, &P1DIR
                  bic.b    #BIT0, &P2DIR                                                    ; Comparator output off
                  bic.b    #BIT2, &P1DIR
                  bis.w    #CPIE, &CPCTL1                                                    ; Close comparative interrupt
                  bic.w    #LPM3 + GIE, 0(SP)                                                ; Modify stack areas (wake up)
                  reti
                  
                  
                  
                  
      ;-------------------------------------------------------------------------------
                  COMMON  INTVEC                                                            ; Interrupt Vectors
      ;-------------------------------------------------------------------------------
                  ORG     RESET_VECTOR                                                    ; POR, ext. Reset
                  DW    RESET
                  
                  ORG     PORT1_VECTOR                                                    ; external interruption
                  DW    port1_interrupt_service_function
                  
                  ORG        ECOMP0_VECTOR                                                    ; Comparator interrupt
                  DW    ecomp_interrupt_service_function            
                  
                  
                 

  • What exactly do you mean with "it can't be used"?

    (I do not have this MCU.)

    (Please use the "Insert Code" function to insert code so that it is formatted properly.)

  • Hello Clemens,

    I mean this program doesn't do what I want.Could you please help me check if there are any mistakes

    8741.FR2111_ecomp_0.txt
    SetREF      mov.b   #PMMPW_H,&PMMCTL0_H      ; Unlock the PMM registers
                bis.w   #INTREFEN,&PMMCTL2       ; Enable internal reference
    PollREF     bit.w   #REFGENRDY,&PMMCTL2      ; Poll till internal reference settles
                jz      PollREF
    
                 mov.w   #CPPSEL0+CPNSEL1+CPNSEL2+CPPEN+CPNEN, &CPCTL0
                                                ; Select C1 as input for V+ terminal
                                                ; Select DAC as input for V- terminal
                                                ; Enable eCOMP input
                bis.w    #CPIIE + CPIE, &CPCTL1
                bis.w    #CPDACREFS + CPDACEN, &CPDACCTL
                bis.w    #0x2b, &CPDACDATA
                bis.w    #CPEN, &CPCTL1
    sleep   
                clr.w    &CPINT
                nop
                bis.w    #LPM3 + GIE, SR    
                nop
                jmp    sleep
                
                
                
                
                
    ecomp_interrupt_service_function    ;Comparative interrupt function
    
    
    ;============================================
                add.w    &CPIV,    PC
                reti
                jmp    wf1_interrupt_pending
                jmp    wf2_interrupt_pending
                
                
    wf1_interrupt_pending
                bis.b    #BIT2, &P1DIR
                bic.b    #BIT0, &P2DIR                                                    ; Comparator output off
                bic.b    #BIT2, &P1DIR
                bis.w    #CPIE, &CPCTL1                                                    ; Close comparative interrupt
                bic.w    #LPM3 + GIE, 0(SP)                                                ; Modify stack areas (wake up)
                reti
    
    
    wf2_interrupt_pending
                bis.b    #BIT2, &P1DIR
                bic.b    #BIT0, &P2DIR                                                    ; Comparator output off
                bic.b    #BIT2, &P1DIR
                bis.w    #CPIE, &CPCTL1                                                    ; Close comparative interrupt
                bic.w    #LPM3 + GIE, 0(SP)                                                ; Modify stack areas (wake up)
                reti
                
                
                
                
    ;-------------------------------------------------------------------------------
                COMMON  INTVEC                                                            ; Interrupt Vectors
    ;-------------------------------------------------------------------------------
                ORG     RESET_VECTOR                                                    ; POR, ext. Reset
                DW    RESET
                
                ORG     PORT1_VECTOR                                                    ; external interruption
                DW    port1_interrupt_service_function
                
                ORG        ECOMP0_VECTOR                                                    ; Comparator interrupt
                DW    ecomp_interrupt_service_function            

  • What exactly do you mean with "doesn't do what I want"? What exactly do you want it to do? What do you observe instead?
  • I've solved it,thanks for your help.

**Attention** This is a public forum