Hi,
I'm trying to configure a BIOS managed ADC interrupt, it seems to work but my adcResult is always returning 0 independently of the voltage on the pin.
Hwi Configuration:
var hwi0Params = new Hwi.Params(); hwi0Params.instance.name = "adcHwi"; Program.global.adcHwi = Hwi.create(40, "&Hwi_adc", hwi0Params);
ADC initialization:
Void Hwi_initADC() {
/* Initializing ADC (MCLK/64/8) */
MAP_ADC14_enableModule();
MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_64,
ADC_DIVIDER_8, ADC_NOROUTE);
MAP_ADC14_setResolution(ADC_14BIT);
/* Setting reference voltage to 2.5 */
MAP_REF_A_setReferenceVoltage(REF_A_VREF2_5V);
MAP_REF_A_enableReferenceVoltage();
/* Configuring GPIO (5.4 A1) */
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN4,
GPIO_TERTIARY_MODULE_FUNCTION);
/* Configuring ADC Memory */
MAP_ADC14_configureSingleSampleMode(ADC_MEM1, false);
MAP_ADC14_configureConversionMemory(ADC_MEM1, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A1, false);
/* Configuring Sample Timer */
MAP_ADC14_enableSampleTimer(ADC_MANUAL_ITERATION);
/* Enabling interrupts */
MAP_ADC14_enableInterrupt(ADC_INT1);
MAP_Interrupt_enableInterrupt(INT_ADC14);
MAP_Interrupt_enableMaster();
/* Enables conversion of ADC data */
MAP_ADC14_enableConversion();
/* Start conversion */
MAP_ADC14_toggleConversionTrigger();
}
ADC isr:
Void Hwi_adc() {
uint64_t status = MAP_ADC14_getEnabledInterruptStatus();
MAP_ADC14_clearInterruptFlag(status);
if (ADC_INT1 & status) {
uint16_t raw = MAP_ADC14_getResult(ADC_MEM1);
Mailbox_post(adcMail, &raw, BIOS_NO_WAIT);
MAP_ADC14_toggleConversionTrigger();
}
}
Task to print values:
Void Task_logger(UArg arg0, UArg arg1) {
uint16_t value;
while (1) {
Mailbox_pend(adcMail, &value, BIOS_WAIT_FOREVER);
System_printf("val: %d\n", value);
System_flush();
}
}
The program prints "val: 0" every time.