This is the DDRO software we write to operate the chip

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers power_up.cpp Source File

power_up.cpp

00001 #include "power_up.h"
00002 using namespace std;
00003 
00004 #define ADDR 0x98 //change to 94 or 98 if doesn't work
00005 #define POWER_UP_TIME 0.3
00006 
00007 I2C i2c(p9, p10);       //sda, scl
00008 DigitalOut ADDR0(p6);   //ADDR0 in DAC
00009 Serial power_pc(USBTX, USBRX);//tx, rx => for debugging purposes
00010 DigitalOut power_indicator (LED1);
00011 DigitalOut power_error_indicator (LED4);
00012 DigitalOut LDAC_BAR(p7);
00013 DigitalOut CLR_BAR(p5);
00014 
00015 void power(const int A, char CA, char MSDB, char LSDB)
00016 {
00017     int state;
00018     char data[3];
00019     data[0]=CA;
00020     data[1]=MSDB;
00021     data[2]=LSDB;
00022     debugPower();
00023     power_error_indicator = 1;
00024     //pc.printf ("%X\n", A);
00025     while (i2c.write(A,data,3,false)) {
00026     }
00027     power_error_indicator = 0;
00028 }
00029 
00030 void powerUp(double voltage)
00031 {
00032     if (voltage > 1 || voltage <0.6) {
00033         voltage = 0.9;
00034     }
00035     unsigned int volt = (voltage/3.3*65535);
00036     char MSDB, LSDB;
00037     LSDB = volt % 0x100;
00038     MSDB = volt / 0x100;
00039     voltage += 0.03;
00040     if(voltage >1) {
00041         voltage = 1;
00042     };
00043     unsigned int boosted_volt = (voltage/3.3*65535);
00044     char MSDB2, LSDB2;
00045     LSDB2 = volt % 0x100;
00046     MSDB2 = volt / 0x100;
00047     //power_pc.printf("%x%x\n", MSDB, LSDB);
00048     power(ADDR,0x31,0x8B,0xA0) ;  //update channel B 1.8V    DVDD2
00049     wait(POWER_UP_TIME);
00050     power(ADDR,0x37,0x4D,0x90) ;  //update channel H 1V      AVDD
00051     wait(POWER_UP_TIME);
00052     power(ADDR,0x35,0x26,0xC0) ;  //update channel F 0.5V    AVDD2
00053     wait(POWER_UP_TIME);
00054     power(ADDR,0x34,MSDB2,LSDB2) ;  //update channel E 1V      WRAPPERVD
00055     wait(POWER_UP_TIME);
00056     power(ADDR,0x32,MSDB,LSDB) ;  //update channel C 1V      COREVDD
00057     wait(POWER_UP_TIME);
00058     power(ADDR,0x30,MSDB2,LSDB2) ;  //update channel A 1V      SRAMVDD
00059     wait(POWER_UP_TIME);
00060     power(ADDR,0x36,MSDB,LSDB) ;  //update channel G 1V      SENSEVDD
00061     wait(POWER_UP_TIME);
00062     power_indicator = 1;
00063     power(ADDR,0x33,0xFF,0xF0) ;  //update channel D 3.3V    DVDD
00064     wait(POWER_UP_TIME);
00065 }
00066 
00067 void powerDown()
00068 {
00069     power(ADDR,0x33,0x00,0x00) ;  //update channel D 3.3V    DVDD
00070     wait(POWER_UP_TIME);
00071     power_indicator = 0;
00072     power(ADDR,0x37,0x00,0x00) ;  //update channel H 1V      AVDD
00073     wait(POWER_UP_TIME);
00074     power(ADDR,0x35,0x00,0x00) ;  //update channel F 0.5V    AVDD2
00075     wait(POWER_UP_TIME);
00076     power(ADDR,0x34,0x00,0x00) ;  //update channel E 1V      WRAPPERVD
00077     wait(POWER_UP_TIME);
00078     power(ADDR,0x32,0x00,0x00) ;  //update channel C 1V      COREVDD
00079     wait(POWER_UP_TIME);
00080     power(ADDR,0x30,0x00,0x00) ;  //update channel A 1V      SRAMVDD
00081     wait(POWER_UP_TIME);
00082     power(ADDR,0x36,0x00,0x00) ;  //update channel G 1V      SENSEVDD
00083     wait(POWER_UP_TIME);
00084 //    power(ADDR,0x31,0x00,0x00) ;  //update channel B 1.8V    DVDD2
00085 //    wait(POWER_UP_TIME);
00086 }
00087 
00088 void powerReset()
00089 {
00090     power_indicator = 0;
00091     CLR_BAR = 0;
00092     ADDR0 = 0;
00093     LDAC_BAR = 0;
00094     CLR_BAR = 1;
00095 }
00096 
00097 void debugPower()
00098 {
00099     char data[3];
00100     data[0]=0x31;
00101     data[1]=0x8B;
00102     data[2]=0xA0;
00103     int A = 0;
00104     for (A = 0; A<=0xFF; A++) {
00105         if (i2c.write(A,data,3,false)==0) {
00106             //pc.printf ("%X\n", A);
00107         }
00108     }
00109 }