mbed code for Farrari board

Dependencies:   DDRO_Farrari mbed

Fork of DDRO_Farrari by Liangzhen Lai

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers dac.cpp Source File

dac.cpp

00001 #include "dac.h"
00002 
00003 using namespace std;
00004 
00005 void power_chan(char i2caddr, char chan, float voltage)
00006 {   
00007     char data[3];
00008     
00009     // voltage = 3.3 * Code / 4096
00010     // Code = voltage * 4096 / 3.3 = voltage * 1241
00011     unsigned int full_code = 1241 * voltage;
00012     
00013     char MSDB, LSDB;
00014     LSDB = full_code % 0x10;
00015     MSDB = full_code / 0x10;
00016     
00017     data[0]=chan;
00018     data[1]=MSDB;
00019     data[2]=LSDB;
00020     
00021     power_error_indicator = 1;
00022     //pc.printf ("%X\r\n", A);
00023     while (dac_i2c.write(i2caddr,data,3,false)) {
00024     }
00025     power_error_indicator = 0;
00026 }