Part Number: LP-MSPM0L2228
Other Parts Discussed in Thread: MSPM0L2228, SYSCONFIG
Task: Evaluate a simple switch debouncing circuit as discussed in SCEA094 with MSPM0L2228's comparator module.


Issue: While trying to use the MSPM0L2228 VREF and COMP module, I am not able to get the comparator to trigger at my configured threshold voltage of 1.5 volts. Instead it triggers around 20 mVolts.
Test setup: Using a potentiometer to vary the voltage entering the COMP0_IN0- expecting to see LED toggle around 1.5 volts.
Below are my SysConfig settings for VREF and COMP:


Code snippets:
#include "ti_msp_dl_config.h"
#include <stdio.h>
/*
* DAC8 Reference Voltage in mV
* Adjust this value according to the external VREF voltage.
*/
#define COMP_INST_REF_VOLTAGE_mV (2500)
/*
* DAC8 static output voltage in mV.
* Adjust output as needed.
*/
#define COMP_INST_DAC8_OUTPUT_VOLTAGE_mV (1500)
volatile static uint32_t onCount = 0, offCount = 0;
int main(void)
{
uint32_t dacValue;
SYSCFG_DL_init();
/*
* Set output voltage:
* DAC value (8-bits) = DesiredOutputVoltage x 255
* -----------------------
* ReferenceVoltage
*/
dacValue =
(COMP_INST_DAC8_OUTPUT_VOLTAGE_mV * 255) / COMP_INST_REF_VOLTAGE_mV;
DL_COMP_setDACCode0(COMP_INST, dacValue);
DL_COMP_enable(COMP_INST);
NVIC_EnableIRQ(COMP_INST_INT_IRQN);
/* Calling WFI after calling DL_SYSCTL_enableSleepOnExit will result in
* only ISR code to be executed. This is done to showcase the device's
* low power consumption when sleeping.
*/
//DL_SYSCTL_enableSleepOnExit();
while (1) {
//__WFI();
// Add a busy wait so the CPU stays in RUN mode
for(volatile int i=0; i<10000000; i++);
uint32_t status = DL_VREF_getStatus(VREF);
printf("Status = %d | OnCount = %d | OffCount = %d\n", status, onCount, offCount);
}
}
void GROUP1_IRQHandler(void)
{
switch (DL_COMP_getPendingInterrupt(COMP_INST)) {
case DL_COMP_IIDX_OUTPUT_EDGE:
DL_GPIO_clearPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN);
offCount++;
break;
case DL_COMP_IIDX_OUTPUT_EDGE_INV:
DL_GPIO_setPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN);
onCount++;
break;
default:
break;
}
}
Questions:
- Whenever I select "Enable VREF as internal reference for COMP", the project fails to build. Why?
- Is there a way to test the VREF voltage through a pin or through the onboard ADC12?
Any guidance on the matter would be appreciated.