Jump to content

OrmatEli

EstablishedMember
  • Content Count

    41
  • Joined

  • Last visited

Community Reputation

0 Neutral

About OrmatEli

  • Rank
    Regular
  1. Thanks, It seems to help. Is this a bug in MPLAB or Boost C?
  2. #include <system.h> #include "RunTrial.h" #include <icd2.h> #include <stdio.h> #pragma DATA _CONFIG1H, _OSC_HS_1H // highspeed crystal oscillator #pragma DATA _CONFIG2L, _PWRT_OFF_2L // Turn PWRT (Power-up Reset Timer) off #pragma DATA _CONFIG2H, _WDT_OFF_2H // watchdog timer off #pragma DATA _CONFIG4L, _DEBUG_ON_4L & _LVP_OFF_4L // Background debugger enabled, RB6 and RB7 are dedicated to In-Circuit Debug #pragma DATA _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L #pragma DATA _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H #pragma DATA _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L #pragma DATA _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H #pragma DATA _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L #pragma DATA _CONFIG7H, _EBTRB_OFF_7H #define CondT_ADcon0 0b00001001 //=9 enable capture from channel AN2 #define BATV_ADcon0 0b00100001 //=33 enable capture from channel AN8 #define OECV_ADcon0 0b00100101 //=37 enable capture from channel AN8 signed int ConDTemp, OECVoltage, BatteryVoltage; typedef struct { unsigned int A; unsigned int B; unsigned int c; unsigned int reg; } CaptureStruct; volatile CaptureStruct CondT_capture, OECV_capture, BatV_capture; void A2DRead() { switch (adcon0) { case CondT_ADcon0 : // capture condenser temperature CondT_capture.reg = adres; // read conversion adcon0= OECV_ADcon0; // next capture: Load current break; case OECV_ADcon0 : OECV_capture.reg = adres; adcon0= BATV_ADcon0; break; case BATV_ADcon0 : BatV_capture.reg = adres; adcon0= CondT_ADcon0; break; } } void interrupt (void) { if (pir1.ADIF) { A2DRead(); pir1.ADIF=0; adcon0.GO=1; } } signed int getReading(CaptureStruct CapSt) { static signed int temporaryPar; // temporary parameter for storing intermediate results pie1.ADIE=0; temporaryPar = CapSt.reg * CapSt.A; temporaryPar = temporaryPar / CapSt.B; // then multiply temporaryPar = temporaryPar - CapSt.c; pie1.ADIE=1; return temporaryPar; } void main() { CondT_capture.A = 16; CondT_capture.B = 25; CondT_capture.c = 263; OECV_capture.A = 13; OECV_capture.B = 4; OECV_capture.c = 0; BatV_capture.A = 13; BatV_capture.B = 2; BatV_capture.c = 0; intcon.GIE=1; intcon.PEIE=1; trisa.2 = 1; trisa.1 = 1; trisf.3=1; trisf.4=1; adcon1 = 0b00000101; adcon2 = 0b10011101; adcon0=CondT_ADcon0; adcon0.1 = 1; //initiate A2D conversion pie1.ADIE=1; pir1.ADIF=0; ipr1.ADIP=1; // EUSART1 configuration //RCSTA1.SPEN trise.0 = 0; trise.7 = 0; trisd.3 = 1; trisd.4 = 1; //portb.5 = 1; //D117 while(1) { porte.0 = portd.3; // D122 porte.7 = portd.4; // D123 ConDTemp = getReading(CondT_capture); OECVoltage = getReading(OECV_capture); BatteryVoltage = getReading(BatV_capture); } } What the program does is manage multiple analog inputs. The CaptureStruct struct stores the parameters for transforming the A2D readings into engineering units (getReading routine). Both the CaptureStruct parameters and the reading come out corrupted. OrmatEli
  3. I also ran into this problem and reported this problem in a microchip forum about two weeka ago. There was no reply yet. Is there a chance that this is a BoostC problem? This problem was resolved in V6.70 (see the version log http://www.sourceboost.com/CommonDownload/VersionLog.html ), its was caused by use of local auto variable types in coff file. In MPLAB when local auto variables are used the variable offset is combined with the contents of SFR register and this is the address that MPLAB displays the contents of. This was fixed by changing the type of variables contained in the coff file. Regards Dave Dave, I just installed V6.8 and it didn't help. I installed by running sourceboost.exe. Is there something that I missed?
  4. I also ran into this problem and reported this problem in a microchip forum about two weeka ago. There was no reply yet. Is there a chance that this is a BoostC problem?
  5. Dave, Can you elaborate how to do these things in MPLAB. I've tried the configuration bits dialog box screen, but it doesn't work.
  6. The funny thing is that if you open a new project in BoostC, using an automatic header file creation you get: #ifndef _RUNTRIAL_H_ #define _RUNTRIAL_H_ #endif //_RUNTRIAL_H_ source fle is: #include <system.h> #include "RunTrial.h" void main() { } According to this thread this template will not work !
  7. my mistake it was extern: #ifndef DECLARE_MY_VARS extern #endif int myglobal1, myglobal2, myglobal3;
  8. Better is a matter of opinion. Depends on the exact application.Declaring the globals in a .c file (rather than a .h) is standard practice. Regards Dave I've just tried what Pavel proposed, it didn't compile. Showed error on "intern" line after the #infndef
  9. Here's another: #include "MainParam.h" ParState HotStart (Readings ReadOEC) { static ParState StateParam; static unsigned int Hot_Timer = TickGetSec(); // Timer for timing out Hot Startup if (ReadOEC.Frequency > FrequencySP.StartUp) // if frequency is detected { StateParam.ExcI_p = 0; // release turbine - excitation current is controlled by FC routine } else { StateParam.ExcI_p = 1; // if no frequency then hold turbine } StateParam.Heat_Demand_p = BurnerSP.Low; if (ReadOEC.OEC_Voltage > VoecSP.UnderVoltage) // if voltage is detected { StateParam.Turbine_State = NORMAL_OPERATION; } else if (TickGetSecDiff(Hot_Timer) > TimerSP.HotStart_Timeout) // if voltage is not detected // if startup timed out { StateParam.Failure_Type = FAIL_to_RUN; } return StateParam; } header file as before. Thanks in advance to everyone.
  10. Emte, If I understand correctly, you propose to add a .c file where all globals will be initiated. Is it better than what Pavel proposed?
  11. Dave, I have some 30 global variables. Do I really have to write them twice inside the header file?
  12. I have a project that compiled OK, but when I try to build it I get: CheckFailure is a function and file which, as I said, already compiled.
  13. Thanks, Chris. for some reason the compiler doesn't show the error on that line but rather at function declaration.
  14. Apparently not or you wouldn't have this error. If you want a more definitive answer you need to provide all code. Pavel Here's the .h file // ********************************************************** // * // File Name: MainParam.H * // * // Objective: Header file- * // Define parameters and variables used * // throughout the program * // * //*********************************************************** // AUTHOR: * // * // revision : 0.0 (04/2007) * // * //*********************************************************** #include <system.h> //#include "Tick.h" #include <icd2.h> #ifndef MainParam_h #define MainParam_h //General structures used inside the program typedef struct { unsigned int OEC_Voltage; // turbine voltage engineering units unsigned int Frequency; // turbine's frequency in engineering units (mV) unsigned int Control_Voltage; // control voltage in engineering units unsigned int Battery_Voltage; // battery voltage (before K7 closes) signed int Load_Current; // turbine's DC current signed int Condenser_Temperature; // condenser Temperature signed int Ambient_Temperature; // Ambient temperature signed int Boiler_Temperature; // boiler temperature unsigned char Burner; // K7FB_i unsigned char K7_oc; // K7 status } Readings; //ReadOEC typedef struct //shadow parmaters which are called from whithin turbine states { unsigned char Turbine_State; unsigned char Failure_Type; unsigned char K7_p; // state of K7 1- closed; 0- open unsigned char ExcI_p; // Excitation Current, 1- Hold TG; 0- FC control unsigned char DL_Enbl_p; // Dummy Load enable, 1- disable; 0- enable unsigned char Heat_Demand_p; // Heat Demand from burner. % of burner } ParState; //StateParam // PID control parameters typedef struct { unsigned int Max; unsigned int Min; signed int KP; signed int KI; signed int KD; }PIDstruct; PIDstruct DummyLoadPID; PIDstruct FCpid; PIDstruct BurnerPID; //**************************************** // A2D convesion parameters typedef struct { unsigned int A; unsigned int B; unsigned int c; unsigned int reg; } CaptureStruct; CaptureStruct VOec_capture; CaptureStruct ContV_capture; CaptureStruct Vbat_Capture; CaptureStruct Iload_Capture; CaptureStruct CondT_capture; CaptureStruct Tamb_capture; CaptureStruct BoilT_capture; #define VOec_ADcon0 0b00010101 // enable capture from channel AN5 #define ContV_ADcon0 0b00000001 // enable capture from channel AN0 #define Vbat_ADcon0 0b00000101 // enable capture from channel AN1 #define EXCi_ADcon0 0b00010001 // enable capture from channel AN4 #define Iload_ADcon0 0b00001101 // enable capture from channel AN3 #define CondT_ADcon0 0b00001001 // enable capture from channel AN2 #define Tamb_ADcon0 0b00011001 // enable capture from channel AN6 #define BoilT_ADcon0 0b00011101 // enable capture from channel AN7 //**************************************************** typedef struct { unsigned int Voec; unsigned int Iload; unsigned int Frequency; unsigned int K7_stat; unsigned int Turbine_State; unsigned int Failure_Type; unsigned int Boiler_temp; unsigned int Condenser_temp; } History; //RecordHist struct TSP // timer setpoint parameters (in seconds) { unsigned char VeryColdON; // time set point for burner "on" at very cold start unsigned char VeryColdOFF; // time set point for burner "off" at very cold start unsigned int ColdtoHot; // timer set point for burner transition from normal to hot start unsigned int HotStart_Timeout; // set point for Hot Start timeout unsigned int Lubrication; // set point for T.G. lubrication unsigned int OverCurrentDelay; // overcurrent delay unsigned int OverVoltageDelay; // overvoltage delay unsigned int UnderVoltageDelay; // under voltage delay } TimerSP; struct VoecSetPoint { unsigned int UnderVoltage; // under voltage set point (cV) unsigned int OverVoltage; // over voltage set point (cV) unsigned int Nominal; // required turbine voltage (cV) unsigned int BurnerIn; // low voltage setpoint for burner on unsigned int BurnerOut; // high voltage setpoint for burner on unsigned int DLin; // dummy load start unsigned int DLout; // dummy load stop } VoecSP; struct VBSP { unsigned int Low; // low battery voltage setpoint unsigned int High; // high battery voltage setpoint } VbatSP; struct FSP // frequency setpoints { unsigned char StartUp = 80; // frequency startup set-point to indicate that turbine is running unsigned int OverSpeed; // Frequency overspeed in engineering units, (Hz) unsigned int Low; // Frequency lower bound in engineering units (Hz) unsigned int DLin; // dummy load start unsigned int DLout; // dummy load stop unsigned int BurnerIn; // turn burner on/low unsigned int BurnerOut; // turn burner to minimum unsigned int Nominal; // nominal Frequency } FrequencySP; struct FCP { unsigned int Hold; // excitation current setpoint for "holding" the generator at startup, mA unsigned int Imax; // maximum (theoretic) excitation current = Voltage/Rcoil (mA) } FcSP; struct B_SP // Boiler temperature setpoints { signed char VeryCold; // set point for Very cold startup char Cold; // set point for transition from Very cold to normal startup char HotStart; // boiler temperature to start at Hot startup char Lubrication; // set point for heating the boiler for lubrication char OverTemp; // set point for over temperature } BoilerSP; // struct CSP // condenser Temperature { char CondenserTempLow; char CondenserTempHigh; } CondenserSP; // struct ISP { unsigned int OverCurrent; // high load current setpoint (short circuit) unsigned char Shunt; // parameters for shunt mV/mA } IloadSP; struct BSP { unsigned char Low; // Lowest heat demand set point unsigned char High; // Highest heat demand set point unsigned char freqControl; // burner is frequency/voltage controlled } BurnerSP; unsigned char HeatDemand; //******************************* STATE CONTROL ********************************************** // Turbine state - determine operation states, and their setpoints // (startup, normal operation, shutdown etc.) #define IDLE 0 // at initialization Turbine_State0 #define VERY_COLD_START 1 #define COLD_START 2 #define HOT_START 3 #define NORMAL_OPERATION 4 #define SHUT_DOWN 5 #define GENERAL_FAILURE 6 // failure types - mark failure types // (over/under voltage, short circuit, flame out, etc..) #define OVER_VOLTAGE 1 #define UNDER_VOLTAGE 2 #define BOILER_HIGH_TEMP 3 #define FLAME_OUT 4 #define OVER_SPEED 5 #define LOW_FREQUENCY 6 #define FAIL_to_RUN 7 #define No_FREQUENCY 8 #define Short_Circuit 9 #define Low_Battery_Voltage 10 #define High_Battery_Voltage 11 #define K7_open 12 #define K7_closed 13 //******************************************************************************** ******** // -------------- SIGNAL and resource management ---------- //Timer3 and Timer4 are the clock sources for ECCP3, CCP4 and //Timer1 and Timer2 are the clock sources for ECCP1 and ECCP2 // --------------------TIMER0 is global timer ----------------- long Fosc = 20000000; // #define FC_DutyCycle ccpr3l // register which houses the duty cycle of the FC PWM // PWM Duty Cycle = (CCPR3L:CCP3CON<5:4>) • TOSC • (TMR4 Prescale Value) // = FC_DutyCycle • 0.05e-6 • 16 = // = FC_DutyCycle • 0.8usec // // convenient definitions for input and output registers // (according to digital drawing) // ------------ analog input terminals ------- #define VCONTR_s porta.0 // control voltage #define VLOAD_s porta.1 // load voltage (K7 - costumer side) #define TCOND_s porta.2 // condenser temperature #define ILOAD_s porta.3 // load voltage #define IEXC_s porta.5 // excitation #define TBOIL_s portf.2 // Boiler temperature #define TAMB_s portf.1 // ambient temperature #define VOEC_s portf.0 // turbine voltage //------------ digital input terminals ------- #define BOILSW_i porte.3 // boiler thermoswitch #define FREQ_i portc.1 // frequency input (HSC) #define K7FB_i portd.5 // K7 feedback #define RESET_i portd.4 // user reset input #define ON_i portd.3 // user turbine On command #define REM_i portd.2 // remote command #define OVERC portb.3 // overcurrent signal //------------ digital output terminals ------- #define K7_o portb.1 // K7 #define ON_Led portb.0 // "ON" indication #define Fail_Led portd.7 // "Failure" indication ///////////////////////////////////////////////////////////// // routine prototypes void CPU_Init(void); // initiate CPU void EEPROM_Init(void); // EEPROM initiate Readings ReadInputs(); // Read inputs from turbine int getFreq(int reg); // get frequency reading from capture register int getReading(CaptureStruct CapStruct); unsigned char CheckFailure(Readings ReadOEC, unsigned char Turbine_State); ParState TurbineControl(Readings ReadOEC, unsigned char Failure_Type); ParState VeryColdStart(Readings ReadOEC); // Very cold turbine startup state ParState ColdStart(Readings ReadOEC); // Normal (cold) turbine startup state ParState HotStart(Readings ReadOEC); // Hot turbine startup state ParState ShutDown(Readings ReadOEC); // shut down turbine ParState MainFailure(Readings ReadOEC); // Main failure routine ParState NormalOperation(Readings ReadOEC); // Normal Operation routine void UpdateOutputs(Readings ReadOEC, ParState StateParam); void WriteHistory(void); // Write history to EEPROM void WriteDisplay(void); // writer status to display // interrupt routines void TickUpdate(void); // update timer void FrequencyCapture(void); // update frequency reading void A2DRead(void); // read A2D conversion result #endif
  15. The following code gives me a "missing semicolon" error at the function decleration line: #include "MainParam.h" void DL_PID(Readings ReadOEC) { static signed char e_Freq =0; // error static signed char Se_Freq =0; // accumulating error static signed char De_Freq =0; // error differential static signed char EFn_1 =0; // hold previous error static unsigned int DLpwm =0x00; // hold current PID value static unsigned int FsSP; // current frequency setpoint static unsigned int `FsPS; if (DLpwm) // if dummy loads are in FsPS = FrequencySP.DLout; // setpoint of frequncy changes else FsPS = FrequencySP.DLin; e_Freq = FsPS - ReadOEC.Frequency; // error= frequency difference Se_Freq = Se_Freq + e_Freq; // accumulating error De_Freq = e_Freq - EFn_1; EFn_1 = e_Freq; DLpwm = DLpwm + DummyLoadPID.KP * e_Freq + DummyLoadPID.KI * Se_Freq + DummyLoadPID.KD * De_Freq; // proportional integral derivative if (DLpwm > DummyLoadPID.Max) DLpwm = DummyLoadPID.Max; else if (DLpwm < DummyLoadPID.Min) DLpwm = DummyLoadPID.Min; // update PWM duty cycle registers ccp1con.4=DLpwm.0; // the LSB goes into bits 4&5 of CCP1CON ccp1con.5=DLpwm.1; ccpr1l = (( DLpwm >> 2)& 0xff); // the 8 MSB go to ccpr1l } As far as I can tell al the parameters and varibles are declared in the MainParam.h file
×
×
  • Create New...