Roberto Vázquez
/
frdm_gpio_DAC
convertidor digital. analogico
main.cpp
- Committer:
- rvazquezc
- Date:
- 2015-06-24
- Revision:
- 0:02e65197aa23
File content as of revision 0:02e65197aa23:
#include "mbed.h" // The sinewave is created on this pin AnalogOut aout(DAC0_OUT); int main() { const double pi = 3.141592653589793238462; const double amplitude = 0.5f; const double offset = 65535/2; double rads = 0.0; uint16_t sample = 0; while(1) { // sinewave output for (int i = 0; i < 360; i++) { rads = (pi * i) / 180.0f; sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset); aout.write_u16(sample); } } }