RE: Re: RE: Re: RE: Switching from Mega to Xmega?

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

Hi,
I'm having trouble with all analog functions in my xmega 128a1.

I've set up the DAC example in the documentation for the sine wave output to DACB. I had to add to the main:

#include 
#include 
#include 

I've got a ETT XMEGA board. Other functions are OK in my full application -- serial, timers, interrupts -- but not the analog stuff in my real application. So I've fallen back to almost the simplest code I can have to try to get the sine wave going just to see it work.

The entire program:

#include 
#include 
#include 
#include 

#define SPEAKER_DAC              DACA
#define SPEAKER_DAC_CHANNEL      DAC_CH0   
#define RATE_OF_CONVERSION       22050   
#define NR_OF_SAMPLES            32


 static const uint16_t sine[NR_OF_SAMPLES] = {       
     32768, 35325, 37784, 40050, 42036, 43666, 44877, 45623,       
     45875, 45623, 44877, 43666, 42036, 40050, 37784, 35325,       
     32768, 30211, 27752, 25486, 23500, 21870, 20659, 19913,       
     19661, 19913, 20659, 21870, 23500, 25486, 27752, 30211,
 };

void evsys_init(void);
void evsys_init(void)   
{       
    sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_EVSYS);       
    EVSYS.CH3MUX = EVSYS_CHMUX_TCC0_OVF_gc;   
}     

void tc_init(void);
void tc_init(void)   
{       
    tc_enable(&TCC0);       
    tc_set_wgm(&TCC0, TC_WG_NORMAL);       
    tc_write_period(&TCC0, (sysclk_get_per_hz() / RATE_OF_CONVERSION) - 1);       
    tc_write_clock_source(&TCC0, TC_CLKSEL_DIV1_gc);    
}     

void dac_init(void);
void dac_init(void)
{       
    struct dac_config conf;         
    dac_read_configuration(&SPEAKER_DAC, &conf);       
    dac_set_conversion_parameters(&conf, DAC_REF_AVCC, DAC_ADJ_LEFT);       
    dac_set_active_channel(&conf, SPEAKER_DAC_CHANNEL, 0);       
    dac_set_conversion_trigger(&conf, SPEAKER_DAC_CHANNEL, 0);       
#ifdef XMEGA_DAC_VERSION_1       
    dac_set_conversion_interval(&conf, 1);       
#endif       
    dac_write_configuration(&SPEAKER_DAC, &conf);       
    dac_enable(&SPEAKER_DAC);   
}
 
int main(void)
{
   sysclk_init();   
   evsys_init();   
   tc_init();   
   dac_init();
   uint8_t i = 0;   
   while (1) 
   {       
       dac_wait_for_channel_ready(&SPEAKER_DAC, SPEAKER_DAC_CHANNEL);       
       dac_set_channel_value(&SPEAKER_DAC, SPEAKER_DAC_CHANNEL, sine[i]);       
       i++;       
       i %= NR_OF_SAMPLES;   
   }   
}

Should this work pretty much as is? If not, what's missing?

Thanks,
madGambol

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your post had nothing to do with the topic, created a new thread for you.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

First you talk about DACB, but the code specifies DACA.
Then the DAC has a resolution of 12 bits, so any value higher than 4095 will act funny, I guess (i.e. will it be capped to 4095, or AND'ed with 4095 ?). Maybe the function set_dac_value() scale values down ?

Have a nice day,
Kraal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks!

The option DAC_ADJ_LEFT should allow the use of the values in the table greater than 4096.

The original code was for DACB --- I switched it to DACA, so I misspoke.

Still, no output.

madGambol

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes my mistake, I didn't read carefully enough. Your code comes from the ASF start guide, so it should work alright.
Now I can't find any reference to the board you mentioned. Are you sure that the DAC output is accessible, and that is has been configured as output ? Something the code above does not I believe.

Have a nice day,
Kraal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, the whole port A is brought to a connector.
madGambol

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I've got a ETT XMEGA board

I found a few ET-Based Xmega PCB's Here .

Not sure which one is yours.

I was looking for a schematic to see if you have to do anything to power AVcc, the ANALOG power supply pin on the Xmega.

I didn't see a schematic.

I'm not overly confident in their PCB or at least in their advertising. The Xmega128 PCB I'm looking at on that site says it can use a 7 - 12 VDC power supply which feeds a 7805 regulator.

That would be a problem, as the Xmegas are 3 V chips.

You might want to take a look and see what voltage regulator is really on the PCB, hopefully it isn't a 7805.

If the CD has a schematic, then make sure that the AVcc pin is connected to V+, either directly, or through a small inductor, (L-C Filter).

I can't help with the code, but none of the analog portion of the chip will work without AVcc being properly powered.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JC,

There is the proper wiring on the board for AVcc, and it operates at 3.3 V -- they wouldn't stay in the board business too long if they couldn't get stuff like that right.

I have a schematic I could show if I could see a way to add attachments.

Thanks,

madGambol

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

if I could see a way to add attachments

Instead of using the Quick Reply are click the button New Reply to get to the full functionality reply editor/composer. There you can attach files.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

These are the schematics that come with the board documentation. 1 of 2 has the AVcc circuitry.
madGambol

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
it operates at 3.3 V

That's good news.
(But it's not what their own literature says!)

The power for AVcc looks fine.

That means its back to a software issue, with which I'll let others give you a hand. C isn't my thing.

Not related to your problem, but are you using a Bootloader, or the PDI interface, to program your Xmega? The reason I ask is that their Reset circuitry is, I think, out of spec for the Xmega series. If PDI programming works fine, that's great. If PDI programming is problematic, then that's the most likely problem.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using JTAG on the board. No operational problems anywhere but the analog section.

I might bite the bullet and implement low level code to program it. I have examples of that in documents and some early attempts to talk to the AD/DA.

I'll post what I put together.

Thanks,
madGambol

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Change
i++;
i %= NR_OF_SAMPLES;

to
i++;
i % NR_OF_SAMPLES;

or
i++ % NR_OF_SAMPLES;

You are setting i to NR_OF_SAMPLES instead of limiting it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The 128a1 is the first and worst Xmega. Try the 128a1u.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Steve17: I would like to upgrade to the 128a1u, but the development board I have doesn't come with that part, and its not interchangeable. But I'll look around.

turbotronic: I think the C is correct.

i++; 
i %= NR_OF_SAMPLES;

... should increment the index i, then perform the modulo operation on it.

I'm still working on this issue. I might have a solution. Back shortly.

Thanks,
madGambol

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear tubotronic..

This just computes a value and "drops it on the floor".

i % NR_OF_SAMPLES; 

No variable is changed at all. Likely the optimizer will remove the code completely.

This increments i, and then computes the remainder and drops that on the floor. Here i will not wrap at all but only continue incrementing (until it wraps because the variables value range is exhausted).

i++ % NR_OF_SAMPLES;

Not only is your code suggestions bad, but you where also wrong on your remark on madGambols code.
It does indeed increment the variable and makes it wrap to zero.

Increment the variable:

i++;

Make it wrap to zero if needed:

i %= NR_OF_SAMPLES;

The above is equivalent to:

i = i % NR_OF_SAMPLES;

I.e. keep the remainder of division with NR_OF_SAMPLES. Assume NR_OF_SAMPLES is 32:

 i    i incremented    i % 32    So new value of i becomes
--    -------------    ------    -------------------------
 .     .                .         .
 .     .                .         .
 .     .                .         .
29    30               30        30
30    31               31        31
31    32                0         0        
0      1                1         1
1      2                2         2
 .     .                .         .
 .     .                .         .
 .     .                .         .

When you are not sure of what you are about to say you can always test the code in e.g. Atmel Studio before going public. E.g. this takes a few minutes to write. Run it in the simulator and keep an eye on PORTD in the IO View:

#include 

int main(void)
{
    int i = 30;
    while(1)
    {
        i++;
        i %= 32;
        PORTD = i;
    }
}

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
Quote:

if I could see a way to add attachments

Instead of using the Quick Reply are click the button New Reply to get to the full functionality reply editor/composer. There you can attach files.
Yes that is one way. You can also use quick reply which is how I do it. The trick is to then click Preview instead of Submit. Then you can add attachments.

By the way, I always use Preview so I can better see my post before I submit it. I hate the few forums I use that don't have a preview.

If you have a link in your post, Preview allows you to try the link so you won't ever post a bad link.

Preview also allows you to see your attachments before you Submit.

I hope the new forum doesn't use the push down stack approach to attaching multiple things. With this forum the last attachment displays first. It makes you plan ahead to get the desired results. Seems like too much unnecessary brain strain to me.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

madGambol wrote:
Steve17: I would like to upgrade to the 128a1u, but the development board I have doesn't come with that part, and its not interchangeable. But I'll look around.

turbotronic: I think the C is correct.

i++; 
i %= NR_OF_SAMPLES;

... should increment the index i, then perform the modulo operation on it.

I'm still working on this issue. I might have a solution. Back shortly.

Thanks,
madGambol

Oops...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi madGambol,

you are expect conversion trigger from EV Channel 3, but in command:

dac_set_conversion_trigger(&conf, SPEAKER_DAC_CHANNEL, 0);  

sets trigger to channel 0. Try change this command to:

dac_set_conversion_trigger(&conf, SPEAKER_DAC_CHANNEL, 3)