Publishing for sharing with Harald

Dependencies:   csi059

Revision:
4:1c48c9fa44fc
Parent:
3:3e8c16b6620c
--- a/EasyFuse_Prog.cpp	Thu Jun 21 22:11:25 2018 +0000
+++ b/EasyFuse_Prog.cpp	Fri May 22 19:19:45 2020 +0000
@@ -23,28 +23,49 @@
 
 void print_nvm_reg(uint8_t *max_Vout, uint8_t *max_Vout_trim, uint8_t *high_time, uint8_t *low_time, uint8_t *adc_samp_rate, 
 uint8_t *adc_range, uint8_t *adc_time_out, uint8_t *comp_offset, uint8_t *range_trim, uint8_t *PMOS_off, uint8_t *Driver2, uint8_t *Driver3, 
-uint8_t *DMOS, uint8_t *CCM_threshold, uint8_t *DMOS_ctrl_trim, uint8_t *adc_op_mode) {
+uint8_t *neg_hlf_rng, uint8_t *CCM_threshold, uint8_t *DMOS_ctrl_trim, uint8_t *adc_op_mode) {
 
     pc.printf("\033[%dm ", 35);//change text color to red
     pc.printf("\n\n\n\r\t    Register contents :\n\r\t   ");
     for ( int i = 0; i<26; i++) pc.printf("\304"); 
-    pc.printf("\n\n\r\t    1. max_Vout        = 0x%2.2X",*max_Vout);
-    pc.printf("\n\n\r\t    2. max_Vout_trim   = 0x%2.2X",*max_Vout_trim);
-    pc.printf("\n\n\r\t    3. high_time       = 0x%2.2X",*high_time);
-    pc.printf("\n\n\r\t    4. low_time        = 0x%2.2X",*low_time);
-    pc.printf("\n\n\r\t    5. adc_samp_rate   = 0x%2.2X",*adc_samp_rate);
-    pc.printf("\n\n\r\t    6. adc_range       = 0x%2.2X",*adc_range);
-    pc.printf("\n\n\r\t    7. adc_time_out    = 0x%2.2X",*adc_time_out);
-    pc.printf("\n\n\r\t    8. comp_offset     = 0x%2.2X",*comp_offset);
-    pc.printf("\n\n\r\t    9. range_trim      = 0x%2.2X",*range_trim);
-    pc.printf("\n\n\r\t   10. PMOS_off        = 0x%2.2X",*PMOS_off);
-    pc.printf("\n\n\r\t   11. Driver2         = 0x%2.2X",*Driver2);
-    pc.printf("\n\n\r\t   12. Driver3         = 0x%2.2X",*Driver3);
-    pc.printf("\n\n\r\t   13. DMOS            = 0x%2.2X",*DMOS);
-    pc.printf("\n\n\r\t   14. CCM_threshold   = 0x%2.2X",*CCM_threshold);
-    pc.printf("\n\n\r\t   15. DMOS_ctrl_trim  = 0x%2.2X",*DMOS_ctrl_trim);
-    pc.printf("\n\n\r\t   16. adc_op_mode     = 0x%2.2X",*adc_op_mode);
-    pc.printf("\n\n\r\t   ");
+    if (*PMOS_off == 0x0f) // ACP Mode
+    {
+        pc.printf("\n\n\r\t\t    ACP Mode \n\n");
+        pc.printf("\n\n\r\t    1. max_Vout        = 0x%2.2X",*max_Vout);
+        pc.printf("\n\n\r\t    2. max_Vout_trim   = 0x%2.2X",*max_Vout_trim);
+        pc.printf("\n\n\r\t    3. high_time       = 0x%2.2X",*high_time);
+        pc.printf("\n\n\r\t    4. low_time        = 0x%2.2X",*low_time);
+        pc.printf("\n\n\r\t    5. adc_samp_rate   = 0x%2.2X",*adc_samp_rate);
+        pc.printf("\n\n\r\t    6. adc_range       = 0x%2.2X",*adc_range);
+        pc.printf("\n\n\r\t    7. adc_time_out    = 0x%2.2X",*adc_time_out);
+        pc.printf("\n\n\r\t    8. comp_offset     = 0x%2.2X",*comp_offset);
+        pc.printf("\n\n\r\t    9. range_trim      = 0x%2.2X",*range_trim);
+        pc.printf("\n\n\r\t   10. PMOS_off        = 0x%2.2X",*PMOS_off);
+        pc.printf("\n\n\r\t   13. SkipPwr         = 0x%2.2X",*neg_hlf_rng);
+        pc.printf("\n\n\r\t   16. adc_op_mode     = 0x%2.2X",*adc_op_mode);
+        pc.printf("\n\n\r\t   ");
+    }
+    else
+    {
+        pc.printf("\n\n\r\t\t    BiP Mode \n\n");       
+        pc.printf("\n\n\r\t    1. max_Vout        = 0x%2.2X",*max_Vout);
+        pc.printf("\n\n\r\t    2. max_Vout_trim   = 0x%2.2X",*max_Vout_trim);
+        pc.printf("\n\n\r\t    3. high_time       = 0x%2.2X",*high_time);
+        pc.printf("\n\n\r\t    4. low_time        = 0x%2.2X",*low_time);
+        pc.printf("\n\n\r\t    5. adc_samp_rate   = 0x%2.2X",*adc_samp_rate);
+        pc.printf("\n\n\r\t    6. adc_range       = 0x%2.2X",*adc_range);
+        pc.printf("\n\n\r\t    7. adc_time_out    = 0x%2.2X",*adc_time_out);
+        pc.printf("\n\n\r\t    8. comp_offset     = 0x%2.2X",*comp_offset);
+        pc.printf("\n\n\r\t    9. range_trim      = 0x%2.2X",*range_trim);
+        pc.printf("\n\n\r\t   10. PMOS_off        = 0x%2.2X",*PMOS_off);
+        pc.printf("\n\n\r\t   11. Driver2         = 0x%2.2X",*Driver2);
+        pc.printf("\n\n\r\t   12. Driver3         = 0x%2.2X",*Driver3);
+        pc.printf("\n\n\r\t   13. neg_hlf_rng     = 0x%2.2X",*neg_hlf_rng);
+        pc.printf("\n\n\r\t   14. CCM_threshold   = 0x%2.2X",*CCM_threshold);
+        pc.printf("\n\n\r\t   15. DMOS_ctrl_trim  = 0x%2.2X",*DMOS_ctrl_trim);
+        pc.printf("\n\n\r\t   16. adc_op_mode     = 0x%2.2X",*adc_op_mode);
+        pc.printf("\n\n\r\t   ");
+    }                
     for ( int i = 0; i<26; i++) pc.printf("\315");
     pc.printf("\033[%dm", 32);//change text color to green
     pc.printf("\n\r");    
@@ -52,20 +73,20 @@
 
 void edit_nvm_reg(uint8_t *max_Vout, uint8_t *max_Vout_trim, uint8_t *high_time, uint8_t *low_time, uint8_t *adc_samp_rate, 
 uint8_t *adc_range, uint8_t *adc_time_out, uint8_t *comp_offset, uint8_t *range_trim, uint8_t *PMOS_off, uint8_t *Driver2, uint8_t *Driver3, 
-uint8_t *DMOS, uint8_t *CCM_threshold, uint8_t *DMOS_ctrl_trim, uint8_t *adc_op_mode) {
+uint8_t *neg_hlf_rng, uint8_t *CCM_threshold, uint8_t *DMOS_ctrl_trim, uint8_t *adc_op_mode) {
 
     char temp;
     int flag1;
     char count;
     char reg_data;
     
-    char reg_name[16][15] = {"max_Vout", "max_Vout_trim", "high_time", "low_time", "adc_samp_rate", 
+    char reg_name[16][20] = {"max_Vout", "max_Vout_trim", "high_time", "low_time", "adc_samp_rate", 
                             "adc_range", "adc_time_out", "comp_offset", "range_trim", "PMOS_off", "Driver2", "Driver3", 
-                            "DMOS", "CCM_threshold", "DMOS_ctrl_trim", "adc_op_mode" };
+                            "neg_hlf_rng_SkipPwr", "CCM_threshold", "DMOS_ctrl_trim", "adc_op_mode" };
 
     uint8_t *reg_addr[16] =  {   max_Vout, max_Vout_trim, high_time, low_time, adc_samp_rate, 
                             adc_range, adc_time_out, comp_offset, range_trim, PMOS_off, Driver2, Driver3, 
-                            DMOS, CCM_threshold, DMOS_ctrl_trim, adc_op_mode};
+                            neg_hlf_rng, CCM_threshold, DMOS_ctrl_trim, adc_op_mode};
                             
     pc.printf("\n\n\n \r\tDo you want to edit the registers? (y/n) : ");  
     temp = 0;
@@ -73,7 +94,7 @@
         temp = pc.getc();
     }
     if (temp == 'n') {
-        pc.printf("\n\n \r\tContinue with above contents");
+        pc.printf("\n\n \r\tContinuing with above contents");
         return;
     }
     temp = 'y';
@@ -112,7 +133,7 @@
             
             print_nvm_reg(  max_Vout, max_Vout_trim, high_time, low_time, adc_samp_rate, 
                         adc_range, adc_time_out, comp_offset, range_trim, PMOS_off, Driver2, Driver3, 
-                        DMOS, CCM_threshold, DMOS_ctrl_trim, adc_op_mode);
+                        neg_hlf_rng, CCM_threshold, DMOS_ctrl_trim, adc_op_mode);
             
             pc.printf("\n\n \r\tDo you want to make more changes? (y/n) : ");
             temp = pc.getc();
@@ -121,7 +142,7 @@
         
 void i2c_write_fn(I2C *i2c_obj, char ptr, char write_data) {
     int flag1;
-    wait_us(10);
+    wait_us(20);
     (*i2c_obj).start();
     flag1 = (*i2c_obj).write(dev_addr);
     if (flag1 != 1) pc.printf("\n\n\r\tNo Ack for dev addr :(");
@@ -129,8 +150,9 @@
     if (flag1 != 1) pc.printf("\n\n\r\tNo Ack reg pointer :(");    
     flag1 = (*i2c_obj).write(write_data); 
     if (flag1 != 1) pc.printf("\n\n\r\tNo Ack data :(");           
-    wait_us(5);
+    wait_us(20);
     (*i2c_obj).stop();
+    wait_us(300);
 }
 
 char i2c_read_fn(I2C *i2c_obj, char ptr) {
@@ -143,14 +165,14 @@
     flag1 = (*i2c_obj).write(ptr);
     if (flag1 != 1) pc.printf("\n\n\r\tNo Ack reg pointer :(");
     (*i2c_obj).stop();
-    wait_us(10);
+    wait_us(300);
     (*i2c_obj).start();
     flag1 = (*i2c_obj).write(dev_addr | 0x01); //lsb 1 for read
     if (flag1 != 1) pc.printf("\n\n\r\tNo Ack for dev addr :(");         
     read_data = (*i2c_obj).read(0); //0- donot send ack after read is done         
     wait_us(5);
     (*i2c_obj).stop();      
-    wait_us(120);
+    wait_us(300);
     return read_data;
 }
 
@@ -158,7 +180,8 @@
     char reg_ptr = 0x00;
     char reg_data[10];
     char data;
-    uint8_t NVM_READ        = 0x70 ;  
+    uint8_t NVM_PWR_ON      = 0x20 ;
+    uint8_t NVM_READ        = 0x90 ;  //force load shadow register
     uint8_t NVM_CTLR_ADR    = 0x0a ;  //Register address for NVM CTRL
     uint64_t NVM_data = 0x0000000000000000;
     
@@ -175,7 +198,7 @@
     uint8_t PMOS_off;
     uint8_t Driver2;
     uint8_t Driver3;
-    uint8_t DMOS;
+    uint8_t neg_hlf_rng;
     uint8_t CCM_threshold;
     uint8_t DMOS_ctrl_trim;
     uint8_t adc_op_mode;
@@ -189,21 +212,10 @@
     pc.printf("\n\n\r\tSwitching to faster clock before reading the NVM");    
     i2c_write_fn(i2c_obj,0x02,0x01); //switching to faster clock for NVM read
     i2c_write_fn(i2c_obj,0x03,0x01); //switching to faster clock for NVM read
+    i2c_write_fn(i2c_obj,NVM_CTLR_ADR,NVM_PWR_ON);
     wait_ms(1);
-    i2c_write_fn(i2c_obj,NVM_CTLR_ADR,NVM_READ); //Perform a complete read; will be sucessful only if NVM is not empty    
-    wait_ms(100);
-
-    //check if tm_nvm_read bit has cleared itself
-    temp = 0;
-    while (temp == 0){
-        data = i2c_read_fn(i2c_obj,NVM_CTLR_ADR);
-        data = data & 0x40;
-        if (data == 0x00) {
-                pc.printf("\n\n\r\ttm_nvm_read has cleared; so loading Register with NVM complete");
-                temp = 1;
-        }
-        else wait_ms(100);
-    }  
+    i2c_write_fn(i2c_obj,NVM_CTLR_ADR,(NVM_PWR_ON + NVM_READ)); //Force load shadow register from NVM    
+    wait_ms(200);
 
     pc.printf("\n\n\n\r\tReading register 0x00 to 0x09");
     for( reg_ptr = 0x00;  reg_ptr <= 0x09; reg_ptr = reg_ptr+1) {
@@ -223,7 +235,7 @@
     PMOS_off        = reg_data[7] & 0x0f;
     Driver2         = reg_data[8] & 0x0f;
     Driver3         = (reg_data[8]>>4) & 0x0f;
-    DMOS            = (reg_data[9]>>7) & 0x01;
+    neg_hlf_rng     = (reg_data[9]>>7) & 0x01;
     CCM_threshold   = (reg_data[7]>>4) & 0x0f;
     DMOS_ctrl_trim  = reg_data[9] & 0x1f;
     adc_op_mode     = (reg_data[5]>>7) & 0x01;
@@ -232,10 +244,10 @@
 
     print_nvm_reg(&max_Vout, &max_Vout_trim, &high_time, &low_time, &adc_samp_rate, 
     &adc_range, &adc_time_out, &comp_offset, &range_trim, &PMOS_off, &Driver2, &Driver3, 
-    &DMOS, &CCM_threshold, &DMOS_ctrl_trim, &adc_op_mode);
+    &neg_hlf_rng, &CCM_threshold, &DMOS_ctrl_trim, &adc_op_mode);
     
     //push data into NVM_data
-    NVM_data = NVM_data | (max_Vout+1); //max_Vout(register) = max_Vout(NVM) - 1
+    NVM_data =  NVM_data | (max_Vout); //max_Vout(register) = max_Vout(NVM) - 1// this needs to be changed
     NVM_data = (NVM_data<<5) | max_Vout_trim; 
     NVM_data = (NVM_data<<7) | high_time; // <<x : x corresponds to no. of bits
     NVM_data = (NVM_data<<7) | low_time;
@@ -247,7 +259,7 @@
     NVM_data = (NVM_data<<4) | PMOS_off;
     NVM_data = (NVM_data<<4) | Driver2;
     NVM_data = (NVM_data<<4) | Driver3;
-    NVM_data = (NVM_data<<1) | DMOS;
+    NVM_data = (NVM_data<<1) | neg_hlf_rng;
     NVM_data = (NVM_data<<4) | CCM_threshold;
     NVM_data = (NVM_data<<5) | DMOS_ctrl_trim;
     NVM_data = (NVM_data<<1) | adc_op_mode;    
@@ -262,36 +274,37 @@
     uint64_t NVM_read_data;
     
     // Register variables
-    uint8_t max_Vout = 0x07;
-    uint8_t max_Vout_trim = 0x00;
-    uint8_t high_time = 0x12;
-    uint8_t low_time = 0x29;
-    uint8_t adc_samp_rate = 0x06;
-    uint8_t adc_range = 0x01;
-    uint8_t adc_time_out = 0x02;
-    uint8_t comp_offset = 0x00;
-    uint8_t range_trim = 0x0f;
-    uint8_t PMOS_off = 0x08;
-    uint8_t Driver2 = 0x08;
-    uint8_t Driver3 = 0x08;
-    uint8_t DMOS = 0x01;
-    uint8_t CCM_threshold = 0x0f;
-    uint8_t DMOS_ctrl_trim = 0x0c;
-    uint8_t adc_op_mode = 0x01;
+    uint8_t max_Vout = 0x00; //4.2V
+    uint8_t max_Vout_trim = 0x03; //0%
+    uint8_t high_time = 0x11; //12us 
+    uint8_t low_time = 0x46; //38us 
+    uint8_t adc_samp_rate = 0x05; //1 sample/1.35s
+    uint8_t adc_range = 0x01; //2mV
+    uint8_t adc_time_out = 0x02; // 1/256 = 5.3ms
+    uint8_t comp_offset = 0x00; //0% 
+    uint8_t range_trim = 0x16; //0% 
+    uint8_t PMOS_off = 0x07; //7 -> 18mV 
+    uint8_t Driver2 = 0x08; //8 -> 36mV
+    uint8_t Driver3 = 0x08; // 8 -> 54mV
+    uint8_t neg_hlf_rng = 0x00; //disabled
+    uint8_t CCM_threshold = 0x00; //off 
+    uint8_t DMOS_ctrl_trim = 0x16; //<14us
+    uint8_t adc_op_mode = 0x00; //Transmit measurements continously 
 
-    // NVM Register Control Bit locations; PWR_ON set in all the definitions
-    uint8_t NVM_RESET       = 0x31 ;
+    // NVM Register Control Bit locations; 
+    uint8_t NVM_RESET       = 0x01 ;
     uint8_t NVM_PWE1        = 0x02 ;
-    uint8_t NVM_CLK1        = 0x34 ;
-    uint8_t NVM_PWR_ON      = 0x30 ;
-    uint8_t NVM_READ        = 0x70 ;
+    uint8_t NVM_CLK1        = 0x04 ;
+    uint8_t NVM_PWR_ON      = 0x20 ;
+    uint8_t NVM_LD_SHDW     = 0x90 ;//unpdated in Rev1.0
+    uint8_t NVM_READ        = 0x50 ;    
     
-    uint8_t NVM_CTLR_ADR     = 0x0a ;  //Register address for NVM CTRL
+    uint8_t NVM_CTLR_ADR    = 0x0a ;  //Register address for NVM CTRL
      
     char reg_data = 0xaa;
     char temp;
     char high_time_prog = 0x04;
-    char low_time_prog = 0x04;
+    char low_time_prog = 0x05;
     int flag1 = 0;
     int i = 0;
     
@@ -306,14 +319,14 @@
     pc.printf("\n\n\r\tFollowing are the default register data that will be programmed: \n\r ");
     print_nvm_reg(&max_Vout, &max_Vout_trim, &high_time, &low_time, &adc_samp_rate, 
     &adc_range, &adc_time_out, &comp_offset, &range_trim, &PMOS_off, &Driver2, &Driver3, 
-    &DMOS, &CCM_threshold, &DMOS_ctrl_trim, &adc_op_mode);    
+    &neg_hlf_rng, &CCM_threshold, &DMOS_ctrl_trim, &adc_op_mode);    
 
     edit_nvm_reg(&max_Vout, &max_Vout_trim, &high_time, &low_time, &adc_samp_rate, 
     &adc_range, &adc_time_out, &comp_offset, &range_trim, &PMOS_off, &Driver2, &Driver3, 
-    &DMOS, &CCM_threshold, &DMOS_ctrl_trim, &adc_op_mode);       
+    &neg_hlf_rng, &CCM_threshold, &DMOS_ctrl_trim, &adc_op_mode);       
       
     //push data into NVM_data
-    NVM_data = NVM_data | (max_Vout+1); //max_Vout(register) = max_Vout(NVM) - 1
+    NVM_data =  NVM_data | max_Vout; //no more addition of 1 as in Jacaranda
     NVM_data = (NVM_data<<5) | max_Vout_trim; 
     NVM_data = (NVM_data<<7) | high_time; // <<x : x corresponds to no. of bits
     NVM_data = (NVM_data<<7) | low_time;
@@ -325,12 +338,11 @@
     NVM_data = (NVM_data<<4) | PMOS_off;
     NVM_data = (NVM_data<<4) | Driver2;
     NVM_data = (NVM_data<<4) | Driver3;
-    NVM_data = (NVM_data<<1) | DMOS;
+    NVM_data = (NVM_data<<1) | neg_hlf_rng;
     NVM_data = (NVM_data<<4) | CCM_threshold;
     NVM_data = (NVM_data<<5) | DMOS_ctrl_trim;
     NVM_data = (NVM_data<<1) | adc_op_mode;
     pc.printf("\n\n\n\r\tData to be written into NVM = 0x%016llX",NVM_data);
-    pc.printf("\n\n\r\tPlease note that max_Vout has been incremented. max_Vout(NVM) = max_Vout(register) + 1");  
     pc.printf("\n\n\r\t"); 
     for ( i = 0; i<80; i++) pc.printf("\304");  
     pc.printf("\n\n\r\tContinue EasyFuse Programming? (y/n): ");  
@@ -342,31 +354,26 @@
         pc.printf("\n\n\r\tAborting... :(");
         return;
     }
+    temp = 0;
+    pc.printf("\n\n\n\r\tConnect PROG to 4.5V & VINA to 4.5V and press 'c' to continue"); 
+    while ( temp!='c') {
+        temp = pc.getc();
+    }
     //EasyFuse Empty check
-    pc.printf("\n\n\r\tPerforming NVM Empty check by trying to load register with NVM contents");
+    pc.printf("\n\n\r\tPerforming NVM Empty check by trying to load register with NVM contents.");
     i2c_write_fn(&i2c,0x02,0x01); //switching to faster clock for NVM read
     i2c_write_fn(&i2c,0x03,0x01); //switching to faster clock for NVM read
     wait_ms(1);
-    i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_READ); //Perform a complete read; will be sucessful only if NVM is not empty    
-    wait_ms(100);
-    
-    //check if tm_nvm_read bit has cleared itself
-    temp = 0;
-    while (temp == 0){
-        reg_data = i2c_read_fn(&i2c,NVM_CTLR_ADR);
-        reg_data = reg_data & 0x40;
-        if (reg_data == 0x00) {
-                pc.printf("\n\n\r\ttm_nvm_read has cleared; so loading Register with NVM complete");
-                temp = 1;
-        }
-        else wait_ms(100);
-    }   
-        
+    i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_PWR_ON); 
+    wait_ms(1);       
+    i2c_write_fn(&i2c,NVM_CTLR_ADR,(NVM_READ + NVM_PWR_ON)); //Initiate NVM read cycle    
+    wait_ms(200);
+          
     reg_data = i2c_read_fn(&i2c,0x02);
     reg_data = reg_data<<4;
     reg_data = reg_data | i2c_read_fn(&i2c,0x03);
     if (reg_data == 0xff) pc.printf("  |\033[%dm  Register read might not be sucessfull \033[%dm ",45,40);
-    if (reg_data == 0x11) pc.printf("\n\n\r\t\033[%dm EasyFuse empty \033[%dm",44,40); //no change at address 0x02 & 0x03
+    if (reg_data == 0x11) pc.printf("\n\n\r\t\033[%dm EasyFuse empty \033[%dm",44,40); //NVM load will be successful only when NVM is not empty
     else {
         pc.printf("\n\n\r\t\033[%dm EasyFuse not empty \033[%dm",45,40);
         pc.printf("\n\n\r\t Better to abort the test.. :(");
@@ -383,18 +390,20 @@
         pc.printf("\n\n\r\tAborting.. :(");
         return;
     }
-    pc.printf("\n\n\r\tEnabled 'fc_enable' & driver1. Monitor the oscillator at the output of comparator");     
-    i2c_write_fn(&i2c,0x0c,0x22);   
+    
+    i2c_write_fn(&i2c,0x17,0x01); //internal clock is muxed out through DATA2_CLK
+    pc.printf("\n\n\r\tMonitor Clock at DATA2_CLK pin");       
+
 osc_trim:
     i2c_write_fn(&i2c,0x02,high_time_prog); //Recommended clocks period 
     i2c_write_fn(&i2c,0x03,low_time_prog); // for programming is 10us
     wait_ms(1);
 
     pc.printf("\n\n\n\r\t\033[%dm", 44);//change backround to blue
-    pc.printf("Please check if Oscillator period is approx 10us (9.4us to 10.4us) \033[%dm\n\n\r\tPress 'y' to continue; Press 'm' to modify clock trim settings : ",40); 
+    pc.printf("Please check if Oscillator period is approx 10us (9.5us to 10.5us) \033[%dm\n\n\r\tPress 'y' to continue; Press 'm' to modify clock trim settings : ",40); 
 
     temp = 0;
-    while ( temp!='y' && temp!='m' && temp!='m' ) {
+    while ( temp!='y' && temp!='m' && temp!='n' ) {
         temp = pc.getc();
     }
     if (temp == 'n') {
@@ -403,6 +412,7 @@
     }
     if (temp == 'm') {
         pc.printf("\n\n\n\n\r\tCurrent high_time trim = 0x%2.2X  & low_time trim = 0x%2.2X",high_time_prog,low_time_prog);
+        pc.printf("\n\n\r\tSuggestion - Change high_trim first then low_trim");
         flag1 = 0;
         while (!flag1) {
             pc.printf("\n\n\r\tEnter new high_time trim in hex (00 to ff): 0x");
@@ -418,43 +428,62 @@
         pc.printf("\n\n\r\tProgramming new high_time trim = 0x%2.2X  & new low_time trim = 0x%2.2X",high_time_prog,low_time_prog);
         goto osc_trim;
     }
-    
-    pc.printf("\n\n\r\tDisabled 'fc_enable' & driver1.");     
-    i2c_write_fn(&i2c,0x0c,0x00); 
+    i2c_write_fn(&i2c,0x17,0x00); //DATA2_CLK pulled to GND 
+    i2c_write_fn(&i2c,0x10,0x04); //tm_ProgSamp_en = 1, needed to disable pull-up device between VINA & PROG        
+    pc.printf("\n\n\r\tDATA2_CLK pulled low");     
     wait_ms(delay2); 
     pc.printf("\n\n\n\r\tAll set to program the EasyFuse, time to blow up some ploy fuses! ..**BOOOM**\n\n\r"); 
+
+    temp = 0;
+    pc.printf("\n\n\n\r\tConnect PROG to 4.5V & VINA to 5V and press 'c' to continue"); 
+    while ( temp!='c') {
+        temp = pc.getc();
+    }
     i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_PWR_ON); //turn ON supply to EasyFuse
     wait_ms(100);    
-    i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_RESET); //turn ON supply to EasyFuse & RESETN = 1
+    i2c_write_fn(&i2c,NVM_CTLR_ADR,(NVM_RESET + NVM_PWR_ON)); //turn ON supply to EasyFuse & RESETN = 1
     wait_ms(1);
     i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_PWR_ON); //RESETN = 0, Prog mode enabled: CKL1 = 0 during RESETN = 0,
-    temp = 0;
-    pc.printf("\n\n\n\r\tConnect PROG to 5V and press 'c' to continue"); 
-    while ( temp!='c') {
-        temp = pc.getc();
-    }    
+    
+    pc.printf("\n\n\n\r\t");
     wait_us(delay2);
-    i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_RESET);  //RESETN = 1,
+    i2c_write_fn(&i2c,NVM_CTLR_ADR,(NVM_RESET + NVM_PWR_ON));  //RESETN = 1
     wait_us(delay2);           
     for ( i = 0; i < 64; i = i+1) {
-        temp =  NVM_RESET + (((NVM_data>>i) & 0x01)?(NVM_PWE1):0); //NVM_PWE1 if NVM_data[i]=1 & CLK1 de-asserted
+        if ( ((NVM_data>>i) & 0x0000000000000001) == 1 ) {
+            temp = NVM_PWE1;
+            pc.printf("1");
+        }
+        else { 
+            temp = 0x00;
+            pc.printf("0");
+        }
+        temp =  (temp | NVM_RESET | NVM_PWR_ON); //NVM_PWE1 if NVM_data[i]=1 & CLK1 de-asserted
+        //pc.printf("\n\n\n\n\r\ttemp = 0x%2.2X",temp);
         i2c_write_fn(&i2c,NVM_CTLR_ADR,temp);
-        wait_us(delay2);
-        temp =  NVM_RESET;
+        //wait_us(delay2);
+        temp =  (NVM_RESET | NVM_PWR_ON);
         i2c_write_fn(&i2c,NVM_CTLR_ADR,temp); //de-assert NVM_PWE1
         wait_us(delay2);          
-        temp =  NVM_RESET + NVM_CLK1;
+        temp =  (NVM_RESET | NVM_CLK1 | NVM_PWR_ON);
         i2c_write_fn(&i2c,NVM_CTLR_ADR,temp); //assert CLK1
         wait_us(delay2); 
     }
+
     pc.printf("\n\n\n\r\t\a\033[%dm", 44);//change backround to blue
-    pc.printf("Finished programming. Let us confirm if the NVM has been programmed correctly by reading the NVM. Proceed (y/n): ");
+    //pc.printf("Finished programming. Let us confirm if the NVM has been programmed correctly by reading the NVM. Proceed (y/n): ");
+    pc.printf("Finished programming. Let us confirm if the NVM has been programmed correctly by reading the NVM.");    
     pc.printf("\033[%dm", 40);//change backround to black 
-          
-    temp = 0;
-    while ( temp!='y' ) {
+    pc.printf("\n\n\n\r\tReduce PROG to 4.2V & VINA to 4.2V and press 'c' to continue");     
+    while ( temp!='c') {
         temp = pc.getc();
-    }
+    }        
+    i2c_write_fn(&i2c,0x10,0x00); //tm_ProgSamp_en = 0,    
+    wait_ms(1);          
+    //temp = 0;
+    //while ( temp!='y' ) {
+    //    temp = pc.getc();
+    //}
     NVM_read_data = EasyFuse_read(&i2c);
     if ( NVM_data == NVM_read_data ) pc.printf("\n\n\r\tData written into NVM matches data read from NVM\n\n\n\r\t\033[%dm NVM PROGRAMMING SUCESSFULL. Hoorayyy!\a \033[%dm\n\r",44,40);
     else  pc.printf("\n\n\r\tuh-oh.. Data written into NVM does not match data read from NVM\n\n\n\r\t\033[%dm NVM PROGRAMMING FAILED!\a \033[%dm\n\r",41,40);