again some bug fixes

This commit is contained in:
Mats van Reenen 2021-01-13 14:46:07 +01:00
parent ff4df01430
commit 4307102b72
4 changed files with 55 additions and 17 deletions

View File

@ -1,12 +1,23 @@
#include <stdint.h>
#include <ti/drivers/PWM.h> #include <ti/drivers/PWM.h>
#include "global.h" #include "global.h"
#include "MPPT.h" #include "MPPT.h"
#define US_TO_COUNT(n) n*1000 #define PWM_MIN 0.001
#define PWM_MAX 0.9
void mppt_vermogenOverride(uint8_t vermogen){ uint8_t mppt_setpoint, mppt_setpointOverrite;
return; uint8_t *mppt_setpointP;
PWM_Handle mppt_pwm;
void mppt_setSetpointOverride(uint8_t vermogen){
mppt_setpointOverrite = vermogen;
mppt_setpointP = &mppt_setpointOverrite;
}
void mppt_setSetpoint(uint8_t vermogen){
mppt_setpoint = vermogen;
} }
void mppt_init(){ void mppt_init(){
@ -14,12 +25,40 @@ void mppt_init(){
PWM_Params params; PWM_Params params;
PWM_Params_init(&params); PWM_Params_init(&params);
params.dutyUnits = PWM_PERIOD_COUNTS; params.dutyUnits = PWM_DUTY_FRACTION;
params.dutyValue = US_TO_COUNT(10); params.dutyValue = 0;
params.periodUnits = PWM_PERIOD_US; params.periodUnits = PWM_PERIOD_US;
params.periodValue = 0; params.periodValue = 0;
PWM_Handle pwm = PWM_open(CONFIG_PWM_0, &params); mppt_pwm = PWM_open(CONFIG_PWM_0, &params);
if (pwm == NULL) { if (mppt_pwm == NULL) {
while (1); while (1);
} }
mppt_setpointP = &mppt_setpoint;
} }
void mppt_setPWM(double d){
if(d < PWM_MIN){
PWM_setDuty(mppt_pwm, 0);
return;
}
if(d > PWM_MAX){
d = 0.9;
}
PWM_setDuty(mppt_pwm, (uint32_t) ((double) PWM_DUTY_FRACTION_MAX * d));
}
void mppt_start(){
PWM_start(mppt_pwm);
double duty = 0, step = 0.01;
while(Status == WORKING){
mppt_setPWM(duty);
duty += step;
if(duty > 1){
step = -step;
duty += step;
}
}
}

View File

@ -4,6 +4,8 @@
#include <stdint.h> #include <stdint.h>
void mppt_init(); void mppt_init();
void mppt_vermogenOverride(uint8_t vermogen); void mppt_start();
void mppt_setSetpointOverride(uint8_t vermogen);
void mppt_setSetpoint(uint8_t vermogen);
#endif #endif

View File

@ -70,20 +70,16 @@ void comm_spi(){
// read the data out the recive buffer // read the data out the recive buffer
switch (ReciveBuffer[0]){ switch (ReciveBuffer[0]){
case SPIPARM_maxVermogen: case SPIPARM_maxVermogen:
uint8_t maxVermogen = ReciveBuffer[2]; noodstop_setMaxVermogen(ReciveBuffer[2]);
noodstop_setMaxVermogen(maxVermogen);
break; break;
case SPIPARM_maxSnelheid: case SPIPARM_maxSnelheid:
uint16_t maxSnelheid = ReciveBuffer[2] + ReciveBuffer[3]*0x100; // convert littelendien noodstop_setMaxSnelheid(ReciveBuffer[2] + ReciveBuffer[3]*0x100);
noodstop_setMaxSnelheid(maxSnelheid);
break; break;
case SPIPARM_maxTempratuur: case SPIPARM_maxTempratuur:
uint8_t maxTemptratuur = &ReciveBuffer[2]; noodstop_setMaxTemptratuur(ReciveBuffer[2]);
noodstop_setMaxTemptratuur(maxTemptratuur);
break; break;
case SPIPARM_setpoint: case SPIPARM_setpoint:
uint8_t setpoint = &ReciveBuffer[2]; mppt_setSsetpoint(ReciveBuffer[2]);
mppt_setpoint(setpoint);
break; break;
} }
@ -93,4 +89,5 @@ void comm_spi(){
TransmitBuffer[0] = 0; TransmitBuffer[0] = 0;
usleep(5000); usleep(5000);
}
} }

View File

@ -36,7 +36,7 @@ void noodstop_snelhied(uint16_t snelhied){
// controleer snelheid // controleer snelheid
if(snelhied > nood_maxwaardes.maxSnelheid){ if(snelhied > nood_maxwaardes.maxSnelheid){
// PANIC!! // PANIC!!
mppt_vermogenOverride(nood_maxwaardes.maxVermogen); mppt_setSetpointOverride(nood_maxwaardes.maxVermogen);
// Wacht 0.5 seconde // Wacht 0.5 seconde
usleep(500E3); usleep(500E3);