8 years, 7 months ago.

DAC does not work well

I tried sine wave sample program in 32L152RE and not work well. onboard SBnn connection is same as initial state. I get 150Hz sine wave in PA4, but its amplitude is 0-200mV. I think that is because outbuffer-amp is off or because power is not supplied to DAC. Please tell me the reason and way to make it go well.

1 Answer

8 years, 7 months ago.

instead of

//#define RANGE     (4096/2) // 12 bits DAC
//#define OFFSET    (4096/2) // 12 bits DAC

try these lines

#define RANGE    (65535/2)
#define OFFSET   (65535/2)

The same old story arises: the hardware DAC has indeed 12 bits, but the library defines the full range as 16 bits. That's why your output was soooo small.

Regards,

Accepted Answer

Thank you very much I get 3.3Vp-p sine wave. You mean when CPU set the DAC value to DAC, he shift it 4bit?

posted by Twotom Zeitlin 10 Dec 2015

Yes.

The mbed libraries are written such that you can assume all DACs and ADCs are 16 bit. The values are then shifted the correct amount for each board. This means that the same code can be used on any board without having to check how many bits the DAC/ADC on that CPU has.

posted by Andy A 10 Dec 2015