Liangzhen Lai / Mbed 2 deprecated Orange_Ferrari_board_functional

Dependencies:   DDRO_Farrari mbed

Fork of DDRO_Farrari by Liangzhen Lai

dac.cpp

Committer:
liangzhen
Date:
2014-07-17
Revision:
3:e1a6e12233dd
Parent:
0:84a8bcfbdec9

File content as of revision 3:e1a6e12233dd:

#include "dac.h"

using namespace std;

void power_chan(char i2caddr, char chan, float voltage)
{   
    char data[3];
    
    // voltage = 3.3 * Code / 4096
    // Code = voltage * 4096 / 3.3 = voltage * 1241
    unsigned int full_code = 1241 * voltage;
    
    char MSDB, LSDB;
    LSDB = full_code % 0x10;
    MSDB = full_code / 0x10;
    
    data[0]=chan;
    data[1]=MSDB;
    data[2]=LSDB;
    
    power_error_indicator = 1;
    //pc.printf ("%X\r\n", A);
    while (dac_i2c.write(i2caddr,data,3,false)) {
    }
    power_error_indicator = 0;
}