Maker Pro
Maker Pro

DAC and ADC Simutaneous Testing

vinit2100

Oct 21, 2013
100
Joined
Oct 21, 2013
Messages
100
DAC_data()
{
unsigned int UpHex,MidHex,LowHex,wDigVoltage,Temp,i;
while(1)
{


unsigned int dac_ip[]= { 0x03C,0x03D,0x03E,0x03F,0x040,0x041,0x042,0x043,0x044,0x045,0x046,0x047,0x048,0x049,0x04A,0x04B,
0x04C,0x04D,0x04E,0x04F,0x050,0x051,0x052,0x053,0x054,0x055,0x056,0x057,0x058,0x059,0x05A,0x05B,
0x05C,0x05D,0x05E,0x05F,0x060,0x061,0x062,0x063,0x064,0x065,0x066,0x067,0x068,0x069,0x06A,0x06B,
0x06C,0x06D,0x06E,0x06F,0x070,0x071,0x072,0x073,0x074,0x075,0x076,0x077,0x078,0x078,0x078,0x078,
0x078,0x078,0x078,0x078,0x078,0x078,0x078,0x078,0x078,0x078,0x078,0x078,0x078,0x078,0x078,0x078,
0x078,0x077,0x076,0x075,0x075,0x074,0x073,0x072,0x071,0x070,0x06F,0x06E,0x06D,0x06C,0x06B,0x06A,
0x069,0x068,0x067,0x065,0x064,0x063,0x062,0x061,0x060,0x05F,0x05E,0x05D,0x05C,0x05B,0x05A,0x059,
0x058,0x057,0x056,0x055,0x054,0x053,0x052,0x051,0x050,0x04F,0x04E,0x04D,0x04C,0x04B,0x04A,0x049,
0x048,0x047,0x046,0x045,0x044,0x043,0x042,0x041,0x040,0x03F,0x03E,0x03D,0x03C,0x03B,0x03A,0x039,
0x038,0x037,0x036,0x035,0x034,0x033,0x032,0x031,0x030,0x02F,0x02E,0x02D,0x02C,0x02B,0x02A,0x029,
0x028,0x027,0x026,0x025,0x024,0x023,0x022,0x021,0x020,0x01F,0x01E,0x01D,0x01C,0x01B,0x01A,0x019,
0x026,0x025,0x018,0x017,0x016,0x015,0x014,0x013,0x012,0x011,0x010,0x00F,0x00E,0x00D,0x00C,0x00B,
0x00A,0x009,0x008,0x007,0x006,0x005,0x004,0x003,0x002,0x001,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x001,0x002,0x003,0x004,0x005,0x006,
0x007,0x008,0x009,0x010,0x00A,0x00B,0x00C,0x00D,0x00E,0x00F,0x011,0x012,0x013,0x014,0x015,0x016,
0x017,0x018,0x019,0x01A,0x01B,0x01C,0x01D,0x01E,0x01F,0x020,0x021,0x022,0x023,0x024,0x025,0x026,
0x027,0x028,0x029,0x02A,0x02B,0x02C,0x02D,0x02E,0x02F,0x030,0x031,0x032,0x033,0x034,0x035,0x036,
0x037,0x038,0x039,0x03A,0x03B

};

for(i=0;i<277;i++)
{

Temp = dac_ip;
.
.
*ptr_dac_reg= wDigVoltage ;

ReadADC( );

}



Here the function DAC data() has a look up table of around 277 samples.

case 1: the function ReadADC(); is NOT included
the for loop takes each samples and covert to analog voltages. so this 277 samples makes a sine wave of around 2.23Khz. amplitude is 100mVpp.


case 2: the function ReadADC(); is included


in this case the output frequency changes to around 200Hz.. because of this additinal function. this is the actual problem

the frequency (2.23Khz )should not change when ADC is included. What should i do ??
 

vinit2100

Oct 21, 2013
100
Joined
Oct 21, 2013
Messages
100
Sorry my question was. How will i fix the frequency of DAC sine wave ?

At present i have a DAC look up table consisting of 277 samples , that generate a sine wave of around 2.23Khz.. and if the number of samples increases the frequency reduces. and if number of samples are less, the frequency will be high.. How will i get a say 2Khx sine wave using this DAC ?
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,720
Joined
Nov 17, 2011
Messages
13,720
Your code depends on the runtime of the code for the timing of the analog signals. This is not good practice. Use interrupts. Adding a bit more detail to my post #11, a suitable code structure could look like this:
Code:
main()
{
set timer_1 to 1.33µs intervall // output one sample every 1.33µs for 2.5kHz
set timer_2 to 20µs intervall // input one ADC value every 20µs, equivalent to 50ksamples/second, more than enough for 2.5kHz analog signal.
// change timing for other frequencies.
while (1);
// do whatever you need to do besides writing DAC values and reading ADC values
}

timer_1_interrupt()
{
output next DAC value;
}

timer_2_interrupt()
{
input next ADC value;
}
 

vinit2100

Oct 21, 2013
100
Joined
Oct 21, 2013
Messages
100
Can you explain this
" set timer_1 to 1.33µs intervall // output one sample every 1.33µs for 2.5kHz
set timer_2 to 20µs intervall // input one ADC value every 20µs, equivalent to 50ksamples/second, more than enough for 2.5kHz analog signal.
// change timing for other frequencies.
"
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
Vary the rate at which you send numbers from your wave table to the DAC.

If your wave table contains 277 samples, comprising one cycle of sine wave, and you are getting an output frequency of about 2.23 kHz, you must be transferring samples to the DAC at a rate of (2230 × 277) = 617.71 kHz, i.e. 617,710 samples per second, or 1.62 µs between sample transfers. If you want a 2 kHz sine wave, you need to send the wave table data to the DAC at a rate of (2000 × 277) = 554 kHz.

That's the simplest way to do it.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,720
Joined
Nov 17, 2011
Messages
13,720
Your microcontroller typically has one or more timer circuits. These can be programmed to count up or down and create an interrupt once a defined numbe is reached. E.g. set timer to a value of "x" and count down to 0, create interrupt when 0 is reached. The timer is then (normally automatically) reloaded with "x" and counting starts again.
By selecting a suitable "x" you can set the duration between interrupts.

The value of "x" will depend on your µC's clock frequency and possibly any prescalers within the chip. You have to study the documentation (datasheet, manual) of the µC for specific details.
 

vinit2100

Oct 21, 2013
100
Joined
Oct 21, 2013
Messages
100
At present the DAC is operating at 12Mhz. so i should lower the operating frequency ?
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
If you are sending a 277-entry wave table to the DAC at a sampling rate of 12 MHz your sine wave frequency would be (12,000,000 / 277) = 43.321 kHz. Please explain yourself clearly.
 
Top