1

I have a problem with a ATSAM4S ADC unit triggered by Timer 0 (channel 1). It seems that the ADC is triggered as fast as possible and blocks my whole application (OS is no longer operational due to this). I want an AD conversion with 1 Hz. This is my code:

sysclk_enable_peripheral_clock(ID_TC1);
uint32_t ul_div = 0;
uint32_t ul_tc_clks = 0;
uint32_t ul_sysclk = sysclk_get_cpu_hz();
tc_find_mck_divisor(1, ul_sysclk, &ul_div, &ul_tc_clks, ul_sysclk);
// Init timer clock 0 channel 1 with the found timings and set up counter 
which resets/clears on reaching the target
tc_init(TC0, 1, 
ul_tc_clks|TC_CMR_WAVE|TC_CMR_WAVSEL_UP_RC|TC_CMR_ACPA_CLEAR|
TC_CMR_ACPC_SET);
tc_write_rc(TC0, 1, (ul_sysclk / ul_div));
tc_write_ra(TC0, 1, (ul_sysclk / ul_div) / 2);  
sysclk_enable_peripheral_clock(ID_ADC);
adc_init(ADC, sysclk_get_cpu_hz(), 6400000, ADC_MR_STARTUP_SUT512);
adc_configure_timing(ADC, 0, ADC_MR_SETTLING_AST9, 2);
adc_set_resolution(ADC, ADC_MR_LOWRES_BITS_12);
adc_enable_tag(ADC);
NVIC_SetPriority((IRQn_Type)ADC_IRQn, 171);
NVIC_EnableIRQ(ADC_IRQn)
tc_start(TC0, 1);
adc_enable_channel(ADC, ADC_CHANNEL_0);
adc_enable_channel(ADC, ADC_TEMPERATURE_SENSOR);
adc_enable_ts(ADC);
adc_enable_interrupt(ADC, ADC_IER_DRDY);
adc_configure_trigger(ADC, ADC_TRIG_TIO_CH_1, 0);

Does anybody knwo what I did wrong? I tested it using a Xplained Pro board (with debugging and onboard LED toggling). I always stayed inside the ADC driver and never left it. So my ADC rate is much too high, but tc_find_mck_divisor seems to return resonable values for 1Hz.

Thanks!

user1995621
  • 47
  • 3
  • 9

0 Answers0