Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: TextLCD mbed dacmodule
Fork of DAC_module by
main.cpp
- Committer:
- psuMbedHead
- Date:
- 2016-11-01
- Revision:
- 0:c1332385cffa
- Child:
- 1:af51ee0c367d
File content as of revision 0:c1332385cffa:
#include "mbed.h" #include "mcp4725.h" #include "TextLCD.h" #include "math.h" TextLCD lcd(p14, p13, p21, p22, p23, p24, TextLCD::LCD16x2); // rs, e, d4-d7 // DigitalOut testLed(LED1); Serial pc(USBTX, USBRX); AnalogIn analogIn(p15); // init the DAC module MCP4725 DAC(p28, p27, MCP4725::Standard100kHz, 0); //define custom characters const char sin_char_top[] = { 0x0, 0xe,0x11,0x11, 0x0, 0x0, 0x0, 0x0}; const char sin_char_bot[] = { 0x0, 0x0, 0x0, 0x0,0x11,0x11, 0xe, 0x0}; const char sq_char_left[] = {0x1c, 0x4, 0x4, 0x4, 0x4, 0x4, 0x4, 0x7}; const char sq_char_right[] = { 0x7, 0x4, 0x4, 0x4, 0x4, 0x4, 0x4,0x1c}; const double pi = 3.14159; int main() { //set custom characters lcd.setUDC(0, (char *) sin_char_bot); lcd.setUDC(1, (char *) sin_char_top); lcd.setUDC(2, (char *) sq_char_left); lcd.setUDC(3, (char *) sq_char_right); int RUN = 0; //start = 1, stop = 0 int SIGNAL_MODE = 0; //1sin,10ksin,1sq,10ksq = 0,1,2,3 while(1) { int dots = 0; while(RUN == 0) { lcd.setCursor(TextLCD::CurOff_BlkOff); lcd.setAddress(0, 0); lcd.printf("Waveform: off\n"); if(dots == 0){ lcd.printf("waiting"); dots++; } else if(dots == 1){ lcd.printf("waiting."); dots++; } else if(dots == 2){ lcd.printf("waiting.."); dots++; } else if(dots == 3){ lcd.printf("waiting..."); dots = 0; } else{ lcd.printf("ERROR CASE"); } wait_ms(100); } int i = 0; while(RUN == 1) { //set display on lcd.setCursor(TextLCD::CurOff_BlkOff); lcd.setAddress(0, 0); lcd.printf("Waveform: on\n"); if(SIGNAL_MODE == 0){ //sin wave 1Hz or 1s lcd.putc(0); lcd.putc(1); lcd.printf("1Hz Sin Wav"); double j = 1.65*sin(2*pi*i/100)+1.65; DAC.write(MCP4725::Normal, (0xFFF * (j/3.3)), false); wait_ms(5); i++; } //end if case else if(SIGNAL_MODE == 1){ //sin wave 10kHz or 100us lcd.putc(0); lcd.putc(1); lcd.printf("10kHz Sin Wav"); double k = 1.65*sin(2*pi*i/100)+1.65; DAC.write(MCP4725::Normal, (0xFFF * (k/3.3)), false); wait_us(0.5); i++; } //end if case else if(SIGNAL_MODE == 2){ //square wave 1Hz or 1s lcd.putc(2); lcd.putc(3); lcd.printf("1Hz Sq Wav"); DAC.write(MCP4725::Normal, 0xFFF, false); wait_ms(500); DAC.write(MCP4725::Normal, 0x000, false); wait_ms(500); } //end if case else if(SIGNAL_MODE == 3){ //square wave 10kHz or 100us lcd.putc(2); lcd.putc(3); lcd.printf("10kHz Sq Wav"); DAC.write(MCP4725::Normal, 0xFFF, false); wait_us(50); DAC.write(MCP4725::Normal, 0x000, false); wait_us(50); } //end if case else{ lcd.printf("ERROR CASE"); //do nothing } //end default } //end while(on) loop } //end while(1) loop } //end main