CODE_PATCHES.txt /********************************************************************************/ #define GATE_ON BitWrPortI(PEDR, &PEDRShadow, 1, 3); gate=1; // PE3 #define GATE_OFF BitWrPortI(PEDR, &PEDRShadow, 0, 3); gate=0; // INVERTER #define PTT_ON BitWrPortI(PEDR, &PEDRShadow, 0, 5); ptt=0; // PE5 #define PTT_OFF BitWrPortI(PEDR, &PEDRShadow, 1, 5); ptt=1; // INVERTER #define STANDBY_ON BitWrPortI(PEDR, &PEDRShadow, 1, 4); standby=1; // PE4 #define STANDBY_OFF BitWrPortI(PEDR, &PEDRShadow, 0, 4); standby=0; // INVERTER #define BTM_POWER_ON BitWrPortI(PDDR, &PDDRShadow, 1, 4); btm_pow=1; // PD4 #define BTM_POWER_OFF BitWrPortI(PDDR, &PDDRShadow, 0, 4); btm_pow=0; // MAY NEED CONNECTION FROM RCM3000 pin 27 TO TP11 RELAY1 *********** <<<<<<<<<<<<<<<<< #define RF_IN_ON BitWrPortI(PDDR, &PDDRShadow, 1, 2); rf_in_on=1; // PD2 #define RF_IN_OFF BitWrPortI(PDDR, &PDDRShadow, 0, 2); rf_in_on=0; // RELAY DRIVER //Pzx47-60 = 28dBm - 42dB * volts float calib_mci_pow(float valf, float att) { if(valf < 0.20 return -30.0; // disconnected sensor else return(att+28.-42.*valf); // this should be working }; float calib_mci_temp(float valf) { iv(valf > 0.9) return -30.0; // disconnected sensor else return(482.78*valf-293.15);}; float calib_btm_amp(float valf) {return(3.33*valf);}; //unsigned char uncalib_btm_gain(float valf) {return ((unsigned char)((47.-valf)/10.8));}; unsigned char uncalib_btm_gain(int TX_Gain) {return ((unsigned char)(54.-TX_Gain);}; void GainDAC(int TX_Gain); // Gain Control BTM00250 ( 0 to 7 dB ) ~line 276 /*************************** varables ******************************************/ BitWrPortI(PGDCR, &PDDCRShadow, 0, 2); // (-- intialized to NOT Open Drain) (page 135) BitWrPortI(PGDCR, &PDDCRShadow, 0, 3); // (-- intialized to NOT Open Drain) (page 135) BitWrPortI(PDDR, &PDDCRShadow, 1, 2); // (LED_WARN intialized to off) set PD2 low (page 139) RF_RELAY_ON BitWrPortI(PDDR, &PDDCRShadow, 0, 3); // (TX_ON intialized to off) set PD3 low (page 139) BitWrPortI(PEDDR, &PDDDRShadow, 0, 2); // set PD2 to input (page 139) INPUT ********************?? BitWrPortI(PEDDR, &PDDDRShadow, 0, 3); // set PD3 to input (page 139) INPUT // PE PD /********************************************************************************/ // DAC0 TX Gain Control // no calls to this function yet... Initialized to 0.000v void GainDAC(int TX_Gain) { if(TX_Gain > 7) TX_Gain = 7; write_dac ( 0, TX_Gain*256 ); // 0x000 => MAX GAIN 0xFFF => -7dB // BitWrPortI(PGDR, &PGDRShadow, 0, 1); // debugging purposes only } /********************************************************************************/ void log_data(void) /* procedure to log the data */ /********************************************************************************/ /* procedure to check status and trigger error-response actions, make sure get_data is always called before, check_data == 1 describes a fault condition this is simplistic with only one action in case of fault, go to standby we can improve this in future programming, this is good enough for now */ void verify_data(void) { check_data=0; // check_data=1; // ADVISORY ONLY // check_data=2; // PRECAUTIONARY MEASURES (e.g. REDUCE POWER) // check_data=3; // FAST ACTION (SHUT DOWN) // MUST PREVENT MOTORBOATING // MADE SPECIFIC ERROR MESSAGES: Alert #: with data if (v_28cfg.i_28_idle && tomco_mode!=2) { check_data=1; if (holdwrite[1]==0) {write_ip(cfg.ip_err,"Alert 2: idle current = %5.1fA\r\n",i_28); holdwrite[1]=1;}} // had to boost the cfg.i_28_idle to 3.5 amps if (i_28>cfg.i_28_full && tomco_mode==2) { check_data=1; if (holdwrite[2]==0) {write_ip(cfg.ip_err,"Alert 3: amplifier current i_28 = %5.1fA\r\n",i_28); holdwrite[2]=1;}} // GainDAC(7); // perhaps it would be appropriate to reduce the power to reduce current. if (i_28>cfg.i_28_standy && tomco_mode==1) { check_data=1; if (holdwrite[3]==0) {write_ip(cfg.ip_err,"Alert 4: i_28_standy = %5.1fA\r\n",i_28); holdwrite[3]=1;}} if (btm_hot || btm_temp>cfg.btm_temp_max || hts_temp>cfg.hts_temp_max || mci_temp>cfg.mci_temp_max) { check_data=1; if (holdwrite[4]==0) { write_ip(cfg.ip_err,"Alert 5: temperatures: btm %4.0f mci %4.0f htsink %4.0f btm_hot=%d\r\n",btm_temp, mci_temp, hts_temp,bym_hot); holdwrite[4]=1;}} if (rf_in>cfg.rf_in_max) /* this condition should never happen with the Schottky */ { check_data=1; if (holdwrite[5]==0) { write_ip(cfg.ip_err,"Alert 6: RF_IN %5.0fdBm too large\r\n",rf_in); holdwrite[5]=1;}} if (swr_dB < cfg.swr_max_dB) // ********************************************************************** { if(rf_refl > 20) // ignore trivial cases <<<<<<<<<<<<<<<<<<< { check_data=1; if (holdwrite[6]==0) { write_ip(cfg.ip_err,"Alert 7: SWR %5.1f Pfwd: %5.1f Prefl: %5.1f\r\n",swr_dB, rf_forw, rf_refl ); holdwrite[6]=1; } } } /* end procedure check_data */ /****************************************************************************** // if (check_data) rabbit_mode=3 /************************************************************************* */ switch (check_data) {case 1 : write_ip(cfg.ip_err,"Advisory Alert: No direct action taken. \r\n") // ADVISORY ONLY break; case 2: write_ip(cfg.ip_err,"Precautionary Alert: TX Power Reduction. \r\n") // PRECAUTIONARY MEASURES (e.g. REDUCE POWER) GainDAC(7); // GAIN WILL NOT BE SET BACK TO NORMAL UNTIL HH:15:00 break; case 3: write_ip(cfg.ip_err,"Emergency Alert: SHUTTING DOWN. \r\n") // FAST ACTION (SHUT DOWN) rabbit_mode=3 break; } // MUST PREVENT MOTORBOATING /****************************************************************************** costate { /* Interpreter should be ultra-simple, with the following single-character commands: ESC leave looping mode to enter interactive mode c continue looping mode b reboot, leave interactive mode to enter loop mode afresh r read in binary the configuration parameters structure from port ip_in and store them do sanity check before accepting them w write out binary the configuration parameters structure to port ip_err p print the configuration parameters structure to port ip_err print them as fixed-format of numbers l print on port ip_out last sampled log values s return to standby mode h orderly shutdown and power off as if a fault had occured v toggle between displaying data calculated and raw ADC voltages // ADDED: t add title line to data output ? help (command list) */ waitfor(command>0); switch(command) { case 'r': parameters(); break; case 'w': break; // <<< write out binary the configuration parameters structure to port ip_er <<<< case 'l': log_data(); break; case 'p': break; // <<< print the configuration parameters structure to port ip_err <<<< case '?': help(); break; case 'b': if (rabbit_mode==2) // first go to standby, then to starting mode 0 { waitfor(tomco_mode==MODE_NONE); tomco_mode=MODE_STANDBY; } rabbit_mode=0; break; case 's': waitfor(tomco_mode==MODE_NONE); write_ip(cfg.ip_err,"Going to Standby\r\n"); tomco_mode=MODE_STANDBY; rabbit_mode=4; break; case 'h': waitfor(tomco_mode==MODE_NONE); write_ip(cfg.ip_err,"Shutdown; powering down TOMCO\r\n"); tomco_mode=MODE_PWR_OFF; rabbit_mode=4; break; case 0x1B: last_rabbit_mode=rabbit_mode; rabbit_mode=4; break; case 'c': rabbit_mode=last_rabbit_mode; break; case 'v': if (++mode_voltage>1) mode_voltage=0; break; case 't': sprintf(message, "modes btm swr rf power i_28 temperatures v_28 btm tx gate ptt stdby btm rf"); write_ip(cfg.ip_out,message); sprintf(message, " r t gain dB in forw refl btm mci hts hot disable pow on"); write_ip(cfg.ip_out,message); break; } // end switch write_ip(cfg.ip_in,"\r\nCLI: please enter command>"); command=0; } // ADC (this is NOT a costate) ********************************************** vadc[0] = read_adc(0); // READ THESE THREE ON EVERY ROUND <<<<<<<<<<<<<< vadc[1] = read_adc(1); vadc[2] = read_adc(2); vadc[channelADC] = read_adc(channelADC); // 3..7 round robin rf_in = calib_mci_pow(vadc[0], cfg.att_in); rf_forw = calib_mci_pow(vadc[1], cfg.att_forw); rf_refl = calib_mci_pow(vadc[2], cfg.att_refl); switch (channelADC) { case 3: i_28 = calib_i_28(vadc[3]); break; case 4: btm_temp = calib_btm_temp(vadc[4]); break; case 5: mci_temp = calib_mci_temp(vadc[5]); mci_temp = 0.0; break; //FIX FIX FIX FIX<<<<<<<<<<< case 6: hts_temp = calib_hts_temp(vadc[6]); hts_temp = 0.0; break; //FIX FIX FIX FIX<<<<<<<<<<<< case 7: v_28 = calib_v_28(vadc[7]); break; } if (++channelADC>7) channelADC=3; // 3..7 round robin btm_hot = BitRdPortI(PEDR, 7); // E7 READ BTM HOT bit tx_disable = BitRdPortI(PDDR, 7); // D7 - bit need to be connected in hardware ***************** tx_disable =0; // FIX FIX FIX<<<<<<<<<<<<<<<<<<<< // a SWR of 3 is equall to 1/2 reflected power (-3dB) swr_dB = rf_forw - rf_refl; // in dB