Jump to content
43oh

Maybe add support for ADC hardware oversampling?


Recommended Posts

Adding hardware oversampling would be realy easy and would make it more easy use this feature with Energia

it's exacly the same as analogRead but you would need to add 

 

uint16_t analogRead(uint8_t pin) {
   _analogRead(pin,0);
}
 
uint16_t analogReadOverSample(uint8_t pin,uint8_t factor) {
   _analogRead(pin,factor);
}
 
uint16_t _analogRead(uint8_t pin,uint8_t factor) {
    uint8_t port = digitalPinToPort(pin);
    uint16_t value[1];
    uint32_t channel = digitalPinToADCIn(pin);
    if (channel == NOT_ON_ADC) { //invalid ADC pin
        return 0;
    }
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    ROM_GPIOPinTypeADC((uint32_t) portBASERegister(port), digitalPinToBitMask(pin));
    ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, channel | ADC_CTL_IE | ADC_CTL_END);
    ROM_ADCHardwareOversampleConfigure(ADC0_BASE,factor);
    ROM_ADCSequenceEnable(ADC0_BASE, 3);
 
    ROM_ADCIntClear(ADC0_BASE, 3);
    ROM_ADCProcessorTrigger(ADC0_BASE, 3);
    while(!ROM_ADCIntStatus(ADC0_BASE, 3, false)) {
    }
    ROM_ADCIntClear(ADC0_BASE, 3);
    ROM_ADCSequenceDataGet(ADC0_BASE, 3, (unsigned long*) value);
    return value[0];
 
}
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...