init
GenCtrl.h@2:9cbc61162554, 2021-11-04 (annotated)
- Committer:
- gert_lauritsen
- Date:
- Thu Nov 04 18:02:10 2021 +0000
- Revision:
- 2:9cbc61162554
- Parent:
- 0:68589a6f09af
pub
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gert_lauritsen | 0:68589a6f09af | 1 | // : |
gert_lauritsen | 0:68589a6f09af | 2 | // Title : Generator controller |
gert_lauritsen | 0:68589a6f09af | 3 | // Filename : GenCtrl.h |
gert_lauritsen | 0:68589a6f09af | 4 | // Author : Gert Lauritsen |
gert_lauritsen | 0:68589a6f09af | 5 | // Origin Date : 26/01/2016 |
gert_lauritsen | 0:68589a6f09af | 6 | // Version : 1.000 |
gert_lauritsen | 0:68589a6f09af | 7 | // Compiler : Keil |
gert_lauritsen | 0:68589a6f09af | 8 | // Target : |
gert_lauritsen | 0:68589a6f09af | 9 | // Notes : None |
gert_lauritsen | 0:68589a6f09af | 10 | // |
gert_lauritsen | 0:68589a6f09af | 11 | //------------------------------------------------------------------------------------ |
gert_lauritsen | 0:68589a6f09af | 12 | |
gert_lauritsen | 0:68589a6f09af | 13 | #ifndef GenCtrl_H |
gert_lauritsen | 0:68589a6f09af | 14 | #define GenCtrl_H |
gert_lauritsen | 0:68589a6f09af | 15 | #include "mbed.h" |
gert_lauritsen | 0:68589a6f09af | 16 | |
gert_lauritsen | 0:68589a6f09af | 17 | typedef void (*GenCallback_type)(); |
gert_lauritsen | 0:68589a6f09af | 18 | #define RotorCurrentAdvLength 12 |
gert_lauritsen | 0:68589a6f09af | 19 | #define VinBuffLength 25 |
gert_lauritsen | 0:68589a6f09af | 20 | |
gert_lauritsen | 0:68589a6f09af | 21 | //Omregning |
gert_lauritsen | 0:68589a6f09af | 22 | #define VoltPrCount (3.3/65535) //vref/12bit |
gert_lauritsen | 0:68589a6f09af | 23 | #define VinGain (4.7/(200+4.7)) //Spændingsdeler i input |
gert_lauritsen | 0:68589a6f09af | 24 | #define VinFromCount (VoltPrCount/VinGain) //Omregning til Count->Volt |
gert_lauritsen | 0:68589a6f09af | 25 | #define IoutCalFaktor (VoltPrCount*(1000/21.5)) //Strøm i Count til Amp |
gert_lauritsen | 0:68589a6f09af | 26 | #define IRotorCalFaktor (VoltPrCount*2.1315) //Målt Count til strøm i rotor [A] |
gert_lauritsen | 0:68589a6f09af | 27 | |
gert_lauritsen | 0:68589a6f09af | 28 | |
gert_lauritsen | 0:68589a6f09af | 29 | typedef struct { |
gert_lauritsen | 0:68589a6f09af | 30 | unsigned int Vset; //2 byte |
gert_lauritsen | 0:68589a6f09af | 31 | unsigned int VMax; //2 byte I tilfælde af at spændingen kommer over dette slukkes for det hele |
gert_lauritsen | 0:68589a6f09af | 32 | unsigned char VmaxRep; //1 byte |
gert_lauritsen | 0:68589a6f09af | 33 | long StartPower; //4 byte |
gert_lauritsen | 0:68589a6f09af | 34 | unsigned int PWMRotaryBlok; //2 Den PWM, som vi kan gå ned til |
gert_lauritsen | 0:68589a6f09af | 35 | unsigned int IRotorMax; //2 Begrænsning af rotor strøm |
gert_lauritsen | 0:68589a6f09af | 36 | unsigned int Kp; //2 Gain i Voltage Reg |
gert_lauritsen | 0:68589a6f09af | 37 | long RunPower; //4 byte |
gert_lauritsen | 0:68589a6f09af | 38 | } CalRecType; //21 byte i alt |
gert_lauritsen | 0:68589a6f09af | 39 | |
gert_lauritsen | 0:68589a6f09af | 40 | typedef struct { //Her har vi alle måle data samlet |
gert_lauritsen | 0:68589a6f09af | 41 | unsigned int Nstak; //Stak af ADC |
gert_lauritsen | 0:68589a6f09af | 42 | long Vmon, Iin ,Irotor; // |
gert_lauritsen | 0:68589a6f09af | 43 | unsigned long regadv; //middel af PWM |
gert_lauritsen | 0:68589a6f09af | 44 | unsigned int regadvcount; //tæller til at regne middel ud med |
gert_lauritsen | 0:68589a6f09af | 45 | unsigned long loadadv; //middel af PWM |
gert_lauritsen | 0:68589a6f09af | 46 | unsigned int loadadvcount; //tæller til at regne middel ud med |
gert_lauritsen | 0:68589a6f09af | 47 | } MessDataType; |
gert_lauritsen | 0:68589a6f09af | 48 | |
gert_lauritsen | 0:68589a6f09af | 49 | |
gert_lauritsen | 0:68589a6f09af | 50 | class GenCtrl |
gert_lauritsen | 0:68589a6f09af | 51 | { |
gert_lauritsen | 0:68589a6f09af | 52 | private: |
gert_lauritsen | 0:68589a6f09af | 53 | GenCallback_type callback; |
gert_lauritsen | 0:68589a6f09af | 54 | PwmOut *RotorPWM; |
gert_lauritsen | 0:68589a6f09af | 55 | Ticker Sampler, GeneralTimer; |
gert_lauritsen | 0:68589a6f09af | 56 | AnalogIn *Vin, *Iin,*Irotor; |
gert_lauritsen | 0:68589a6f09af | 57 | |
gert_lauritsen | 0:68589a6f09af | 58 | unsigned int ADCValue[3]; //Analog In Vout, Iout, Irotor |
gert_lauritsen | 0:68589a6f09af | 59 | unsigned int VinBuff[VinBuffLength]; //Buffer til at filtre input spænding (undgå Ron) |
gert_lauritsen | 0:68589a6f09af | 60 | unsigned int NotInRegArea; //Disable function til generator |
gert_lauritsen | 0:68589a6f09af | 61 | unsigned int RotorCurrent[RotorCurrentAdvLength]; |
gert_lauritsen | 0:68589a6f09af | 62 | unsigned int vmaxdone; //Tæller for hvor mange gange der har været over Vmax |
gert_lauritsen | 0:68589a6f09af | 63 | int softstartTimeOut; //en tid, hvor den efter at være kommet over i reg mode stadig har en Max Pout |
gert_lauritsen | 0:68589a6f09af | 64 | void AnalogIn(void); //Sampler |
gert_lauritsen | 0:68589a6f09af | 65 | unsigned int AdvRotorCurrent(void); //Finder middelstrøm |
gert_lauritsen | 0:68589a6f09af | 66 | void SetNewPwM (void); //ReCalc PWM |
gert_lauritsen | 0:68589a6f09af | 67 | void Blink(); //debug function |
gert_lauritsen | 0:68589a6f09af | 68 | void Timer(); //General timer 1gg/sec |
gert_lauritsen | 0:68589a6f09af | 69 | |
gert_lauritsen | 0:68589a6f09af | 70 | unsigned char MaxValuePos(void); |
gert_lauritsen | 0:68589a6f09af | 71 | |
gert_lauritsen | 0:68589a6f09af | 72 | public: |
gert_lauritsen | 0:68589a6f09af | 73 | GenCtrl(PinName PWMSignal,PinName VinSignal,PinName IInSignal,PinName IrotorSignal,GenCallback_type _callback); |
gert_lauritsen | 0:68589a6f09af | 74 | bool Rotionprotech; //Sættes hvis omdrejningerne kommer for lang ned |
gert_lauritsen | 0:68589a6f09af | 75 | int softstart; //Opstarts styring |
gert_lauritsen | 0:68589a6f09af | 76 | unsigned int Vmax; //målt Vmax |
gert_lauritsen | 0:68589a6f09af | 77 | unsigned int LastRpm; |
gert_lauritsen | 0:68589a6f09af | 78 | unsigned int Vout; //stakket måling over 1 sek [count] |
gert_lauritsen | 0:68589a6f09af | 79 | |
gert_lauritsen | 0:68589a6f09af | 80 | MessDataType MessData; //Målte data (load m.m.) |
gert_lauritsen | 0:68589a6f09af | 81 | CalRecType CalRec; //Record med opsætningsparameter |
gert_lauritsen | 0:68589a6f09af | 82 | |
gert_lauritsen | 0:68589a6f09af | 83 | void ResetMessData(void); //når man har aflæst sine værdier rester man dem. |
gert_lauritsen | 0:68589a6f09af | 84 | void SetVCal(float Vset,float Vmax,float StartPower,float RunPower,float RotorMaxCurrent); |
gert_lauritsen | 0:68589a6f09af | 85 | void NewVout(float Vset); |
gert_lauritsen | 0:68589a6f09af | 86 | }; |
gert_lauritsen | 0:68589a6f09af | 87 | |
gert_lauritsen | 0:68589a6f09af | 88 | #endif |