Commit d90c5b7a authored by Alessio Igor Bogani's avatar Alessio Igor Bogani
Browse files

Changes

parent 442aaea3
......@@ -8,7 +8,7 @@
/****************************************************************************/
-cr /* Link using C conventions */
-stack 0x200
-stack 0x400
-heap 0x000
/* Specify the System Memory Map */
......
......@@ -127,7 +127,7 @@ struct pru2user_data_transfer {
volatile float SetPoint;
volatile unsigned long int IOStatus;
volatile float Debug0,Debug1,Debug2,Debug3;
volatile unsigned int Debug0,Debug1,Debug2,Debug3;
volatile float Kp,Ki,Kd,RampStep,Imin,Imax,Kff;
volatile int Reset; // 0xffff = retest interlocks
volatile unsigned int PRU0FirmRev;
......@@ -165,6 +165,9 @@ int main(void)
flagDC = 0; // resets flag for dclink warning
delay = 0;
p2udt.SetPoint = FLT_MAX;
p2udt.IOStatus = ULONG_MAX;
//init IO readback
IOStatus = 0x0;
......@@ -272,12 +275,18 @@ int main(void)
}
ReadIO();
}
Debug0++; // Cycle counter
if (SetPoint != p2udt.SetPoint || IOStatus != p2udt.IOStatus) {
Debug1++; // Change counter
p2udt.SetPoint = SetPoint;
p2udt.IOStatus = IOStatus;
#if 0
if (pru_rpmsg_receive(&transport, &src, &dst, &p2udt, &len) == PRU_RPMSG_SUCCESS) {
p2udt.SetPoint = SetPoint;
p2udt.IOStatus = IOStatus;
Debug2++; // Change notification
pru_rpmsg_send(&transport, dst, src, &p2udt, len);
}
#endif
}
}
}
......@@ -366,9 +375,9 @@ 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;
Debug1 = Integrator;
Debug2 = Derivator;
//Debug0 = regulator;
//Debug1 = Integrator;
//Debug2 = Derivator;
// pwm1offset e'l'offset per andare al 50% duty cycle (16056320 dec)
regulator=sum(regulator, (pwm1offset << 16));
......@@ -393,7 +402,7 @@ void Compensator(float SP, float Iout) // PWM frequency 100kHz, control loop 50
prev_error = error; // update error for derivative part
Debug3=pwm1corr;
//Debug3=pwm1corr;
//Debug2=pwm2corr;
......
......@@ -39,12 +39,14 @@ FILENAME : ReadADC.c DESIGN REF: MC18
//#include <stdio.h>
#include <pru_cfg.h>
#include <pru_intc.h>
#include <pru_ctrl.h>
//#include <rsc_types.h>
#include <pru_rpmsg.h>
#include "resource_table_1.h"
#include <limits.h>
#include <float.h>
#include <time.h>
volatile register uint32_t __R31;
......@@ -111,10 +113,10 @@ volatile float ScaleA3;
volatile float ScaleA4;
volatile float ScaleA5; // if needed cubic calibration: OutputCurrent = A0 + A1*avg + A2*avg^2 + A3*avg^3
volatile unsigned int ADC0, ADC1, ADC2, ADC3, ADC4, ADC5, ADC6;
volatile unsigned int ADC0, ADC1, ADC2, ADC2_previous, 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 unsigned int Debug0,Debug1,Debug2,Debug3;
struct pru2pru_data_transfer {
float OCnorm;
} p2pdt;
......@@ -123,7 +125,8 @@ volatile float OCnorm, OCnorm_previous;
struct pru2user_data_transfer {
float OCnorm;
unsigned int OVnorm;
} p2udt;
unsigned int num5ns;
} p2udt[20];
void SetSPI();
void SetADCBB();
......@@ -151,6 +154,9 @@ int main(void)
/* Clear the status of the PRU-ICSS system event that the ARM will use to 'kick' us */
CT_INTC.SICR_bit.STS_CLR_IDX = FROM_ARM_HOST;
/* Enable cycle counter */
PRU1_CTRL.CTRL_bit.CTR_EN = 1;
signed int Buffer[32];
signed int sum = 0, avg = 0;
......@@ -168,8 +174,9 @@ int main(void)
PRU1FirmRev = 20210415;
Debug0, Debug1, Debug2, Debug3 = 0;
p2udt.OCnorm = FLT_MAX;
p2udt.OVnorm = UINT_MAX;
OCnorm_previous = FLT_MAX;
ADC2_previous = UINT_MAX;
int data_index = 0;
//init SPI
SetSPI();
......@@ -217,7 +224,7 @@ int main(void)
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>31) i=0;
// check the sign make average on 16 samples, divide by 16 (shift 4 times)
......@@ -231,13 +238,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
......@@ -267,11 +274,30 @@ int main(void)
//ADC6 &= 0xff0; // read only one channel for digital FF
//ff=mpy((ADC6+0.0),0.005);
if (OCnorm != p2udt.OCnorm || ADC2 != p2udt.OVnorm) {
if (pru_rpmsg_receive(&transport, &src, &dst, &p2udt, &len) == PRU_RPMSG_SUCCESS) {
p2udt.OCnorm = OCnorm;
p2udt.OVnorm = ADC2;
pru_rpmsg_send(&transport, dst, src, &p2udt, len);
Debug0++; // Cycle
if (OCnorm != OCnorm_previous || ADC2 != ADC2_previous) {
Debug1++; // Change
OCnorm_previous = OCnorm;
ADC2_previous = ADC2;
if (data_index == 0) {
PRU1_CTRL.CYCLE = 1; // Reset counter
if (pru_rpmsg_receive(&transport, &src, &dst, &p2udt, &len) != PRU_RPMSG_SUCCESS) {
Debug2++; // Missing notification receive
continue;
}
}
p2udt[data_index].OCnorm = OCnorm;
p2udt[data_index].OVnorm = ADC2;
p2udt[data_index].num5ns = PRU1_CTRL.CYCLE;
data_index++;
if (data_index > 20) {
if (pru_rpmsg_send(&transport, dst, src, &p2udt, len) != PRU_RPMSG_SUCCESS) {
Debug3++; // Missing notification sent
}
data_index = 0;
}
}
}
......@@ -304,7 +330,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