Commit 6aeeb6c2 authored by Alessio Igor Bogani's avatar Alessio Igor Bogani
Browse files

Retrieve PRUs cycle counters

parent 959c6b9d
......@@ -35,6 +35,9 @@ FILENAME : ControlLoop.c DESIGN REF: MC18
*/
#include <stdint.h>
#include <pru_cfg.h>
#include <pru_ctrl.h>
#define HWREG(x) (*((volatile unsigned int *)(x)))
#define HWREGH(x) (*((volatile unsigned short *)(x)))
......@@ -68,7 +71,8 @@ volatile int Run; // while 0xFFFF run compensator
volatile float OutputCurrent;
volatile float SetPoint;
volatile unsigned long int IOStatus;
volatile float Debug0,Debug1,Debug2,Debug3;
volatile float Debug2,Debug3;
volatile int Debug0, Debug1;
volatile float Kp,Ki,Kd,RampStep,Imin,Imax,Kff;
volatile int Reset; // 0xffff = retest interlocks
volatile unsigned int PRU0FirmRev;
......@@ -89,12 +93,16 @@ int main(void)
{
//enable OCP master ports in SYSCFG (PRU_ICSS_CFG)
HWREG(0x26004) = 0x2A;
//CT_CFG.SYSCFG_bit.STANDBY_INIT = 0; // Enable OCP master port
PRU0FirmRev = 20200827;
trigger = 1; //for pulse operation
timer = 0;
flagDC = 0; // resets flag for dclink warning
delay = 0;
uint32_t cycle, stall;
PRU0_CTRL.CTRL_bit.CTR_EN = 1; // Enable cycle counter
//init IO readback
IOStatus = 0x0;
......@@ -128,9 +136,10 @@ int main(void)
//HWREG(0x481AC190) = 0b1000000000;
//__delay_cycles(200000000);
PRU0_CTRL.CTRL_bit.CTR_EN = 1; // Enable cycle counter
while((Run == 0xffff) && ((IOStatus & 0xfdffffff) == 0))
while((Run == 0xffff) && ((IOStatus & 0xfdffffff) == 0))
// 0xfdffffff is masking dc-link warning contact on 25th bit, so if a warning happens the converter is not switched off
{
//syncronize with T0
......@@ -140,12 +149,20 @@ int main(void)
HWREG(0x481AC194) = 0b10; // GPIO2_SETDATAOUT gpio2_1
#endif
PRU0_CTRL.STALL = PRU0_CTRL.CYCLE = 1; // Reset counter
Compensator(SetPoint, OutputCurrent);
ReadIO();
#ifdef benchmark
HWREG(0x481AC190)= 0b10; // GPIO2_CLEARDATAOUT gpio2_1 P8_18
#endif
cycle = PRU0_CTRL.CYCLE;
stall = PRU0_CTRL.STALL;
Debug0 = cycle;
Debug1 = stall;
}
// converter is switched off
......@@ -266,7 +283,7 @@ void Compensator(float SP, float Iout) // PWM frequency 100kHz, control loop 50
//regulator = sum(mpy(Kp, error), Integrator);
regulator = sum(sum(mpy(Kp, error), Integrator), Derivator);
Debug0=regulator;
//Debug0=regulator;
// pwm1offset e'l'offset per andare al 50% duty cycle (16056320 dec)
regulator=sum(regulator, (pwm1offset << 16));
......@@ -291,8 +308,8 @@ void Compensator(float SP, float Iout) // PWM frequency 100kHz, control loop 50
prev_error = error; // update error for derivative part
//Debug0 = regulator;
Debug1 = Integrator;
Debug2 = Derivator;
//Debug1 = Integrator;
//Debug2 = Derivator;
//Debug1=pwm1corr;
//Debug2=pwm2corr;
......
......@@ -66,6 +66,10 @@ FILENAME : ReadADC.c DESIGN REF: MC18
#pragma LOCATION(OutputCurrent,0x2004) // punta alla memoria del pru successivo che e'0004
//#pragma LOCATION(ff,0x2040)
#include <stdint.h>
#include <pru_cfg.h>
#include <pru_ctrl.h>
volatile float ScaleA0;
volatile float ScaleA1;
volatile float ScaleA2;
......@@ -76,7 +80,8 @@ volatile float ScaleA5; // if needed cubic calibration: OutputCurrent = A0 + A1
volatile unsigned int ADC0, ADC1, ADC2, ADC3, ADC4, ADC5, ADC6;
// ADC0=Aux V, ADC1=Heater temp, ADC2=Out V, ADC3=dc link, ADC4=3.3V, ADC5=heatsink temp, ADC6=5V
volatile unsigned int PRU1FirmRev;
volatile float Debug0,Debug1,Debug2,Debug3;
volatile float Debug2,Debug3;
volatile int Debug0, Debug1;
volatile float OutputCurrent;
volatile float OCnorm;
......@@ -105,7 +110,11 @@ int main(void)
unsigned int i, j, temp;
volatile unsigned int *po = &ADC0;
uint32_t cycle, stall;
//CT_CFG.SYSCFG_bit.STANDBY_INIT = 0; // Enable OCP master port
PRU1_CTRL.CTRL_bit.CTR_EN = 1; // Enable cycle counter
ADC0=0;ADC1=0;ADC2=0;ADC3=0;ADC4=0;ADC5=0;ADC6=0;
PRU1FirmRev = 20210401;
......@@ -132,13 +141,14 @@ int main(void)
#ifdef benchmark1
HWREG(0x481ac194) = 0b1000000000;// gpio2_9 P8-44 // bit 1, pin p8-18 GPIO2_1 GPIO2_SETDATAOUT
#endif
PRU1_CTRL.STALL = PRU1_CTRL.CYCLE = 1; // Reset counter
//i = i%16; // 32
sum -= Buffer[i]; //substract old sample
Buffer[i] = GetADC(); //get new sample
sum += Buffer[i]; //add new sample
Debug0 = Buffer[i];
//Debug0 = Buffer[i];
i++;
if (i>7) i=0;
// check the sign make average on 16 samples, divide by 16 (shift 4 times)
......@@ -152,13 +162,13 @@ int main(void)
//avg=GetADC();
// scale the output currrent
Debug1 = avg;
//Debug1 = avg;
//OCnorm = mpy((float) avg,9.536752259018191355E-7); // divide by fffff/9.536752259018191355E-7 16samples 20bit (>>1)
//OCnorm = mpy((float) avg,7.6294527393E-6); // divide by 1ffff/7.6294527393E-6 18bit (>>3)
//OCnorm = mpy((float) avg,1.9073504518E-6); // divide by 7ffff/1.9073504518E-6 20bit (>>1)
OCnorm = mpy((float) avg,12.3023170647082461E-6); // divided by (1ffff*1.612) // dovrebbe essere diviso per il max valore ammissibile
Debug2=OCnorm;
//Debug2=OCnorm;
// even coefficients negated
// 40us execution time
......@@ -171,7 +181,12 @@ int main(void)
#ifdef benchmark1
HWREG(0x481ac190) = 0b1000000000;// gpio2_9 P8_44 // GPIO2_CLEARDATAOUT
#endif
cycle = PRU1_CTRL.CYCLE;
stall = PRU1_CTRL.STALL;
Debug0 = cycle;
Debug1 = stall;
// all signs positive
//OutputCurrent = -(ScaleA0+(ScaleA1*OCnorm)+(ScaleA2*OCnorm*OCnorm)+(ScaleA3*OCnorm*OCnorm*OCnorm)+(ScaleA4*OCnorm*OCnorm*OCnorm*OCnorm)+(ScaleA5*OCnorm*OCnorm*OCnorm*OCnorm*OCnorm))*20.0;
......@@ -217,7 +232,7 @@ signed int GetADC()
// positive 00000-1FFFF (0 - 131071dec) 0V _ 10V all'ingresso
if(retval >= 0x20000) // negative 20000-3FFFF (131072 - 262143dec) -10V _ 0V
retval |= 0xFFFE0000; // 1111|1111|1111|1110|0|0|0|0
Debug1=retval;
//Debug1=retval;
return retval;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment