L.R.A 78 Posted June 16, 2014 Share Posted June 16, 2014 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]; } Automate 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.