Hi there,
I am using an arduino DUE, and I would like to "Arm" its DAC using a hardware trigger. My use case would be that the arduino receives a trigger from a clock which runs the rest of the setup. As soon as it receives it, it changes the output voltage of the DAC according to some precalculated value. The clock has a period of 9 us, so we have some time to waste, but not that much time.
The most simple way would be to connect an interrupt to a trigger input pin, and then change the output, but that leads to quite some jitter on the output port, so I hope that setting up the hardware properly will make it more stable.
The datasheet seems to suggest that it may be possible to use an external trigger (https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-11057-32-bit-Cortex-M3-Microcontroller-SAM3X-SAM3A_Datasheet.pdf, page 5)
According to the pinout, the DA trigger it should be accessible under pin D19 (https://docs.arduino.cc/resources/pinouts/A000056-full-pinout.pdf, in the "advanced" section, page 5)
I am guessing it would be a small adoption from this code, (thank you @anatolyk69_gmail.c ), but I don't understand what to change here:
void TC_setup ()
{
pmc_enable_periph_clk(TC_INTERFACE_ID + 0 *3 + 0);
TcChannel * t = &(TC0->TC_CHANNEL)[0];
t->TC_CCR = TC_CCR_CLKDIS;
t->TC_IDR = 0xFFFFFFFF;
t->TC_SR;
t->TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1 |
TC_CMR_WAVE |
TC_CMR_WAVSEL_UP_RC |
TC_CMR_EEVT_XC0 |
TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_CLEAR |
TC_CMR_BCPB_CLEAR | TC_CMR_BCPC_CLEAR;
t->TC_RC = freq_intc;
t->TC_RA = freq_intc /2;
t->TC_CMR = (t->TC_CMR & 0xFFF0FFFF) | TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_SET;
t->TC_CCR = TC_CCR_CLKEN | TC_CCR_SWTRG;
}
void dac_setup ()
{
pmc_enable_periph_clk (DACC_INTERFACE_ID) ; // start clocking DAC
dacc_reset(DACC);
dacc_set_transfer_mode(DACC, 0);
dacc_set_power_save(DACC, 0, 0);
dacc_set_trigger(DACC, 1); /* PROBABLY HERE, but what should I do? */
dacc_set_channel_selection(DACC, 1);
dacc_enable_channel(DACC, 1);
dacc_set_analog_control(DACC, DACC_ACR_IBCTLCH0(0x02) | DACC_ACR_IBCTLCH1(0x02) | DACC_ACR_IBCTLDACCORE(0x01));
NVIC_DisableIRQ(DACC_IRQn);
NVIC_ClearPendingIRQ(DACC_IRQn);
}
Would anyone be able to point out how do do this?
If it's unclear what I would like to do, I can also make a small sketch.
kind regards,
Dirk