Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
AtomicZombie
PostPosted: Jan 21, 2012 - 07:42 PM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

Greets,

Moving along, i am now messing with the XMega DAC. I seem to be getting what I expect out of PB2, but would appreciate it if an XMega guru could confirm that my settings are good. I set up the DAC like this...

Code:


; SET DAC FOR SINGLE CHANNEL
LDI r16,DAC_CHSEL_SINGLE_gc
STS DACB_CTRLB,r16

; SET DAC TO VCC REFERENCE
ldi r16,DAC_REFSEL_AVCC_gc
sts DACB_CTRLC,r16

; ENABLE DAC MODULE
ldi r16,DAC_CH0EN_bm | DAC_ENABLE_bm
sts DACB_CTRLA,R16



And for a test, am just ramping up a 16 bit value and sending it to the DAC...

Code:


; WRAP 16 BIT VALUE
adiw zl:zh,1

; WRITE DAC LO BYTE
sts DACB_CH0DATA,zl

; WRITE DAC HI BYTE
clr r18
sts DACB_CH0DATA+1,zh



On my scope, I get the expected triangular waveform with a clipped top (due to the lost 4 bits).

Is there any other DAC setting I should be concerned with, or did I decode the datasheet correctly on the first try?

Cheers,
Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
indianajones11
PostPosted: Jan 22, 2012 - 03:05 AM
Raving lunatic


Joined: Nov 28, 2004
Posts: 3552
Location: San Diego, Ca

Be aware of the DACB.TIMCTRL register,when the time is right . Your code looks correct to me, otherwise .

_________________
1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1
 
 View user's profile Send private message  
Reply with quote Back to top
AtomicZombie
PostPosted: Jan 22, 2012 - 04:25 PM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

indianajones11 wrote:
Be aware of the DACB.TIMCTRL register,when the time is right . Your code looks correct to me, otherwise .


I was looking at that REG, but it seems to be for only dual ended operation. At least, that's what I understood from the datasheet.

Since I am only using single ended operation, would it be of any use in my program?

I intend to mix 4 8 bit values and then send them to a single channel.

Cheers,
Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
indianajones11
PostPosted: Jan 22, 2012 - 08:16 PM
Raving lunatic


Joined: Nov 28, 2004
Posts: 3552
Location: San Diego, Ca

Quote:
I was looking at that REG, but it seems to be for only dual ended operation. At least, that's what I understood from the datasheet.
It's for both modes .

Quote:
Since I am only using single ended operation, would it be of any use in my program ?
So long as the settings are proper it's ok, but it can have an impact and it has a timing requirement ( See Man. A pg 322 again ) . If the conversion interval's too short/long, it WILL distort a waveform ( data pts. will be put in the wrong place, in time ), at high enough freq.

For your DAC code, you're not checking to see if the DAC result register's empty before sending a new value .

_________________
1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1
 
 View user's profile Send private message  
Reply with quote Back to top
AtomicZombie
PostPosted: Jan 23, 2012 - 03:55 PM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

Interesting. Never considered a "too long" issue on a DAC. I am used to using a passive R2R DAC where the only issue is "too short" or too much noise.

I will have to dig deeper to understand this. Currently, I am just spewing bytes to the high register of the DAC in a timer interrupt set to fire at 10KHz. The main loop changes 8 bytes and then the interrupt sums them and sends them out. Maybe this solves the timing issues for me?


Another thing I noted is that the XMega DAC is so much more noisy than any of my R2R breadboard DACs. These is so much background noise that I can actually hear it on my audio amp.

Odd considering my breadboard R2R DAC makes a perfect sample with detectible noise output.

Either I have set something up incorrectly, or the DAC is just too low quality for even 8 bit audio.

Will be doing more tests tonight.

Thanks again,
Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
angelu
PostPosted: Jan 23, 2012 - 04:52 PM
Resident


Joined: May 28, 2006
Posts: 716
Location: Toronto, Canada

Quote:
These is so much background noise that I can actually hear it on my audio amp.

I noticed it as well.
George.

_________________
www.sofgel.ro bootloader for mega and xmega
www.elsofgel.com XME development board
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
AtomicZombie
PostPosted: Jan 23, 2012 - 06:05 PM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

angelu wrote:
Quote:
These is so much background noise that I can actually hear it on my audio amp.

I noticed it as well.
George.



Hmm.... not good! Oh well, these packages are not lacking in pins, so it isn't a big deal to bolt on an 8 or 12 bit R2R DAC. Sending a bit to the R2R port costs the same number of cycles as does setting the internal DAC, so maybe I will just go back to my original method.

I just set up a simple DDS using a 256 byte SIN wave, and the output is "not bad" from the XMega DAC, but not as good as a basic R2R DAC hacked to a breadboard with spaghetti wiring.

Strange that a breadboard full of 10k and 20k through hole resistors running to a port through 6 inch long wires would give a much cleaner signal that the DAC built into the XMega!

Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
indianajones11
PostPosted: Jan 23, 2012 - 08:23 PM
Raving lunatic


Joined: Nov 28, 2004
Posts: 3552
Location: San Diego, Ca

Quote:
Strange that a breadboard full of 10k and 20k through hole resistors running to a port through 6 inch long wires would give a much cleaner signal that the DAC built into the XMega!
That's really bad, then . Have either of you been able to measure how big a noise signal it is ?

Quote:
Maybe this solves the timing issues for me?
Set the conv_interval bits to max. value and see if your signal distorts because of it .

_________________
1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1
 
 View user's profile Send private message  
Reply with quote Back to top
AtomicZombie
PostPosted: Jan 23, 2012 - 08:25 PM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

I am redoing my 8 voice DDS mixer and will post photos later of both the internal DAC as compared to my R2R DAC.

You can really see the noise in the SIN waveform.

Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
AtomicZombie
PostPosted: Jan 23, 2012 - 08:59 PM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

Ok, here are some shots of the DAC running on the XMega256A3. i am using a fresh set of alkaline AA batteries and the internal 32 MHz clock. The DAC is being pumped with a 256 byte SIN wave and my routine is 100% cycle counted and balanced.


At low frequency, the output is not too bad.


As the frequency increases, so does the ugliness!


Really close up. Could this be the clock source making the noise? With a fresh DC source and decoupling, I would not expect that.

When I go back to spewing the bytes out to a breadboard R2R DAC, the noise all but disappears.

So dude, what's up here?

Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
indianajones11
PostPosted: Jan 24, 2012 - 12:23 AM
Raving lunatic


Joined: Nov 28, 2004
Posts: 3552
Location: San Diego, Ca

What are the 2 frequencies you used for both cases ? 256 byte table... they must be LOW frequencies, huh ? I used 20 byte and got 50 KHz Max using a timer ISR in C ( 25 KHz with 40 byte table ) . When I ran the 20 byte version "raw" in a tight loop, it was close to 100KHZ, IIRC . Both tables were uint16_t .

Mine looked good as far as I could tell, but my 'scope is analog with a BW of only 15 MHz ! Maybe it's a low enough quality DAC after all . Maybe tickling those bits I mentioned may help... Does it look as bad using a smaller table ?
Quote:
Could this be the clock source making the noise?
Maybe, the noise has a "regular" pattern to it, probably at every write of a byte from the way it looks ( just guessing ) .

_________________
1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1
 
 View user's profile Send private message  
Reply with quote Back to top
AtomicZombie
PostPosted: Jan 24, 2012 - 02:23 AM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

I will try the other registers as soon as I sort out my current problem.

I now have two 8 bit values (r16 and r17) and I am trying to add them together and send them to the DAC in 12 bit mode (right justified).

Seems easy enough since the max value of the addition will be only 9 bits. I though this would send the low byte and MSB bit (remainder R1), but my math must be all wrong...

Code:


;ADD TO GET 9 BIT VALUE
clr r0
clr r1
add r16,r17

; WRITE 9 BIT DATA TO DAC (RIGHT JUSTIFIED)
sts DACB_CH0DATA,r16
sts DACB_CH0DATA+1,r1



Maybe my understanding of adding two 8 bit values into a 9 bit value is bogus. I am getting something out of the DAC, but it is damn ugly!

I can add the two 8 bit values and toss the result for 8 bit mode and that seems to work, but I eventually want to add 8 registers and send out an 11 bit value to the dac.

This works, but only gives 8 bits...


Code:


add r16,r17

; WRITE 8 BIT DATA TO DAC (LEFT JUSTIFIED)
sts DACB_CH0DATA+1,r1



Sometimes the most basic things put the brakes on. This time 8bit+8bit=9bit

Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
angelu
PostPosted: Jan 24, 2012 - 02:38 AM
Resident


Joined: May 28, 2006
Posts: 716
Location: Toronto, Canada

What r1 has to do here ?
George.

_________________
www.sofgel.ro bootloader for mega and xmega
www.elsofgel.com XME development board
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
indianajones11
PostPosted: Jan 24, 2012 - 02:51 AM
Raving lunatic


Joined: Nov 28, 2004
Posts: 3552
Location: San Diego, Ca

Quote:
What r1 has to do here ?
Yeah, neither of those codes is right as far as r1 . Wouldn't you set LSB of r1 depending on if C bit is set ?

_________________
1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1
 
 View user's profile Send private message  
Reply with quote Back to top
angelu
PostPosted: Jan 24, 2012 - 03:03 AM
Resident


Joined: May 28, 2006
Posts: 716
Location: Toronto, Canada

Code:
clr r1
add r16, r17
adc r1, r1 ; r1: MSB, r16: LSB

George.

_________________
www.sofgel.ro bootloader for mega and xmega
www.elsofgel.com XME development board
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
AtomicZombie
PostPosted: Jan 24, 2012 - 03:27 AM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

angelu wrote:
Code:
clr r1
add r16, r17
adc r1, r1 ; r1: MSB, r16: LSB

George.


Thanks, that's what I eventually came to as well. I had multiplication on the brain or something.

After some tests, the mixing is not so good. I am now trying a system where each voice routine sends its data to the DAC in succession, creating a kind of pseudo mixer, sharing time with the DAC. This worked very well in a previous project, producing a perfect 8 channel mix into an 8 bit DAC with zero loss.

Will report back again!

Cheers,
Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
AtomicZombie
PostPosted: Jan 24, 2012 - 09:54 AM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

Interesting... you can use the same HEX file on any XMega as long as memory mappings satisfy the smaller part. I did not have a board for my 164A, so I just used the include for it and am testing my code on the 256A.

If anyone happens to have an XMega with the DAC pin (PB2) connected to an audio amp or speaker, drop this HEX file in and listen to the sound of 4 voices with ASD sharing time on the DAC.

The program runs on the internal 32MHz OSC and only requires PB2 to be connected to an audio source.

www.lucidscience.com/temp/Sound.hex

This is the beginning of my 8 voice sound system, which will be one of the support chips on a new XMega game system. The sound processor will have a 4 voice system like the C64 plus 2 white noise channels and 2 digital sample channels.

The test program in the HEX file just plays 4 random notes using the attack/sustain/decay envelope generator. The voices are also set to SIN,SAW,TRI, and SQR wave shapes.

Instead of wasting cycles mixing 8 channels in code and then killing the amplitude, I split the time between each voice equally, so they hurl their respective bytes out to the DAC in succession at about 30 killohertz. This creates a perfect mix without sacrificing any bits in the addition and division process of mathematically mixing samples.

I am enjoying the XMega learning curve, but all those damn registers!....

Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
DocJC
PostPosted: Feb 13, 2012 - 08:20 PM
Raving lunatic


Joined: Dec 11, 2007
Posts: 6848
Location: Cleveland, OH

A little late to this thread...

Brad, what do you have for a LPF on the output of the DAC?

Looking at the high freq noise on the scope images it must be in the area of 2.5 MHz. A LPF ought to remove some of that.

I think you would have to look closely at the Power Supply rails for a comparison on the noise. If the noise is on the entire bus, then one knows where is it coming from, (i.e. NOT just the DAC itself, but permeating throughout the entire microcontroller and board).

Also, for that noise, one obviously has to be careful with long leads to the scope probes.

You can pick up that much noise just connecting a piece of hookup wire to the scope probe and laying it near the PCB.

I was recently playing with a simple DDS on an Xmega to check the DAC. The PCB does not have a LPF on the DAC output, and I have long hookup leads to the scope probe, and the output still looks cleaner than what you have posted above.

Xmega34A4, 32 MHz, 100 kHz ISR loading the DAC for the DDS.

JC

I put one photo in This Thread. This has no LPF on the DAC, and long, dangling leads all over the place. The top bit rolling over to zero was a software bug.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits