system
July 31, 2014, 12:46pm
1
Hello all,
Are there any analogue comparitors available on the Due? The examples online that I find don't seem aplicable to the Due's processor. I am looking through the data sheet, but working examples would be greatly appreciated if people have some!
Thanks,
Wesley.
I think DUE's ADC has comparator mode, look in the adc.h and adc.c
void adc_set_comparison_mode(Adc *p_adc, const uint8_t uc_mode);
uint32_t adc_get_comparison_mode(const Adc *p_adc);
void adc_set_comparison_window(Adc *p_adc, const uint16_t us_low_threshold,
const uint16_t us_high_threshold);
void adc_set_comparison_channel(Adc *p_adc, const enum adc_channel_num_t channel);
Section 44.7.9 to set interrupt on comparator, bit 26 - COMPE.
44.7.14 - setting EMR register.
Just an example, haven't use comparator yet, but here how you can wrap it up:
void adc_setup ()
{
pmc_enable_periph_clk(ID_ADC);
// adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST);
adc_init(ADC, SystemCoreClock, 21000000UL, ADC_STARTUP_FAST);
NVIC_EnableIRQ (ADC_IRQn); // enable ADC interrupt vector
adc_disable_all_channel(ADC);
adc_enable_interrupt(ADC, ADC_IER_RXBUFF); <<--- THIS SHOUD BE ADC_IER_COMPE
adc_set_bias_current(ADC, 0x01);
// adc_enable_tag(ADC);
adc_enable_channel(ADC, ADC_CHANNEL_7); // AN0
adc_enable_channel(ADC, ADC_CHANNEL_6); // AN1
adc_enable_channel(ADC, ADC_CHANNEL_5); // AN2
adc_enable_channel(ADC, ADC_CHANNEL_4); // AN3
adc_start(ADC);
}
void ADC_Handler (void)
{
if((adc_get_status(ADC) & ADC_ISR_RXBUFF) == ADC_ISR_RXBUFF) { <<-- AGAIN "COMPE"
// YOUR ACTION ON EVENT
}
}
system
July 31, 2014, 3:06pm
3
Thanks!
I've been scan reading the data sheet and beggining to recognise a few of the variables you've listed there.
Mighty steep learning curve for a python programmer but looks like the Due will make a cracking stepper driver...