CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

CCS compiler overwriting SFRs

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Zezem



Joined: 02 Mar 2017
Posts: 7

View user's profile Send private message

CCS compiler overwriting SFRs
PostPosted: Mon Jun 25, 2018 4:39 pm     Reply with quote

I'm pretty sure I saw something related to this on this forum and was just wondering if someone had an solution.

Right now I have a program that keeps assigning float variables to weird memory addresses. They are trying to store them in SFR locations 0xF81-0xF83.

Because of this the float values aren't being written to and always outputting 0.0000.

If I make a duplicate of the floating points giving me my problem, and just leave the original variables untouched. The duplicate floating points will get assigned a proper register value and everything will work fine.

I read somewhere on here that it might be my compiler version but I was seeing if there was another way to fix this problem.

compiler version 5.046


Code:

F81-F84 pump_voltage
F81     PORTB
F81.1   WRITE
F82-F85 _24VDC
F82.0   READ
F82     PORTC
F82.7   Test_Pin
F83     PORTD
F84     PORTE
F85-F88 pump_current
F89     LATA
F8A     LATB
F8B     LATC
F8C     LATD


Code:

 //==================================================================================================
//      Filename: MAIN.C
// Function Name: main()
//        Author: PGS
//
//   Description: Main loop of Flow Cell Control uP  PIC18F26K22
//   
//=================================================================================================

#include "18F26k22.h"
#device ICD=TRUE
#fuses HSM, WDT, PUT, NOPLLEN, BROWNOUT, CCP2C1, PROTECT

//#include "Flow_Params.h" 
//#include "f_proto.h"
#include "globals.h"
#include "defines.h"
#include "f26k22_regs.h"
#include "math.h"
#include "stdlib.h"

#id CHECKSUM
#use delay(clock=4000000, RESTART_WDT)
#use standard_io(B)
#use standard_io(C)
#use rs232(baud=1000,FLOAT_HIGH,xmit=PIN_B1,rcv=PIN_C0)

//#include "Flow_Params.h"
#include "init.c"
#include "isr_t1.c"
//#include "i2c.c"
//#include "wr_1803.c"     //Write/Read to DS1803 Digital Pot
//#include "medley.c"      //Misc utilities, mostly pot adjustments for temp/pressure
                    //compensation
//#include "RS232_RXTX.c"  //"White Wire Interface" functions and commands
#include "ad_read.c"     //A->D read utility, called by "rd_sig.c"
#include "rd_sig.c"      //Reads one of 10 analog channels "read_a_signal(CH)"
                         //Also adjusts Pot settings "set_a_signal(CH)"
//#include "cal_sw.c" 

//#include "wr_unit_param.c"
//#include "rd_unit_param.c"
#include "Err_Chk.c"

//#include "Param_Default_Flow.h"

// static byte stored_error_code;
// static byte stored_unit_status;
// static short main_fault_sw_status;
// int8 degrees_modulator=0, offset;
 int16 degrees_raw, prev_degrees_raw=0;
 int16 pump_voltage_raw;
 int16 _24VDC_raw;
 int16 pump_current_raw;
 int16 temp16;

// *****************************************************************
//                       MAIN()
// *****************************************************************
void main(void)
{
// int8 temp8;
  int8 bytes_recvd;

  initialize();
//  read_eeprom_data();    // get stored calibration values
  restart_wdt();

  //temp8 = compute_checksum();
  //delay_us(1);
/*                                       // check after 1st eeprom read
  if(header_byte != HEADER_BYTE_VALUE)
    error_code1= ERR_EEPROM_HEADER_BYTE;
  else if(eeprom_checksum != compute_checksum())
    error_code1= ERR_EEPROM_CHKSUM;

  if(error_code1)                        // power-up fault on 1st read?
   {
    error_code1= CLEAR;                  // clear error code from 1st read
    read_eeprom_data();                  // read eeprom 2nd time FIX
    restart_wdt();
                                        // check after 2nd eeprom read
    if(header_byte != HEADER_BYTE_VALUE)
      error_code1= ERR_EEPROM_HEADER_BYTE;
    else if(eeprom_checksum != compute_checksum())
      error_code1= ERR_EEPROM_CHKSUM;

    if(error_code1)                      // power up fault on 2nd read?
      Restore_Factory_Param();   
   }
  err_check();
*/ 
  GIE = OFF;
  //unit_status = 0;

//================================================================================
//=====================================MAIN LOOP==================================
//================================================================================
 for(;;) //MAIN LOOP
  {
   restart_wdt();

Test_Pin = ~Test_Pin;
 
//===================== Read Temperature ===================================
//current degrees is 10 bit number, LM50=10mv/degree C on a 0.5V bias
   degrees_raw= (read_a_signal(RD_TEMP));  // Read LM50
   degrees3= (float)((degrees_raw + prev_degrees_raw) / 2);
   prev_degrees_raw = degrees_raw;
   degrees3 *= .00488;   // .00488 = 5 / 1024...convert to voltage     
   degrees3-= 0.5;  //subtract off .5V bias
   degrees3/=.01;  // 10mV per degree C                Floating Point DEGREES
 
   TEMP_HIGH_ERR_ACTIVE = NO;
   TEMP_LOW_ERR_ACTIVE = NO;
   if(degrees3 > 75)
     TEMP_HIGH_ERR_ACTIVE = YES;
   if(degrees3 < -40)
     TEMP_LOW_ERR_ACTIVE = YES;
restart_wdt();

 
 //==================== Read +24VDC ============================================
 //Vf = V(RA2) * 10.3 * 5 / 1024,   1(1 / 10.3 / 5 * 1024) = .0503 volts per step
   _24VDC_raw = read_a_signal(RD_24VDC);
   _24VDC3 = ((float)_24VDC_raw) * .0503;
   _24VDC3 += .7;  // reverse polarity diode                //floating point 24VDC

   _24V_HIGH_ERR_ACTIVE = NO;
   _24V_LOW_ERR_ACTIVE = NO;
   if(_24VDC3 > 30)
     _24V_HIGH_ERR_ACTIVE = YES;
   if(_24VDC3 < 18)
     _24V_LOW_ERR_ACTIVE = YES;
restart_wdt();

 //====================== Read Pump Voltage ======================================
 //Vp = V(RA1) * 5 * 5 / 1024,  1(1 / 5 / 5 * 1024) = .0244 volts per step
   pump_voltage_raw = read_a_signal(RD_PUMP_VOLTAGE);
   pump_voltage3 = (float)pump_voltage_raw * .0244;    //floating point PUMP VOLTAGE

   _12V_HIGH_ERR_ACTIVE = NO;
   _12V_LOW_ERR_ACTIVE = NO;
   if(pump_voltage3 > 14)
     _12V_HIGH_ERR_ACTIVE = YES;
   if(pump_voltage3 < 11)
     _12V_LOW_ERR_ACTIVE = YES;
restart_wdt();


//========================= Read Pump Current ======================================
//V(RA5)= 11I   I = V(RA5) / 11 * 5 / 1024, 1(11 / 5 * 1024) = .000444 Amps per step
   pump_current_raw = read_a_signal(RD_PUMP_CURRENT);
   pump_current3 = (float)pump_current_raw * .000444; //floating point PUMP CURRENT

restart_wdt();

//============================= Pump Power ===========================================
   pump_voltage3 = pump_voltage3 - (1 * pump_current3); //Subtract off voltage drop across
                                                     //current sense resistor (1 Ohm)(Ip)
   pump_power3 = pump_current3 * pump_voltage3;         //floating point PUMP POWER

temp16 = 0; 
while(temp16++ < 0x7A12);
    delay_us(1);

 } //end of for(;;)
   
} //End of Main
 

//*********************************************************************************
//*********************************************************************************

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 25, 2018 5:32 pm     Reply with quote

Your posted code doesn't compile because of various missing items.
How are we going to solve this if we don't have a compilable test program
to look at ?
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jun 25, 2018 6:30 pm     Reply with quote

Along with what PCM P says...
just some observations...

1) why the cryptic 0x7A12 when a simple delay_us(31250); will work and show how long the delay is ?

2) enabling the WDT should only be done in the final version of code

3) since you have ICD=TRUE, that will alter the overall operation of the PIC and the code

4) running the PIC at 4 MHZ seems 'silly' to me, especially with the number of floating point calculations the program has.They along might actually trip the WDT

5) some lines are commented out,well a lot of them,along with a lot of 'includes'. ALL 'commented out' code should be deleted in a posted program. One of those 'less is better' ideas. It helps others concentrate on real code and not get distracted with stuff that isn't happening in the PIC.

6) anytime you have a #use RS232(...options..) you need to add 'ERRORs' to the option list when using the HW UARTs.

7) I don't see where any of the float variables are 'defined ' IE: you have int16 degrees_raw before main() but no float degrees3. I've seen it said here that the compiler requires variables defined( or whatever the term is, I'm NOT a student of C) before main().

8) I don't know(since I seldom use floating points) , but when you do a compare,say if(pump_voltage3 >14), is the '14' converted to the floating point 14.0000 ? To me 14 and 14.0000 can be 2 different numbers within the code and the PIC.

What I do know is that integers, even scaled integers are a LOT faster for the PIC to handle especially using a 'snail slow' 4MHz clock.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Tue Jun 26, 2018 12:08 am     Reply with quote

One other comment. All of these:
Code:


//#include "Flow_Params.h"
//#include "f_proto.h"
#include "globals.h"
#include "defines.h"
#include "f26k22_regs.h"
#include "math.h"
#include "stdlib.h"


Should be _after_ you have setup the delays and RS232.

The standard layout for reliability, is:
Processor include
Fuses
Timing setup
any #pin_select if applicable
#use statements
_then_ the includes.

In this case WDT won't trigger, since with ICD selected this will be turned off. However if it was there could be a problem. The watchdog on this chip (worst case) triggers in just 3.5mSec. Your maths on the reading:
addition
division by 2
multiplication by 0.00488
subtraction
division by 100

at 4Mhz, takes 513uSec+1449uSec+358uSec+523uSec+1449uSec = 4292uSec. Not even allowing any time for actually reading and saving the variables. Result on a real chip the watchdog would trigger.....

Just work in integer. Use signed int16 values. Then:
Code:

    adc_val=//However you read the adc. You don't actually show the code
    adc_val*=49;
    adc_val-=5000;


No averaging shown. Honestly better to do this by taking two readings rather than 'carrying forward' the last reading each time.

Now this gives 100 counts per degree. So 125 degrees is 12500 counts. If you think about it the sensor gives 1.75v at 125C. This is 358 counts on the ADC. 358*49 = 17542. Subtract 5000 gives 12542. Nominally 125.42C. One int16 multiplication and one subtraction. Takes 36uSec against the 4.3mSec!... 120* faster (and smaller code as well). Error in the maths only about 0.3%. Given the sensor itself only claims 3% accuracy, far better than is needed.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jun 26, 2018 4:43 am     Reply with quote

Thank Mr T for posting the 'how and why' reply ! Should be a sticky. Anyone wanting to do floating point should read your post !! I knew FP was slow ,but well over 100 TIMES slower !! It should be a real eye opener to every programmer !!
Zezem



Joined: 02 Mar 2017
Posts: 7

View user's profile Send private message

PostPosted: Tue Jun 26, 2018 8:05 am     Reply with quote

Thanks for the awesome support guys!

To be honest this is my boss's code. He is a smart man but the way he writes code is very old school and can be a pain to follow.

I will talk to him today and make some changes to increase performance. I still don't understand why the compiler would give these floating points weird addresses that are already used by SFRs. I can switch to int16 instead of floats but I'm just curious how this happened?

PORTB location 0xF41
pump_voltage address location = 0xF41

Code:

//==================================================================
//      Filename: GLOBALS.H
// Function Name: na
//        Author: PGS
//
//   Description:
//    Parameters:
//                Input: None.
//               Output: None.
//===================================================================
 int16 current_seconds;
 int16 calsw_snapshot;
 signed int16 Drift_Array_CH0[16];
 signed int16 Drift_Array_CH1[16];

 int8 quarter_seconds;
 int1 LED_Enable;
 int1 comm_ready;
 int1 Wait_For_Int;

 int8 block0[256];
 byte header_byte;        // after write to eeprom, holds 0xAA
 byte unit_status;        // shows current status of unit
 byte error_code1;        // holds 1st priority err if >0, else none
 int8 error_code2;
 int8 Device_Code_L,Device_Code_H;
 int16 norm_value;


//             Global Status Bits
// Permanent Unit Status. Stored to EEPROM. Read from EEPROM at Boot (WR_CALS, RD_CALS)

 byte config_byte;   // Config Status CH0                         
// Pat's version has the following statement changed from "UNIT_ZEROED_ONCE".
 #bit UNIT_ZEROED_CH0      = config_byte.0  // unit has ONCE been zeroed @ 26C
 #bit UNIT_SPANNED_CH0     = config_byte.1  // unit is currently zeroed @ 26C
 #bit HOT_ZEROED_CH0      = config_byte.2
 #bit COOL_ZEROED_CH0      = config_byte.3
 #bit COOL_ZERO_SLOPE_CH0   = config_byte.4
 #bit HOT_ZERO_SLOPE_CH0   = config_byte.5
 #bit FCR_TABLE_LOADED_CH0   = config_byte.6
 //#bit       = config_byte.7  // unit has ONCE been spanned
       
// Pat's version has several bits in config_byte and config2_byte different
// than in Steve's version.
 byte config2_byte;      // Config Status CH0
 #bit UNIT_ZEROED_CH1      = config2_byte.0  // unit has ONCE been zeroed hot
 #bit UNIT_SPANNED_CH1      = config2_byte.1
 #bit HOT_ZEROED_CH1      = config2_byte.2  // unit is currently zeroed hot      
 #bit COOL_ZEROED_CH1      = config2_byte.3  // unit currently zeroed cool @ <+3C
 #bit COOL_ZERO_SLOPE_CH1   = config2_byte.4 
 #bit HOT_ZERO_SLOPE_CH1   = config2_byte.5 
 #bit FCR_TABLE_LOADED_CH1   = config2_byte.6  // COOL bal. factor slope, 1=Pos/0=Neg
//     = config2_byte.7  // HOT bal. factor slope, 1=Pos/0=Neg
 

 
//**********************************************************************************
//Global Temperature Value. This is the DS1775(2's comp) value added to 45. We add 45
//to keep numbers positive over entire operating range(-40 to 85)
//This format is used for all internal calculations.
//Actual temp value (2's comp) is returned as "Unit Temp"
//unsigned int8 degrees; //, last_degrees;
float test;

float degrees;
float pump_voltage;
float _24VDC;
float pump_current;
float pump_power;

float degrees3;
float pump_voltage3;
float _24VDC3;
float pump_current3;
float pump_power3;

//**********************************************************************************

                       
//**********************************************************************************           
//Holds run-time calculated EEPROM checksum
//Compared to EEPROM stored checksum
 byte eeprom_checksum;
//**********************************************************************************

 int8 cmmd_string[4];             // holds RS232 (White Wire) TX & RX bytes

 byte _24vdc_rd_value;


//***********************************************************************************
//unions used to construct larger variable types from bytes
//Kept gloabal since they are generally read and written over White Wire interface
//***********************************************************************************
 union word1            // [0] locations for fine adjustment pot   (L_byte)
 {                      // [1] locations for coarse adjustment pot (H_byte)
  long word_data;          // BAL_value.word_data
  char byte_data[2];       // BAL_value.byte_data[0] or [1]
 } BAL_value;

 union word2
 {                         // Warm-Up time expressed in seconds (32767 max)
  signed long word_data;   // Used in "Main"
  int8 byte_data[2];       // Configurable over white wire, stored in EEPROM
 } WARMUP_value;

 union word4           
 {                     
  int16 word_data;          // CAL_value.word_data
  int8 byte_data[2];       // CAL_value.byte_data[0] or [1]
 } CAL_value;

 union word6           
 {                     
  int16 word_data;          // RANGE_value.word_data
  int8 byte_data[2];       // RANGE_value.byte_data[0] or [1]
 } RANGE_value;

 union word7
 {
  long word_data;          // SPAN_value.word_data
  char byte_data[2];       // SPAN_value.byte_data[0] or [1]
 } SPAN_value;
 
 union word8
 {
  long word_data;          // SERIAL_num.word_data
  char byte_data[2];       // SERIAL_num.byte_data[0] or [1]
 } SERIAL_num;
 
// union word15
// {                         // used to relay actual pot values in main
//  long word_data;          // DP_value.word_data
//  char byte_data[2];       // DP_value.byte_data[0] or [1]
// } DP_value;

 union word16
 {                         // month and day on which unit was last calibrated
  long word_data;          // CALIBRATION_DATE.word_data
  char byte_data[2];       // CALIBRATION_DATE.byte_data[0] or [1]
 } CALIBRATION_DATE;

 union word17
 {                         // used as scratch pad in various functions
  long word_data;          // scratch_value.word_data
  char byte_data[2];       // scratch_value.byte_data[0] or [1]
 } SCRATCH_value;
 
 
 
//union word22   Used in "read_ad"
 
/*
 union word64
 {
  float word_data;  //Used for Ideal Gas Law Calculations (medley.c)
  int8 byte_data[4];
 } Kelvin_degrees;
*/

//91,92,93,94 used for test parameters

union word95
 {
  int16 word_;
  int8  byte_[2];
 } CH0_Buffer_Size;

union word96
 {
  int16 word_;
  int8  byte_[2];
 } CH1_Buffer_Size;

// *****************************************************************
//                GLOBAL FLAG VARIABLES
// Temporary Unit Status bits. Set, cleared, and read during run-time.
// Not stored to EEPROM
// *****************************************************************
// Pat's version has several changes to this section.

 byte flag_byte1;
 #bit ZERO_SWITCH     = flag_byte1.0  // a flag to zero calibrate unit
 #bit SPAN_SWITCH     = flag_byte1.1  // a flag to span calibrate unit
 //#bit HOT_ZERO_SW_CH0     = flag_byte1.2  // a switch to Hot Zero unit
 #bit FAULT_ABORT_SWITCH  = flag_byte1.3  // a flag to abort fault routine
 #bit MAIN_FAULT_SWITCH   = flag_byte1.4  // an error occurred in main
 #bit CONFIG_BYTE_SWITCH  = flag_byte1.5  // a flag to adjust config byte
 #bit FOUR_20MA_SWITCH    = flag_byte1.6  // a flag to engage in 4-20ma cal
// #bit COOL_ZERO_SW_CH0    = flag_byte1.7  // a switch to Cool Zero unit

 byte flag_byte2;
 #bit LD_BAL_POT_SWITCH      = flag_byte2.0  // a flag to load actual pot value
 #bit LD_AGC_POT_SWITCH_0    = flag_byte2.1  // a flag to load actual pot value
 #bit LD_SPAN_POT_SWITCH     = flag_byte2.2  // a flag to load actual pot value
 #bit STORE_SN_SWITCH        = flag_byte2.3  // a flag to store SN# in eeprom
 #bit STORE_CAL_DATE_SWITCH  = flag_byte2.4  // a flag to store cal date info
 #bit SOURCE_ENABLED         = flag_byte2.5  // a enable's or disable's source
 #bit NO_TEMP_ERROR          = flag_byte2.6  // a flag to check if temp error
 #bit STORE_BITSBYTE_SWITCH  = flag_byte2.7  // a flag to store bits byte
/*
 byte flag_byte3;
 #bit LOAD_TABLE_0_SWITCH    = flag_byte3.0  // if set, read in table one
 //#bit LOAD_TABLE_1_SWITCH    = flag_byte3.1  // if set, read in table two
 #bit RD_TABLE_0_CS_SWITCH   = flag_byte3.2  // read table one checksum switch
 #bit BAL_SLOPE_BIT          = flag_byte3.3  // returns slope to calling function
 #bit STORE_TARGET_TEMP_SW   = flag_byte3.4  // store temp control target temp
 #bit ZERO_CH1_SWITCH        = flag_byte3.5  // a flag to...
 #bit SPAN_CH1_SWITCH        = flag_byte3.6  // a flag to...
 //#bit CH_SELECT              = flag_byte3.7  // 0=CH0, 1=CH1

 byte flag_byte4;
 //#bit     = flag_byte4.0 
 //#bit     = flag_byte4.1 
 //#bit     = flag_byte4.2
 //#bit      = flag_byte4.3   
 //#bit     = flag_byte4.4   
 //#bit     = flag_byte4.5   
 #bit HOT_ZERO_SW_CH0        = flag_byte4.6  //
 #bit COOL_ZERO_SW_CH0       = flag_byte4.7  //
*/
byte flag_byte5;
 //#bit RD_TABLE_1_CS_SWITCH   = flag_byte5.0
 #bit HOT_ZERO_SW_CH1        = flag_byte5.1
 #bit COOL_ZERO_SW_CH1       = flag_byte5.2
 #bit OK_TO_HZ             = flag_byte5.3 //Temp OK, Unit Status OK for Hot Zero
 #bit OK_TO_CZ             = flag_byte5.4
 #bit SELF_TEST_SW           = flag_byte5.5
 #bit ABORT_TEST_SW          = flag_byte5.6
 #bit Abort_Warm_Up          = flag_byte5.7
/*
byte flag_byte6;
 #bit Reset_CH0_Buf_Zero      = flag_byte6.0
 #bit Reset_CH0_Buf_Span      = flag_byte6.1
 #bit Reset_CH1_Buf_Zero      = flag_byte6.2
 #bit Reset_CH1_Buf_Span      = flag_byte6.3
 #bit Reset_CH0_Drift_Array      = flag_byte6.4
 #bit Reset_CH1_Drift_Array      = flag_byte6.5
 #bit Err_CH0                  = flag_byte6.6                   
 #bit Err_CH1                 = flag_byte6.7

byte flag_byte7;
 #bit Pres_Table_Loaded_CH0      = flag_byte7.0 //Run time flag, updated
// #bit Pres_Table_Loaded_CH1      = flag_byte7.1 //during "load_cal_factors"
 #bit Valid_Pres_Input         = flag_byte7.2
 #bit Pres_En_Global_CH0      = flag_byte7.3
// #bit WR_COMP_SWITCH         = flag_byte7.4
// #bit WR_SPAN_CH0_SW         = flag_byte7.5
// #bit WR_SPAN_CH1_SW         = flag_byte7.6
// #bit WR_COMP_STATUS         = flag_byte7.7
*/
byte flag_byte8;
 #bit RANGE_SWITCH               = flag_byte8.0 // 1=Write new Range(EEPROM)
 #bit CAL_VALUE_SWITCH           = flag_byte8.1 // 1=Write new Cal Value
 #bit load_cal_fact           = flag_byte8.2 //
 //#bit        = flag_byte8.3
 //#bit         = flag_byte8.4
 #bit Store_Fact_Param         = flag_byte8.5 //Copies Data E2 to Prog Mem
 #bit Restore_Fact_Param        = flag_byte8.6 //Copies Prog Mem to Data E2
 //#bit         = flag_byte8.3 //
/*
byte flag_byte9;
 #bit checksum_ready         = flag_byte9.0 //Used in read table checksum
 #bit ZERO_CH0_FLAG            = flag_byte9.1 //Zero Command zeros both channels
                                 //This flag set after CH1 Zero...signals CH0 Zero
 #bit COOL_ZERO_CH0_FLAG      = flag_byte9.2
                                 //This flag set after CH1 Cool Zero...signals CH1 Cool Zero
 #bit HOT_ZERO_CH0_FLAG         = flag_byte9.3
                                 //This flag set after CH1 Hot Zero...signals CH0 Hot Zero
 //#bit WR_Drift_Tables_CH0_0      = flag_byte9.4 //Drift Table write done in 4 sections
 //#bit WR_Drift_Tables_CH0_1      = flag_byte9.5 //
 //#bit WR_Drift_Tables_CH1_0      = flag_byte9.6 //
 //#bit WR_Drift_Tables_CH1_1      = flag_byte9.7 //

// Steve added.  This was missing from Pat's file.
unsigned int8 flags_read;   // General purpose flags set by slave and read
                            // by master.
#bit ee_written = flags_read.0  // Flag to tell master that slave had to
                                // write defaults to its EEPROM because
                                // of bad checksum.
*/
// Everything from here on, Pat added.
byte flag_byte10; //Critical Faults
 
 #bit _12V_HIGH_ERR_ACTIVE      = flag_byte10.0
 #bit _12V_LOW_ERR_ACTIVE      = flag_byte10.1
 #bit No_Pressure_Signal      = flag_byte10.2
 #bit TEMP_HIGH_ERR_ACTIVE      = flag_byte10.3
 #bit TEMP_LOW_ERR_ACTIVE      = flag_byte10.4
 #bit _24V_HIGH_ERR_ACTIVE      = flag_byte10.5
 #bit _24V_LOW_ERR_ACTIVE      = flag_byte10.6
 #bit MPL115A2_RD_ERR_ACTIVE   = flag_byte10.7
/*

byte flag_byte11; //Recoverable Faults
 //#bit zero_drift            = flag_byte11.0  //Zero drift
 #bit AGC_POT_MIN            = flag_byte11.1   
 #bit AGC_POT_MAX            = flag_byte11.2
 #bit delayed_zero_drift_0      = flag_byte11.3
 #bit delayed_zero_drift_1      = flag_byte11.4
 //#bit          = flag_byte11.5
 //#bit          = flag_byte11.6
 //#bit          = flag_byte11.7
*/

byte flag_byte12;
 #bit Optical_Problem         = flag_byte12.0
 #bit CRITICAL_FAULT_SW         = flag_byte12.1
 //#bit Comp_out_of_range      = flag_byte12.2


byte flag_byte13;
 #bit Wr_Zero_Param            = flag_byte13.0 //Flags for EEProm Writes
 #bit Wr_Span_Param            = flag_byte13.1
 #bit Wr_Hot_Zero_Param_CH0      = flag_byte13.2
 #bit Wr_Cool_Zero_Param_CH0   = flag_byte13.3
 #bit Wr_Zero_Param_CH1         = flag_byte13.4
 #bit Wr_Span_Param_CH1         = flag_byte13.5
 #bit Wr_Hot_Zero_Param_CH1      = flag_byte13.6
 #bit Wr_Cool_Zero_Param_CH1   = flag_byte13.7
/*

byte flag_byte14;
 #bit WR_Four_Ma_Value         = flag_byte14.0
 #bit WR_Span_Ma_Value         = flag_byte14.1
 #bit WR_COMP_SWITCH         = flag_byte14.2
 #bit WR_SPAN_CH0_SW         = flag_byte14.3
 #bit WR_SPAN_CH1_SW         = flag_byte14.4
 #bit WR_COMP_STATUS         = flag_byte14.5
 #bit WR_Drift_Tables_CH0_0      = flag_byte14.6 //Drift Table write done in 4 sections
 #bit WR_Drift_Tables_CH0_1      = flag_byte14.7 //

byte flag_byte15;
 #bit WR_Drift_Tables_CH1_0      = flag_byte15.0 //
 #bit WR_Drift_Tables_CH1_1      = flag_byte15.1 //
*/

byte warning_flags;
 #bit interfering_gas      = warning_flags.0
 #bit Calibration_Needed   = warning_flags.1
//Analyt-0: Primary Analytical optical channel...always present
//Analyt-1: 2nd Analytical channel...used to comp Analyt-1 or Independant 2nd gas measurement
/*

byte comp_status;   //Optical Compensation
 #bit COMP_SWITCH          = comp_status.2 //Analyt-1 used to Comp Analyt-0, 1=ON, 0=OFF
*/
byte unit_settings;
 #bit IGL_SWITCH      = unit_settings.0 // 1=Ideal Gas Law Comp Enabled
// #bit       = unit_settings.1
 #bit CHl_Active         = unit_settings.2 // 1= CH1 Analyt is Active
 #bit single_channel      = unit_settings.3 // 1= Single Gas Output
 #bit Drift_Tracking      = unit_settings.4 // 1=On, 0=Off
 #bit Suppress            = unit_settings.5 //Suppress low output levels...1=On, 0=Off
 #bit Comp_Warn_or_Err      = unit_settings.6 //Large Comp Value Result...Warning = 1, Err = 0
 #bit Cal_Warning_Mode      = unit_settings.7 // 1 = ON, 0 = Off
/*
byte I2C_STATUS;
 #bit MPL115A2_err         = I2C_STATUS.0  //I2C Com Error Pres/Temp Sensor
*/
//int16   pv_out;     // Gas concentration.
//int8   twos_comp_degrees_out;
unsigned int8 st_talk_attempts, st_talk;

byte i2c_error;

enum
{
   ST_STARTUP,      /* In this state the Master attempts
               to send startup information to the
               Slave. */
   
   ST_NORMAL = 2,      /* Normal state.  The Master has sent
               the startup information earlier and
               now is sending and receiving Slave
               updates. */

   ST_MALFUNCTION   /* Malfunction state.  Number of
               attempts to write to Slave has
               expired.  Master will continue
               trying but will set an error code
               of ERR_NO_SLAVE */
};

int8 master_ww_state;   // Master's HART/white-wire state machine.
                  // 0 = idle.
                  // 1 = got command.
                  // 2 = wrote response.

//unsigned int8 ww_cmmd_string[4];   // Stores command string used
                           // when HART is used to
                           // communicate the white wire
                           // command.

//unsigned int8 loop_current_mode = 0;
                                    // Determines whether output current
                                    // is active (value = 0) or parked
                                    // (value = 1).

// HART units code definitions.
#define TEMPERATURE_CODE 32         // Degree C.
#define PRESSURE_CODE 6             // psi.
#define PPM_CODE 139                // parts per million.
#define PLEL_CODE 161               // percent of least explosive level.
#define PPB_CODE 169                // parts per billion.
#define VOLUME_PERCENT_CODE 149     // percent volume.
#define MILLIGRAM_PER_LITER_CODE 170
 
                                             
// Pressure temperature sensor:
#define PT_I2C_ADDR 0x60    // I2C address.

#define TEMPERATURE_ADDER 5     // amount to add to temp sensor readings.

#define FCOEFF 0.98         // Filter coefficient to filter pressure readings.

//unsigned int8 ptcomp[12];
//float a0_float, b1_float, b2_float, c12_float, c11_float, c22_float;











Man I have a dream to one day be half as smart as some of you guys Laughing


I didn't include all the files because they are quiet large. [/quote]
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Tue Jun 26, 2018 9:19 am     Reply with quote

We still don't have the code to compile it. There could easily be something in one of your unpublished files causing the problem. Any #locate statements?. Any #byte or #word statements?.
You need ideally to generate a smaller version of the code that you can distribute, which shows the problem, so we can test and see if the problem is the same on a different compiler.
Do a search yourself in the files. Any statement lines involving 'pump_voltage'?.
Zezem



Joined: 02 Mar 2017
Posts: 7

View user's profile Send private message

PostPosted: Tue Jun 26, 2018 9:36 am     Reply with quote

Quote:
Any #locate statements?. Any #byte or #word statements?.


Ok so there is a header file with #bit declarations that might be the problem:

Code:


// Registers.
// Created for 18f26k22 on 12-16-2011 --- Steve A.

#byte ANSELA    = 0xF38
#byte ANSELB    = 0xF39
#byte ANSELC    = 0xF3A
#byte ANSELD    = 0xF3B
#byte ANSELE    = 0xF3C
#byte PMD2      = 0xF3D
#byte PMD1      = 0xF3E
#byte PMD0      = 0xF3F
#byte VREFCON2  = 0xF40
#byte VREFCON1  = 0xF41
#byte VREFCON0  = 0xF42
#byte CTMUICON  = 0xF43
#byte CTMUCONL  = 0xF44
#byte CTMUCONH  = 0xF45
#byte SRCON1    = 0xF46
#byte SRCON2    = 0xF47
#byte CCPTMRS1  = 0xF48
#byte CCPTMRS0  = 0xF49
#byte T6CON     = 0xF4A
#byte PR6       = 0xF4B
#byte TMR6      = 0xF4C
#byte T5GCON    = 0xF4D
#byte T5CON     = 0xF4E
#byte TMR5L     = 0xF4F
#byte TMR5H     = 0xF50
#byte T4CON     = 0xF51
#byte PR4       = 0xF52
#byte TMR4      = 0xF53
#byte CCP5CON   = 0xF54
#byte CCPR5L    = 0xF55
#byte CCPR5H    = 0xF56
#byte CCP4CON   = 0xF57
#byte CCPR4L    = 0xF58
#byte CCPR4H    = 0xF59
#byte PSTR3CON  = 0xF5A
#byte ECCP3AS   = 0xF5B
#byte PWM3CON   = 0xF5C
#byte CCP3CON   = 0xF5D
#byte CCPR3L    = 0xF5E
#byte CCPR3H    = 0xF5F
#byte SLRCON    = 0xF60
#byte WPUB      = 0xF61
#byte IOCB      = 0xF62
#byte PSTR2CON  = 0xF63
#byte ECCP2AS   = 0xF64
#byte PWM2CON   = 0xF65
#byte CCP2CON   = 0xF66
#byte CCPR2L    = 0xF67
#byte CCPR2H    = 0xF68
#byte SSP2CON3  = 0xF69
#byte SSP2MSK   = 0xF6A
#byte SSP2CON2  = 0xF6B
#byte SSP2CON1  = 0xF6C
#byte SSP2STAT  = 0xF6D
#byte SSP2ADD   = 0xF6E
#byte SSP2BUF   = 0xF6F
#byte BAUDCON2  = 0xF70
#byte RCSTA2    = 0xF71
#byte TXSTA2    = 0xF72
#byte TXREG2    = 0xF73
#byte RCREG2    = 0xF74
#byte SPBRG2    = 0xF75
#byte SPBRGH2   = 0xF76
#byte CM2CON1   = 0xF77
#byte CM2CON0   = 0xF78
#byte CM1CON0   = 0xF79
#byte PIE4      = 0xF7A
#byte PIR4      = 0xF7B
#byte IPR4      = 0xF7C
#byte PIE5      = 0xF7D
#byte PIR5      = 0xF7E
#byte IPR5      = 0xF7F
#byte PORTA     = 0xF80
#byte PORTB     = 0xF81
#byte PORTC     = 0xF82
#byte PORTD     = 0xF83
#byte PORTE     = 0xF84
#byte LATA      = 0xF89
#byte LATB      = 0xF8A
#byte LATC      = 0xF8B
#byte LATD      = 0xF8C
#byte LATE      = 0xF8D
#byte TRISA     = 0xF92
#byte TRISB     = 0xF93
#byte TRISC     = 0xF94
#byte TRISD     = 0xF95
#byte TRISE     = 0xF96
#byte OSCTUNE   = 0xF9B
#byte HLVDCON   = 0xF9C
#byte PIE1      = 0xF9D
#byte PIR1      = 0xF9E
#byte IPR1      = 0xF9F
#byte PIE2      = 0xFA0
#byte PIR2      = 0xFA1
#byte IPR2      = 0xFA2
#byte PIE3      = 0xFA3
#byte PIR3      = 0xFA4
#byte IPR3      = 0xFA5
#byte EECON1    = 0xFA6
#byte EECON2    = 0xFA7
#byte EEDATA    = 0xFA8
#byte EEADR     = 0xFA9
#byte EEADRH    = 0xFAA
#byte RCSTA1    = 0xFAB
#byte TXSTA1    = 0xFAC
#byte TXREG1    = 0xFAD
#byte RCREG1    = 0xFAE
#byte SPBRG1    = 0xFAF
#byte SPBRGH1   = 0xFB0
#byte T3CON     = 0xFB1
#byte TMR3L     = 0xFB2
#byte TMR3H     = 0xFB3
#byte T3GCON    = 0xFB4
#byte ECCP1AS   = 0xFB6
#byte PWM1CON   = 0xFB7
#byte BAUDCON1  = 0xFB8
#byte PSTR1CON  = 0xFB9
#byte T2CON     = 0xFBA
#byte PR2       = 0xFBB
#byte TMR2      = 0xFBC
#byte CCP1CON   = 0xFBD
#byte CCPR1L    = 0xFBE
#byte CCPR1H    = 0xFBF
#byte ADCON2    = 0xFC0
#byte ADCON1    = 0xFC1
#byte ADCON0    = 0xFC2
#byte ADRESL    = 0xFC3
#byte ADRESH    = 0xFC4
#byte SSP1CON2  = 0xFC5
#byte SSP1CON1  = 0xFC6
#byte SSP1STAT  = 0xFC7
#byte SSP1ADD   = 0xFC8
#byte SSP1BUF   = 0xFC9
#byte SSP1MSK   = 0xFCA
#byte SSP1CON3  = 0xFCB
#byte T1GCON    = 0xFCC
#byte T1CON     = 0xFCD
#byte TMR1L     = 0xFCE
#byte TMR1H     = 0xFCF
#byte RCON      = 0xFD0
#byte WDTCON    = 0xFD1
#byte OSCCON2   = 0xFD2
#byte OSCCON    = 0xFD3
#byte T0CON     = 0xFD5
#byte TMR0L     = 0xFD6
#byte TMR0H     = 0xFD7
#byte STATUS    = 0xFD8
#byte FSR2L     = 0xFD9
#byte FSR2H     = 0xFDA
#byte PLUSW2    = 0xFDB
#byte PREINC2   = 0xFDC
#byte POSTDEC2  = 0xFDD
#byte POSTINC2  = 0xFDE
#byte INDF2     = 0xFDF
#byte BSR       = 0xFE0
#byte FSR1L     = 0xFE1
#byte FSR1H     = 0xFE2
#byte PLUSW1    = 0xFE3
#byte PREINC1   = 0xFE4
#byte POSTDEC1  = 0xFE5
#byte POSTINC1  = 0xFE6
#byte INDF1     = 0xFE7
#byte WREG      = 0xFE8
#byte FSR0L     = 0xFE9
#byte FSR0H     = 0xFEA
#byte PLUSW0    = 0xFEB
#byte PREINC0   = 0xFEC
#byte POSTDEC0  = 0xFED
#byte POSTINC0  = 0xFEE
#byte INDF0     = 0xFEF
#byte INTCON3   = 0xFF0
#byte INTCON2   = 0xFF1
#byte INTCON    = 0xFF2
#byte PRODL     = 0xFF3
#byte PRODH     = 0xFF4
#byte TABLAT    = 0xFF5
#byte TBLPTRL   = 0xFF6
#byte TBLPTRH   = 0xFF7
#byte TBLPTRU   = 0xFF8
#byte PCL       = 0xFF9
#byte PCLATH    = 0xFFA
#byte PCLATU    = 0xFFB
#byte STKPTR    = 0xFFC
#byte TOSL      = 0xFFD
#byte TOSH      = 0xFFE
#byte TOSU      = 0xFFF

//******************************************************************
//                       PORT BIT DEFINITIONS
//******************************************************************

//**** Port A
//#bit                       =   PORTA.0   //Pin  2  AN0
#bit   Pump_Voltage         =   PORTA.1   //Pin  3  AN1
#bit   _24VDC               =   PORTA.2   //Pin  4  AN2
#bit   Temperature_LM50      =   PORTA.3   //Pin  5  AN3
//#bit                     =   PORTA.4   //Pin  6
#bit     Pump_Current         =   PORTA.5   //Pin  7  AN4
//#bit                     =   PORTA.6   //Pin 10
//#bit                     =   PORTA.7   //Pin  9

//**** Port B
//#bit                     =   PORTB.0  //Pin 21
#bit   WRITE               =   PORTB.1  //Pin 22
//#bit                      =   PORTB.2  //Pin 23
//#bit                     =   PORTB.3  //Pin 24
//#bit                     =   PORTB.4  //Pin 25
//#bit                     =   PORTB.5  //Pin 26
//#bit                     =   PORTB.6  //Pin 27
//#bit                     =   PORTB.7  //Pin 28

//**** Port C
#bit   READ            =   PORTC.0  //Pin 11
//#bit   Fan_Tach         =   PORTC.1
//#bit                  =   PORTC.2
#define    _SCL         PIN_C3
#define      _SDA          PIN_C4
//#bit                  =   PORTC.5
//#bit                  =   PORTC.6
#bit   Test_Pin         =   PORTC.7  //Pin 18

//STATUS register bits
 #BIT    CARRY       =     STATUS.0
 #BIT    DC          =     STATUS.1
 #BIT    ZERO        =     STATUS.2
 #BIT    PWR_DOWN    =     STATUS.3
 #BIT    TIME_OUT    =     STATUS.4
 #BIT    RP0         =     STATUS.5
 #BIT    RP1         =     STATUS.6
 #BIT    IRP         =     STATUS.7

//INTCON register bits
 #BIT    RBIF       = INTCON.0
 #BIT    INTF       = INTCON.1
 #BIT    T0IF       = INTCON.2
 #BIT    RBIE       = INTCON.3
 #BIT    INTE       = INTCON.4
 #BIT    T0IE       = INTCON.5
 #BIT    PEIE       = INTCON.6
 #BIT    GIE        = INTCON.7

 // PIR1 register bits
 #BIT    TMR1IF     =  PIR1.0
 #BIT    TMR2IF     =  PIR1.1
 #BIT    CCP1IF     =  PIR1.2
 #BIT    SSPIF      =  PIR1.3
 #BIT    TXIF       =  PIR1.4
 #BIT    RCIF       =  PIR1.5
 #BIT    ADIF       =  PIR1.6
 #BIT    PSPIF      =  PIR1.7

// PIR2 register bits
 #BIT    CCP2IF     =  PIR2.0

/* T1CON register bits
 #BIT    TMR1ON      =  T1CON.0
 #BIT    TMR1CS     =  T1CON.1
 #BIT    T1SYNC_    =  T1CON.2
 #BIT    T1OSCEN    =  T1CON.3
 #BIT    T1CKPS0    =  T1CON.4
 #BIT    T1CKPS1    =  T1CON.5
*/

// T1CON register bits
 #BIT   TMR1ON     =  T1CON.0
 #BIT   T1RD16     =  T1CON.1
 #BIT   T1SYNC_    =  T1CON.2
 #BIT   T1SOSCEN   =  T1CON.3
 #BIT   T1CKPS0    =  T1CON.4
 #BIT   T1CKPS1    =  T1CON.5
 #BIT   TMR1CS0    =  T1CON.6
 #BIT   TMR1CS1    =  T1CON.7

 // T3CON register bits
 #BIT   TMR3ON       =  T3CON.0
 #BIT   T3RD16     =  T3CON.1
 #BIT   T3SYNC_    =  T3CON.2
 #BIT   T3SOSCEN   =  T3CON.3
 #BIT   T3CKPS0    =  T3CON.4
 #BIT   T3CKPS1    =  T3CON.5
 #BIT   TMR3CS0    =  T3CON.6
 #BIT   TMR3CS1    =  T3CON.7


 // T2CON register bits
 #BIT    T2CKPS0    =  T2CON.0
 #BIT    T2CKPS1    =  T2CON.1
 #BIT    TMR2ON     =  T2CON.2
 #BIT    TOUTPS0    =  T2CON.3
 #BIT    TOUTPS1    =  T2CON.4
 #BIT    TOUTPS2    =  T2CON.5
 #BIT    TOUTPS3    =  T2CON.6

 // SSPCON register bits
// #BIT    SSPM0      =  SSPCON1.0
// #BIT    SSPM1      =  SSPCON1.1
// #BIT    SSPM2      =  SSPCON1.2
// #BIT    SSPM3      =  SSPCON1.3
// #BIT    CKP        =  SSPCON1.4
// #BIT    SSPEN      =  SSPCON1.5
// #BIT    SSPOV      =  SSPCON1.6
// #BIT    WCOL       =  SSPCON1.7

  // RCSTA register bits
#BIT    RX9D       =  RCSTA1.0
#BIT    OERR       =  RCSTA1.1
#BIT    FERR       =  RCSTA1.2
#BIT    ADDEN      =  RCSTA1.3
#BIT    CREN       =  RCSTA1.4
#BIT    SREN       =  RCSTA1.5
#BIT    RX9        =  RCSTA1.6
#BIT    SPEN       =  RCSTA1.7

 // CCP1CON register bits
 #BIT    CCP1M0     =  CCP1CON.0
 #BIT    CCP1M1     =  CCP1CON.1
 #BIT    CCP1M2     =  CCP1CON.2
 #BIT    CCP1M3     =  CCP1CON.3
 #BIT    CCP1Y      =  CCP1CON.4
 #BIT    CCP1X      =  CCP1CON.5

 // CCP2CON register bits
 #BIT    CCP2M0     =  CCP2CON.0
 #BIT    CCP2M1     =  CCP2CON.1
 #BIT    CCP2M2     =  CCP2CON.2
 #BIT    CCP2M3     =  CCP2CON.3
 #BIT    CCP2Y      =  CCP2CON.4
 #BIT    CCP2X      =  CCP2CON.5

  // ADCON0 register bits
 #BIT    ADON       =  ADCON0.0
 #BIT    GO         =  ADCON0.1
 #BIT    DONE_      =  ADCON0.1
 #BIT    CHS0       =  ADCON0.2
 #BIT    CHS1       =  ADCON0.3
 #BIT    CHS2       =  ADCON0.4
 #BIT    CHS3      =  ADCON0.5
 //#BIT          =  ADCON0.6
 //#BIT          =  ADCON0.7

 // ADCON2 register bits
 #BIT    ADCS0      =  ADCON2.0
 #BIT    ADCS1      =  ADCON2.1
 #BIT    ADCS2      =  ADCON2.2
 #BIT    ACQT0        =  ADCON2.3
 #BIT    ACQT1     =  ADCON2.4
 #BIT    ACQT2      =  ADCON2.5
 //#BIT             =  ADCON2.6
 #BIT    ADFM      =  ADCON2.7

 // T0CON register bits
 #BIT    T0PS0        =  T0CON.0
 #BIT    T0PS1        =  T0CON.1
 #BIT    T0PS2        =  T0CON.2
 #BIT    PSA        =  T0CON.3
 #BIT    T0SE       =  T0CON.4
 //#BIT    RTE        =  T0CON.4
 #BIT    T0CS       =  T0CON.5
 //#BIT    RTS        =  T0CON.5
 #BIT    T08BIT     =  T0CON.6
 //#BIT    INTEDG     =  T0CON.6
 #BIT    TMR0ON     =  T0CON.7
 //#BIT    RBPU_      =  T0CON.7

 // TRISA register bits
 #BIT    TRIS_A0    =  TRISA.0
 #BIT    TRIS_A1    =  TRISA.1
 #BIT    TRIS_A2    =  TRISA.2
 #BIT    TRIS_A3    =  TRISA.3
 #BIT    TRIS_A4    =  TRISA.4
 #BIT    TRIS_A5    =  TRISA.5
 #BIT    TRIS_A6    =  TRISA.6
 #BIT    TRIS_A7    =  TRISA.7

 // TRISB register bits
 #BIT    TRIS_B0    =  TRISB.0
 #BIT    TRIS_B1    =  TRISB.1
 #BIT    TRIS_B2    =  TRISB.2
 #BIT    TRIS_B3    =  TRISB.3
 #BIT    TRIS_B4    =  TRISB.4
 #BIT    TRIS_B5    =  TRISB.5
 #BIT    TRIS_B6    =  TRISB.6
 #BIT    TRIS_B7    =  TRISB.7

 // TRISC register bits
 #BIT    TRIS_C0    =  TRISC.0
 #BIT    TRIS_C1    =  TRISC.1
 #BIT    TRIS_C2    =  TRISC.2
 #BIT    TRIS_C3    =  TRISC.3
 #BIT    TRIS_C4    =  TRISC.4
 #BIT    TRIS_C5    =  TRISC.5
 #BIT    TRIS_C6    =  TRISC.6
 #BIT    TRIS_C7    =  TRISC.7

 // PIE1 register bits
 #BIT    TMR1IE     =  PIE1.0
 #BIT    TMR2IE     =  PIE1.1
 #BIT    CCP1IE     =  PIE1.2
 #BIT    SSPIE      =  PIE1.3
 #BIT    TXIE       =  PIE1.4
 #BIT    RCIE       =  PIE1.5
 #BIT    ADIE       =  PIE1.6
 #BIT    PSPIE      =  PIE1.7

 // TXSTA register bits
#BIT    TXD8       =  TXSTA1.0
#BIT    TRMT       =  TXSTA1.1
#BIT    BRGH       =  TXSTA1.2
#BIT    SYNC       =  TXSTA1.4
#BIT    TXEN       =  TXSTA1.5
#BIT    TX89       =  TXSTA1.6
#BIT    CSRC       =  TXSTA1.7

 // ADCON1 register bits
 #BIT    PCFG0      =  ADCON1.0
 #BIT    PCFG1      =  ADCON1.1
 #BIT    PCFG2      =  ADCON1.2


Zezem



Joined: 02 Mar 2017
Posts: 7

View user's profile Send private message

PostPosted: Tue Jun 26, 2018 9:48 am     Reply with quote

Figured out the problem after posting the last reply.

Someone thought it was a good idea to use the same variable names

#bit Pump_Voltage = PORTA.1 //Pin 3 AN1
#bit _24VDC = PORTA.2 //Pin 4 AN2
#bit Pump_Current = PORTA.5 //Pin 7 AN4

float pump_voltage, _24VDC, pump_current;


Thanks for all your help!! I got educated on floating points that i will use for all future projects!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Tue Jun 26, 2018 11:24 am     Reply with quote

As I said:
Quote:

Do a search yourself in the files. Any statement lines involving 'pump_voltage'?.


Hopefully that search was what led to finding it.... Smile

Aargh.

That is one reason why when working on reasonably serious code, I like to have the names 'self indicate'. So a 'bit' would normally always be xxx_b. A type would be xxx_t. etc.. It helps to avoid that sort of problem.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jun 26, 2018 1:12 pm     Reply with quote

Gee when I started this 'microcomputer' gig, variables were limited to TWO characters when using the 'high level' language of Microsoft BASIC ! When I used COBOL every variable was coded as xxx_yyy_zzz.
Nowadays you can probably use 254 characters to name a variable so it is sad (and frustrating) to see the 'fun' the OP has had with this code.
Jay
jeremiah



Joined: 20 Jul 2010
Posts: 1346

View user's profile Send private message

PostPosted: Thu Jun 28, 2018 6:11 pm     Reply with quote

Zezem wrote:
Figured out the problem after posting the last reply.

Someone thought it was a good idea to use the same variable names

#bit Pump_Voltage = PORTA.1 //Pin 3 AN1
#bit _24VDC = PORTA.2 //Pin 4 AN2
#bit Pump_Current = PORTA.5 //Pin 7 AN4

float pump_voltage, _24VDC, pump_current;


Thanks for all your help!! I got educated on floating points that i will use for all future projects!!


Also keep in mind there is a #case directive you can use to enforce casing. It would have saved you on 2 of those (they would have been separate variables), but the _24VDC would have still been a problem.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group