How to trigger DAC from TimerCounter?

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to use the SamvV71 DAC to generate a waveform at a specific frequency. I am using the ASF4 drivers but I can’t find a good example for the DAC.  I am setting up TC0 channel 1 to generate the frequency that will drive the DAC.

 

I am using the DAC_async_write() to point to send my waveform data to the DAC

 

It looks like I can set the DAC to trigger from TC0.   But what exactly does this mean? The outputs of TC0 are TIOA and TIOB. Does this mean I have to use TIOA or TIOB to trigger the DAC. Or do I have to trigger the DAC on TCO channel 1 overflow?

 

When I set DAC trigger to TC0, what exactly is the trigger from TC0?

 

Also, How do I know when the last byte of my 1K buffer has been written to the DAC?

Last Edited: Fri. Aug 14, 2020 - 01:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I did something similar as you plan with a SAME70. I assume the DACC is the same as in the SAMV71

I used the PWM event mechanism to trigger the DACC with a regular pattern. This helped me to save timer elements in the µC. Certainly that depends on your application design. If you need to use the timer I think the DACC is triggered each time the timer (TC0/1/2) has an overrun. So the timer period has to be equal to the DACC output period. Don't forget that the trigger starts the DACC and it will take another 14 DACC cycles until the value is visible at the output pin.

If the 1k buffer you mentioned contains already existing values at the beginning of your DACC activity, you can use XDMA to feed the DACC and get an interrupt at the end (and in the middle if necessary). There is also a counter in each XDMA channel that allows you to follow the data transfer.

If the values in the buffer are successively calculated while the DACC is already converting you can simply use a global variable that keeps track how many values are already converted. 

I didn't use XDMA in my application. So I'm not sure if it will work for a large buffer - on the other side I see no reason why not. I used the small buffer (2 values) inside the DACC. You can define an interrupt that is raised if this FIFO is empty. I used this interrupt to calculate two more and but them again into the buffer. In any case you should be able to use this interrupt and copy 2 values from your buffer into the DACC internal buffer. Be sure that this interrupt service routine has appropriate priority because if you run the DACC at full speed you have approx 300 µC cycles left to update the conversion data registers (assuming you run the µC at 300MHz). Inside this interrupt service routine you can use a static variable that is counting the number of elements that has been transferred from your 1k buffer to the DACC. So if the information about the number of elements that has been already been transferred shouldn't be available in your application globally, this might version is bit more elegant compared to the global variable.

 

Best Regards

Markus