again some bug fixes
This commit is contained in:
parent
ff4df01430
commit
4307102b72
53
src/MPPT.c
53
src/MPPT.c
@ -1,12 +1,23 @@
|
||||
#include <stdint.h>
|
||||
#include <ti/drivers/PWM.h>
|
||||
|
||||
#include "global.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){
|
||||
return;
|
||||
uint8_t mppt_setpoint, mppt_setpointOverrite;
|
||||
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(){
|
||||
@ -14,12 +25,40 @@ void mppt_init(){
|
||||
|
||||
PWM_Params params;
|
||||
PWM_Params_init(¶ms);
|
||||
params.dutyUnits = PWM_PERIOD_COUNTS;
|
||||
params.dutyValue = US_TO_COUNT(10);
|
||||
params.dutyUnits = PWM_DUTY_FRACTION;
|
||||
params.dutyValue = 0;
|
||||
params.periodUnits = PWM_PERIOD_US;
|
||||
params.periodValue = 0;
|
||||
PWM_Handle pwm = PWM_open(CONFIG_PWM_0, ¶ms);
|
||||
if (pwm == NULL) {
|
||||
mppt_pwm = PWM_open(CONFIG_PWM_0, ¶ms);
|
||||
if (mppt_pwm == NULL) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,8 @@
|
||||
#include <stdint.h>
|
||||
|
||||
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
|
||||
@ -70,20 +70,16 @@ void comm_spi(){
|
||||
// read the data out the recive buffer
|
||||
switch (ReciveBuffer[0]){
|
||||
case SPIPARM_maxVermogen:
|
||||
uint8_t maxVermogen = ReciveBuffer[2];
|
||||
noodstop_setMaxVermogen(maxVermogen);
|
||||
noodstop_setMaxVermogen(ReciveBuffer[2]);
|
||||
break;
|
||||
case SPIPARM_maxSnelheid:
|
||||
uint16_t maxSnelheid = ReciveBuffer[2] + ReciveBuffer[3]*0x100; // convert littelendien
|
||||
noodstop_setMaxSnelheid(maxSnelheid);
|
||||
noodstop_setMaxSnelheid(ReciveBuffer[2] + ReciveBuffer[3]*0x100);
|
||||
break;
|
||||
case SPIPARM_maxTempratuur:
|
||||
uint8_t maxTemptratuur = &ReciveBuffer[2];
|
||||
noodstop_setMaxTemptratuur(maxTemptratuur);
|
||||
noodstop_setMaxTemptratuur(ReciveBuffer[2]);
|
||||
break;
|
||||
case SPIPARM_setpoint:
|
||||
uint8_t setpoint = &ReciveBuffer[2];
|
||||
mppt_setpoint(setpoint);
|
||||
mppt_setSsetpoint(ReciveBuffer[2]);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -93,4 +89,5 @@ void comm_spi(){
|
||||
TransmitBuffer[0] = 0;
|
||||
|
||||
usleep(5000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ void noodstop_snelhied(uint16_t snelhied){
|
||||
// controleer snelheid
|
||||
if(snelhied > nood_maxwaardes.maxSnelheid){
|
||||
// PANIC!!
|
||||
mppt_vermogenOverride(nood_maxwaardes.maxVermogen);
|
||||
mppt_setSetpointOverride(nood_maxwaardes.maxVermogen);
|
||||
|
||||
// Wacht 0.5 seconde
|
||||
usleep(500E3);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user