Source file: /~heha/ewa/Reluktanzmotor/maweig-Motor-190927.zip/Settings.h

// Description:	User settings, global includes, global declarations
#pragma once

#include <F28x_Project.h>

// This sets the BUILDLEVEL to one of the available choices.
const enum {
  LEVEL1=1,  // 1 = Module check out (do not connect the motors) LEVEL1
  LEVEL2=2,  // 2 = Verify ADC, park/clarke, calibrate the offset and speed measurement
  LEVEL3=3,  // 3 = Verify closed current(torque) loop and its PIs
  LEVEL4=4,  // 4 = Verify speed loop and speed PID
}BUILDLEVEL=LEVEL1;

#define bit(x) (1UL<<(x))
typedef unsigned char uint8_t;	// fehlt irgendwie
#define elemof(x) (sizeof(x)/sizeof(*(x)))

// This sets the Current sense option
// Can be measured from multiple sources, but one is taken for control.
const enum {
  SHUNT_CURRENT_SENSE,LEM_CURRENT_SENSE,SD_CURRENT_SENSE
}CURRENT_TAKE = LEM_CURRENT_SENSE;
// All sources are used for tripping!!
const int SENSES = bit(LEM_CURRENT_SENSE)|bit(SD_CURRENT_SENSE);

// Position Encoder options
// Only one is measured and used. SinCos is not yet implemented.
const enum {
  QEP_ENCODER,SINCOS_ENCODER
}POSITION_ENCODER = QEP_ENCODER;

const int ENCODERS = bit(QEP_ENCODER);

// Define CPU and system frequency (Hz)
const float F_CPU=200E6;	// 200 MHz
// Define some frequencies (Hz)
const float F_PWM=10E3;		// 10 kHz PWM-Grundfrequenz (Pfeifen)
const float F_ISR=10E3;		// 10 kHz

void configPwm(volatile EPWM_REGS&,Uint16 period,Uint16 slave_phase);

// adc.cpp
struct Currentsense{
  float As,Bs,Cs;	// Phase A, B, C
  void readSDFM();				// sigmadelta.cpp
  void readShunt();
  void readLEM();
  static void integrateSDFMoffset(float K2);	// sigmadelta.cpp
  static void resetSDFMoffset();		// sigmadelta.cpp
  static void integrateADCoffset(float K2);
  static void resetADCoffset();
  static void setADCoffsetregs();
};
void adcGetSinCos(float sincos[2]);
void initADC();
float myGetTemperatureC(int16_t);

// posEncoderSuite.cpp
extern float posEncElecTheta,posEncMechTheta;	// ref: MotorControl.cpp
extern Uint16 lsw;		// ref: MotorControl.cpp
void posEncoderSuite();		// ref: MotorControl.cpp
void initPosEncoderSuite();	// ref: main.cpp

// amc1210spi.cpp
extern struct Amc1210 {
  static void init();
// Der Standardtransfer ist 1 Adressbyte, gefolgt von 1 oder mehr 16-Bit-Wörtern.
// Das Adressbyte besteht aus 1 R/W-Bit (1 = Lesen) und 7 Adressbits.
// rx und tx dürfen gleich sein, dürfen NULL sein.
// rx und tx sollten nicht gleichzeitig NULL sein, wäre wohl Quatsch.
// n muss zwischen 1 und 16 liegen.
  static void send(uint8_t adr, const uint16_t*tx, size_t n=1);	// Senden (max. 16)
// „Bottom Half“ = Abholen / Leeren der FIFO und ChipSelect = High
  static void recv(uint8_t adr, uint16_t*rx, size_t n=1);	// Senden (Adresse und Dummies) (max. 16)
  static void wait();	// Warten und Abholen / leeren (max. 16)
  static void send(uint8_t adr, uint16_t msg);	// Einzel-Transfer
  static uint16_t recv(uint8_t adr);		// Einzel-Transfer
}amc1210;

// comport.cpp
struct Comport {
  volatile SCI_REGS&regs;
  const uint8_t*sendptr;	// für ISR
  uint8_t*recvptr;		// für ISR
  volatile size_t sendlen,recvlen;	// für ISR
  uint8_t sendbin,recvbin;	// für ISR, wenn Bit 0 = 1 dann ist Bit 1 = Byteadresse
  Comport(volatile SCI_REGS&r):regs(r) {}	// Konstruktor
// <constexpr> kennt der Compiler nicht!!
//  constexpr uint16_t BRR(float baud) {return F_CPU/8/baud-0.5;}
#define BRR(x) uint16_t(F_CPU/8/(float)(x)-0.5)
  void init(uint16_t brr);
// Im Normalfall wird "Text" transferiert, so als ob typeof(tx) == char* ist.
// Da im TMS320 ein char = 16 Bit ist, muss binary auf true gesetzt werden,
// um für Speicherabzüge und wchar_t* 2 Bytes pro Adresse zu senden bzw. zu empfangen.
// Im Binärmodus ist n = Anzahl der BYTES, Bit 1 von <binary> gibt den Startwert (Lo oder Hi) vor.
// So lassen sich Speicherbereiche bytegenau (Anfang UND Ende) transferieren
  void send(const uint8_t*tx, size_t n,uint8_t binary=false);
  void recv(uint8_t*rx, size_t n,uint8_t binary=false);
  enum{
    RxComplete=1,	// letztes Bit eingeschoben
    TxComplete=2,	// letztes Bit ausgeschoben
    TxDataOut=4,	// Daten(schwanz) komplett in Sende-FIFO
    RxStop=8,		// Empfang abbrechen oder neu vorbereiten
    TxStop=16,		// Senden abbrechen
  };
  void wait(uint8_t mask);	// Warten bis fertig (kein Handshake, dadurch endlich)
  void RxIsr();
  void TxIsr();
// synchron ohne Interrupt-Overhead, für Text und 12-MBaud-UART
  void send(char) const;
  void send(wchar_t) const;	// in UTF-8-Kodierung
  void send(const char*) const;
  void send(const wchar_t*) const;
  void send(const char*,size_t) const;
  void send(const wchar_t*,size_t) const;
//  void vprintf(const char*,va_list) const;
  void vprintf(const wchar_t*,va_list) const;
//  void printf(const char*,...) const;
  void printf(const wchar_t*,...) const;
  int recv() const;		// Liest 1 Byte, -1 wenn keins in der RxFifo
  int recv(char*) const;	// Liest 0..16 Bytes, liefert gelesene Zeichen
  char getchr() const;		// wartet (unendlich) bis 1 Byte angekommen ist, für UTF-8
  wchar_t getwchr() const;	// wartet (unendlich) bis ganze UTF-8-Sequenz angekommen ist
  int recv(wchar_t*) const;	// Liest 0..16 Zeichen, mit UTF-8-Dekodierung
};

// Other source file entries
void initMotorControl();	// MotorControl.cpp, ref: main.cpp
extern bool RunMotor;		// MotorControl.cpp, ref: main.cpp
void initSigmaDelta();		// sigmadelta.cpp, ref: main.cpp

#ifdef _FLASH
# define RAMFUNC __attribute__((ramfunc))
#else
# define RAMFUNC		// don't place into “.TI.ramfuncs” section
#endif

#ifdef _DEBUG
# define MONITOR		// visible in Expressions window
#else
# define MONITOR static		// suppress visibility
#endif
Detected encoding: UTF-80