SPRADL9 February 2025 CC1310
The following describes ADC code implementation in the Sensor Controller Studio.
Start with configuring the needed data structures and task resources:
Data structures:
Task resources:
Initialization Code:
//Select SAR ADC input pin compaSelectGpioInput(AUXIO_A_PIN_ANALOG); fwScheduleTask(1);Execution Code:
//Enable comparator compaEnable(COMPA_PWRMODE_ANY);
state.nextVal = 0x0080; // 1/2 VDD
output.value = 0; //Set the reference DAC output to 1/2 VDD refdacStartOutputOnCompaRef(state.nextVal); refdacEnable(REFDAC_PWRMODE_ANY,REFDAC_REF_VDDS);
U16 currBit = cfg.resolution;
U16 step = 64;
while(currBit > 0){ //Update DAC value refdacChangeOutputValue(state.nextVal); //Wait for DAC to stabilize...
//An additional slight delay for DAC and comparator to stabilize...
refdacWaitForStableOutput();
fwDelayUs(10); //Read comparator output compaGetOutput(state.isLarger); if(state.isLarger == 1){
state.nextVal += step; //Increase DAC value for next iteration
}
else{
state.nextVal -= step; //Decrease DAC value for next iteration
}
step >>= 1; //Divide step by 2
currBit -= 1;
//Update output value
output.value |= (state.isLarger << currBit);
}
refdacStopOutput();
compaSelectIntRef(COMPA_REF_VSS); //Disable peripherals
refdacDisable();
compaDisable();
fwScheduleTask(1);Termination Code:
//Disable peripherals
refdacDisable();
compaDisable();