I have used this code to successfully acquire the audio from a 2-wire intercom system and played it back using a audio amplifier.
Now on the same 2-wire system there is data present too, which again acquired( on A0 using ADC) using this code and shown on the oscilloscope at DAC output.
Now I would like to show the received data onto serial port ?
DACC->DACC_MR =
DACC_MR_TRGEN_EN | DACC_MR_TRGSEL (1) | // trigger 1 = TIO output of TC0
(0 << DACC_MR_USER_SEL_Pos) | // select channel 0
DACC_MR_REFRESH (0x0F) | // bit of a guess... I'm assuming refresh not needed at 48kHz
(24 << DACC_MR_STARTUP_Pos) ; // 24 = 1536 cycles which I think is in range 23..45us since DAC clock = 42MHz
The DAC peripheral is much faster than the ADC peripheral:
Sam3x datasheet, Page 1403: Max ADC sampling frequency = 1 MHz
Sam3x datasheet, Page 1411: Max DAC sampling frequency = 2 MHz
BTW, to sample from one of the builtin ADC channels and output from one of the builtin DAC channels, the best option is to make use of the PDC DMA to divide by the buffer size the total number of interruptions
pmc_enable_periph_clk (TC_INTERFACE_ID + 0*3+0) ; // clock the TC0 channel 0
TcChannel * t = &(TC0->TC_CHANNEL)[0] ; // pointer to TC0 registers for its channel 0
t->TC_CCR = TC_CCR_CLKDIS ; // disable internal clocking while setup regs
t->TC_IDR = 0xFFFFFFFF ; // disable interrupts
t->TC_SR ; // read int status reg to clear pending
t->TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1 | // use TCLK1 (prescale by 2, = 42MHz)
TC_CMR_WAVE | // waveform mode
TC_CMR_WAVSEL_UP_RC | // count-up PWM using RC as threshold
TC_CMR_EEVT_XC0 | // Set external events from XC0 (this setup TIOB as output)
TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_CLEAR |
TC_CMR_BCPB_CLEAR | TC_CMR_BCPC_CLEAR ;
t->TC_RC = 875 ; // counter resets on RC, so sets period in terms of 42MHz clock
t->TC_RA = 440 ; //why 440???
t->TC_CMR = (t->TC_CMR & 0xFFF0FFFF) | TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_SET ; // set clear and set from RA and RC compares
t->TC_CCR = TC_CCR_CLKEN | TC_CCR_SWTRG ; // re-enable local clocking and switch to hardware trigger source.
I am trying to output a 60Hz sinewave via a DMA. Would anyone be able to explain why TC_RA is set to 440?
In the attached code I have a 2000 point sinewave (I know it could have less points) I set TC_RC to 350 because the dac should output at a frequency of n*"desired hz"
However, when I ran the code with RA at 440 the dac did not output anything, when I changed RA to 110 the DAC began to output.
BTW, there is an interrupt after each and every conversion ( 1000 times per second). A more rational sampling method would be to fill a sampling buffer (e.g. 128 values), output this buffer thru a DAC while continuously sampling to fill another buffer with a PDC DMA thus dividing interrupts by a 128 scale.
thank you for your reply, i did not saw the inversion, think i was tired.
About the other sketch, do you think it is really better, because this one works good and i only need a sampling frequency of 1k and the input is a sinewave of 100hz, i have the feeling that i can works with that sketch, no ?
Sampling a 100 Hz sinwave at a frequency of 1000 Hz is not a good idea (10 points per period is a bit weak). You won't see a nice sinewave output from the DAC.