Skip to content

Bug in adc_configure_trigger for Arduino Due #1819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
madrang opened this issue Jan 22, 2014 · 1 comment
Closed

Bug in adc_configure_trigger for Arduino Due #1819

madrang opened this issue Jan 22, 2014 · 1 comment
Assignees
Labels
Board: Arduino Due Applies only to the Due Component: Core Related to the code for the standard Arduino API

Comments

@madrang
Copy link
Contributor

madrang commented Jan 22, 2014

In https://github.com/arduino/Arduino/blob/ide-1.5.x/hardware/arduino/sam/system/libsam/source/adc.c

/**
 * \brief Configure conversion trigger and free run mode.
 *
 * \param p_adc Pointer to an ADC instance.
 * \param trigger Conversion trigger.
 * \param uc_freerun ADC_MR_FREERUN_ON enables freerun mode,
 * ADC_MR_FREERUN_OFF disables freerun mode.
 *
 */
void adc_configure_trigger(Adc *p_adc, const enum adc_trigger_t trigger,
                uint8_t uc_freerun)
{
        p_adc->ADC_MR |= trigger | ((uc_freerun << 7) & ADC_MR_FREERUN);
}

ADC_MR_FREERUN_ON == 0x80
ADC_MR_FREERUN_OFF == 0x00

Running the following on a due show the problem

  Serial.begin(115200);

  Serial.print("ADC->ADC_MR == ");
  Serial.println(ADC->ADC_MR);

  //Should enable FreeRun but it will not.
  adc_configure_trigger(ADC, ADC_TRIG_SW, ADC_MR_FREERUN_ON);

  Serial.print("ADC->ADC_MR == ");
  Serial.println(ADC->ADC_MR);

  //This call properly enables FreeRun
  ADC->ADC_MR |= ADC_MR_FREERUN_ON;      // DAC in free running mode.

  Serial.print("ADC->ADC_MR == ");
  Serial.println(ADC->ADC_MR);

  //This should disable FreeRun but it will not.
  adc_configure_trigger(ADC, ADC_TRIG_SW, ADC_MR_FREERUN_OFF);

  Serial.print("ADC->ADC_MR == ");
  Serial.println(ADC->ADC_MR);

Edit: Updated my sketch to include

  int ADCMR = ADC->ADC_MR;

  adc_configure_trigger(ADC, ADC_TRIG_SW, ADC_MR_FREERUN_ON); // DAC in free running mode.

  //Temporary bug fix
  if(ADCMR == ADC->ADC_MR) {
    Serial.println("Bug with adc_configure_trigger, See https://github.com/arduino/Arduino/issues/1819 for more information.");
    ADC->ADC_MR |= ADC_MR_FREERUN_ON;  // DAC in free running mode.
  }
@facchinm
Copy link
Member

facchinm commented Jan 7, 2016

Solved by #3524

@facchinm facchinm closed this as completed Jan 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Board: Arduino Due Applies only to the Due Component: Core Related to the code for the standard Arduino API
Projects
None yet
Development

No branches or pull requests

4 participants