Pages: [1]   Go Down
Author Topic: Arduino DUE DAC library  (Read 5621 times)
0 Members and 1 Guest are viewing this topic.
USA
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Don't fix it if it's broken
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was wondering if there was an arduino DAC library upcoming, that is under development?
Logged

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 21
Posts: 1670
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There is an Arduino DAC library under the Audio folder, its used by the Audio library.

..\Hardware\Arduino\SAM\Libraries\Audio\Dac.h

The library is geared towards buffered output, i.e. audio playback from a buffer using an interrupt to push new values from the buffer at a regular interval.

For direct access to the DAC use analogWrite(DAC0,ulValue); this will give you an output range of 0-255.

In the quick and dirty synth I have used analogWrite to set up the DAC, but then use

dacc_write_conversion_data(DACC_INTERFACE, ulOutput);

To write the output directly using 12 bit resolution rather than the 8 bit resolution provided by analogWrite

Duane B

rcarduino.blogspot.com
Logged


USA
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Don't fix it if it's broken
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Guys thanks for the help, I was wondering if there was an easy way to produce sine waves,triangle waves, etc.
Logged

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 21
Posts: 1670
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No, there is not, you have to use Direct Digital Synthesis to generate them, this project generates two ramp waveforms using DDS -

http://rcarduino.blogspot.com/2012/11/quick-and-dirty-synth-for-arduino-due.html

Out of interest, what do you want the waveforms for ? Generating them at 44.1Khz takes quite a lot of the processor time, generating them at 8Khz gives a much lower quality but takes very little processor time.

Duane B

rcarduino.blogspot.com
Logged


Dubai, UAE
Offline Offline
Edison Member
*
Karma: 21
Posts: 1670
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here you go, total overkill - a post on Arduino Due DDS including a sample sketch for a sinewave with frequency controlled by a pot on analog pin 0.

http://rcarduino.blogspot.com/2012/12/arduino-due-dds-part-1-sinewaves-and.html

Duane B

rcarduino.blogspot.com
Logged


Dubai, UAE
Offline Offline
Edison Member
*
Karma: 21
Posts: 1670
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Looking at the assembly, the ISR is around 30 instructions, so accounting for some over head outside the ISR, generating a sinewave at a 44.1Khz sample rate is using around 2% of the Arduino Due processing time. Its huge improvement over the UNO which would really struggle with 44.1Khz. A lot of the improvement is due to the Due being able to operate on 32 bits at a time, the UNO needs 4 cycles to process 32 bits. Add the faster processor clock and the Due is cruising.

Not much happening here -
Code:
00080198 <TC4_Handler>:
   80198: 2101      movs r1, #1
   8019a: b510      push {r4, lr}
   8019c: 480c      ldr r0, [pc, #48] ; (801d0 <TC4_Handler+0x38>)
   8019e: f000 f9a3 bl 804e8 <TC_GetStatus>
   801a2: 4b0c      ldr r3, [pc, #48] ; (801d4 <TC4_Handler+0x3c>)
   801a4: 6819      ldr r1, [r3, #0]
   801a6: 4b0c      ldr r3, [pc, #48] ; (801d8 <TC4_Handler+0x40>)
   801a8: 681a      ldr r2, [r3, #0]
   801aa: 188a      adds r2, r1, r2
   801ac: f1b2 5f16 cmp.w r2, #629145600 ; 0x25800000
   801b0: 601a      str r2, [r3, #0]
   801b2: d901      bls.n 801b8 <TC4_Handler+0x20>
   801b4: 2200      movs r2, #0
   801b6: 601a      str r2, [r3, #0]
   801b8: 4b07      ldr r3, [pc, #28] ; (801d8 <TC4_Handler+0x40>)
   801ba: 4808      ldr r0, [pc, #32] ; (801dc <TC4_Handler+0x44>)
   801bc: 681a      ldr r2, [r3, #0]
   801be: 4b08      ldr r3, [pc, #32] ; (801e0 <TC4_Handler+0x48>)
   801c0: 0d12      lsrs r2, r2, #20
   801c2: f833 1012 ldrh.w r1, [r3, r2, lsl #1]
   801c6: e8bd 4010 ldmia.w sp!, {r4, lr}
   801ca: f000 b9e6 b.w 8059a <dacc_write_conversion_data>
   801ce: bf00      nop
   801d0: 40084000 .word 0x40084000
   801d4: 20070564 .word 0x20070564
   801d8: 20070568 .word 0x20070568
   801dc: 400c8000 .word 0x400c8000
   801e0: 2007076c .word 0x2007076c

Assembly generated using -
http://rcarduino.blogspot.com/2012/09/how-to-view-arduino-assembly.html

Duane B
Logged


Pages: [1]   Go Up
Jump to: