convertidor digital. analogico

Dependencies:   mbed

Committer:
rvazquezc
Date:
Wed Jun 24 00:14:15 2015 +0000
Revision:
0:02e65197aa23
convertidor-Digital-analogico

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rvazquezc 0:02e65197aa23 1 #include "mbed.h"
rvazquezc 0:02e65197aa23 2
rvazquezc 0:02e65197aa23 3 // The sinewave is created on this pin
rvazquezc 0:02e65197aa23 4 AnalogOut aout(DAC0_OUT);
rvazquezc 0:02e65197aa23 5
rvazquezc 0:02e65197aa23 6 int main()
rvazquezc 0:02e65197aa23 7 {
rvazquezc 0:02e65197aa23 8 const double pi = 3.141592653589793238462;
rvazquezc 0:02e65197aa23 9 const double amplitude = 0.5f;
rvazquezc 0:02e65197aa23 10 const double offset = 65535/2;
rvazquezc 0:02e65197aa23 11 double rads = 0.0;
rvazquezc 0:02e65197aa23 12 uint16_t sample = 0;
rvazquezc 0:02e65197aa23 13
rvazquezc 0:02e65197aa23 14 while(1) {
rvazquezc 0:02e65197aa23 15 // sinewave output
rvazquezc 0:02e65197aa23 16 for (int i = 0; i < 360; i++) {
rvazquezc 0:02e65197aa23 17 rads = (pi * i) / 180.0f;
rvazquezc 0:02e65197aa23 18 sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset);
rvazquezc 0:02e65197aa23 19 aout.write_u16(sample);
rvazquezc 0:02e65197aa23 20 }
rvazquezc 0:02e65197aa23 21 }
rvazquezc 0:02e65197aa23 22 }