Closed
Description
if i understand correctly we can only do a sync analog read at the moment ?
this has a problem of being super slow and wasting many cpu cycles ...
i tried to split analogRead into 3 functions .... analogReadAsync, analogReadAsyncReady and analogReadAsyncGet :
void IRAM_ATTR __analogReadAsync(uint8_t pin)
{
int8_t channel = digitalPinToAnalogChannel(pin);
SET_PERI_REG_BITS(SENS_SAR_MEAS_START1_REG, SENS_SAR1_EN_PAD, (1 << channel), SENS_SAR1_EN_PAD_S);
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_SAR_M);
SET_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_SAR_M);
}
bool IRAM_ATTR __analogReadAsyncReady()
{
return (GET_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_DONE_SAR) != 0);
}
uint16_t IRAM_ATTR __analogReadAsyncGet()
{
return GET_PERI_REG_BITS2(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_DATA_SAR, SENS_MEAS1_DATA_SAR_S);
}
and then use it like:
analogAsyncRead(34);
if (analogReadAsyncReady) myvalue = analogReadAsyncGet();
however this is far from perfect and could be implemented better i guess.
also is there an Interrupt i could set to be fired when adc reading is done ? or something like free running mode on atmega chips ? can i somehow change clock freq to make it faster (and less precise i guess) ?