Hi,
I'm having trouble with all analog functions in my xmega 128a1.
I've set up the DAC example in the documentation for the sine wave output to DACB. I had to add to the main:
#include#include #include
I've got a ETT XMEGA board. Other functions are OK in my full application -- serial, timers, interrupts -- but not the analog stuff in my real application. So I've fallen back to almost the simplest code I can have to try to get the sine wave going just to see it work.
The entire program:
#include#include #include #include #define SPEAKER_DAC DACA #define SPEAKER_DAC_CHANNEL DAC_CH0 #define RATE_OF_CONVERSION 22050 #define NR_OF_SAMPLES 32 static const uint16_t sine[NR_OF_SAMPLES] = { 32768, 35325, 37784, 40050, 42036, 43666, 44877, 45623, 45875, 45623, 44877, 43666, 42036, 40050, 37784, 35325, 32768, 30211, 27752, 25486, 23500, 21870, 20659, 19913, 19661, 19913, 20659, 21870, 23500, 25486, 27752, 30211, }; void evsys_init(void); void evsys_init(void) { sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_EVSYS); EVSYS.CH3MUX = EVSYS_CHMUX_TCC0_OVF_gc; } void tc_init(void); void tc_init(void) { tc_enable(&TCC0); tc_set_wgm(&TCC0, TC_WG_NORMAL); tc_write_period(&TCC0, (sysclk_get_per_hz() / RATE_OF_CONVERSION) - 1); tc_write_clock_source(&TCC0, TC_CLKSEL_DIV1_gc); } void dac_init(void); void dac_init(void) { struct dac_config conf; dac_read_configuration(&SPEAKER_DAC, &conf); dac_set_conversion_parameters(&conf, DAC_REF_AVCC, DAC_ADJ_LEFT); dac_set_active_channel(&conf, SPEAKER_DAC_CHANNEL, 0); dac_set_conversion_trigger(&conf, SPEAKER_DAC_CHANNEL, 0); #ifdef XMEGA_DAC_VERSION_1 dac_set_conversion_interval(&conf, 1); #endif dac_write_configuration(&SPEAKER_DAC, &conf); dac_enable(&SPEAKER_DAC); } int main(void) { sysclk_init(); evsys_init(); tc_init(); dac_init(); uint8_t i = 0; while (1) { dac_wait_for_channel_ready(&SPEAKER_DAC, SPEAKER_DAC_CHANNEL); dac_set_channel_value(&SPEAKER_DAC, SPEAKER_DAC_CHANNEL, sine[i]); i++; i %= NR_OF_SAMPLES; } }
Should this work pretty much as is? If not, what's missing?
Thanks,
madGambol