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.

MSP430FR5994: Using a comparator to measure the time to hit a voltage range

Part Number: MSP430FR5994

Hello,

I am using the msp430fr5994, and I need help setting up the eCOMP. I am a student at North Carolina State University, and I have never used the eCOMP before. The project I am working on involves charging and discharging a makeshift 29 pF capacitor and measuring the time it takes to reach a certain voltage range. I am charging the capacitor up to 3.3 volts, then setting the pin direction low to allow it to discharge. I am trying to measure the time it takes to go from the start of the discharge to the voltage range between 1 and 1.1 volts. I have looked over the eCOMP registers in the user guide and there are quite a few I don't understand. Does anyone have an easy way to set up the eCOMP to check between 1 and 1.1 volts?

Thank you.

  • Hi Barry,

    You can start with the code example in the MSP430 driver library. These examples shows you the steps to configure the device and COMP to make it work.

    http://dev.ti.com/tirex/#/?link=Software%2FMSP430Ware%2FLibraries%2FDriver%20Library%2FMSP430FR5xx_6xx%2FExample%20Projects%2FCOMP_E%2FCOMP_E%2FCOMP_E

    Best regards,

    Jovi He

  • Hi Jovi,

    This was really helpful in setting up my code. I'm currently having some trouble working with the interrupt.

    I need the interrupt to execute two separate sequences. When my capacitor's voltage first hits the threshold (3.2V), I need the eCOMP_ISR to toggle the charging pin then reset the timer. I then need the eCOMP_ISR to trigger when it hits the low threshold (1.1V), and I need it to tell me how long it took (based off my counter) to discharge to that voltage.

    I believe that the conditions in the if-statements in the eCOMP_ISR are wrong. It seems to immediately enter the second if statement after exiting the first. The code for the interrupt is posted below. Can you check to see if the conditions are correct and point me in the right direction?

    #pragma vector=COMP_E_VECTOR
    __interrupt void COMP_E_ISR(void)
    {
    //Toggle the edge at which an interrupt is generated
    Comp_E_toggleInterruptEdgeDirection(COMP_E_BASE);

    //Clear Interrupt flag
    Comp_E_clearInterrupt(COMP_E_BASE, COMP_E_OUTPUT_INTERRUPT_FLAG);

    if(CECTL1&CEOUT){
    capCharged=1;
    salinityTimer=0;
    P8DIR &= ~IR_LED; //start capacitor discharge
    }

    if(!(CECTL1&CEOUT) && (capCharged==1)){
    salinityDischargeTime = salinityTimer;
    salinityFunctionDone=1;
    }

    //Toggle P3.5 output pin.
    GPIO_toggleOutputOnPin(GPIO_PORT_P3, GPIO_PIN5); //toggle output pin port 3 pin 5
    }

    Thanks,
    Barry
  • Barry,

    Please check the timing constant of the cap discharge and the MCU running speed. If the capacitor discharge time is few CPU cycles, then it will execute the second statement immediately.

    Best regards,

    Jovi He 

  • The capacitance is about 30 pF and the resistance is 5.1 Mohms. The time constant should be 153 microseconds. The microcontroller is using an 8 MHz clock. The discharge time is much greater than a few CPU cylces. Since you didn't mention the if-statement conditions, can I assume those are correct?
  • Hi Barry,

    What's the COMP reference voltage to compare in your circuit here? if it's 3.2V, then after the discharge instructions in the first if statement, the capacitor voltage is already lower than the COMP threshold. So the CEOUT will be low, and the second if-statement will be executed.

    Best regards,
    Jovi He

**Attention** This is a public forum