0
#include "mbed.h"
DigitalOut gpo(PTD7);
AnalogOut Aout(PTE30);
float x; 
unsigned int i,j;

int main() {
   x=0;
   i=0;
   while(1) {
      gpo=i & 1;
      x=16*2047.0*(1+sin(2*3.142*i/64));
      j=x; 
      Aout.write_u16(j);
      i++; 
   } 
}

This code is supposed to produce a sine wave from the DAC. The microcontroller I'm using is 16 bits while the DAC that the information is being sent to is 12 bits. The line x=... is the equation for a sine wave and produces new values for a sine wave every loop. Can someone explain why we need to multiply the value by 16*2047? like how does this help calibrate the waveform ?

4
  • Its possible the DAC is 12 bits, but is left justified in the 16 bit register.. (i.e. the bottom 4 bits are ignored). This is "common" because fractional representation is very common in DSP (0xffff is ~1.0/full scale, 0x0000 is 0). Your processing stays the same if you have a 16 bit dac, a 12 bit, or an 8 bit dac. Commented Mar 30, 2022 at 21:04
  • You need to read the manual to see how the DAC presents the data. Most often it can be configured. In case of external DAC then endianess is also a consideration. Commented Mar 31, 2022 at 6:45
  • 1
    It seems as if this is a homework question. Please edit your question and tell us what specifically you don't understand. Commented Mar 31, 2022 at 6:46
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Mar 31, 2022 at 10:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.