Minimum Placid Platypus Trial

This commit is contained in:
Pascal Brisset
2009-09-08 20:15:47 +00:00
parent 26ba8b8827
commit 686a3cb18e
4 changed files with 232 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
<!DOCTYPE module SYSTEM "module.dtd">
<module name="MPPT">
<header>
<file name="MPPT.h"/>
</header>
<init fun="MPPT_init()"/>
<periodic fun="MPPT_periodic()" freq="4." delay="4" autorun="TRUE"/>
<makefile target="ap">
<file name="MPPT.c"/>
</makefile>
<makefile target="sim">
<file name="sim_MPPT.c"/>
</makefile>
</module>
+138
View File
@@ -0,0 +1,138 @@
/*
* $Id$
*
* Copyright (C) 2009 ENAC, Pascal Brisset, Michel Gorraz
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include <stdbool.h>
#include "MPPT.h"
#include "main_fbw.h"
#include "i2c.h"
#define MPPT_SLAVE_ADDR 0x40
#define NB_DATA 8
#define MPPT_MODE_ADDR 0xf
#define MPPT_IBAT_INDEX 1
/**
0: VBat (mV)
1: IBat (mA)
2: PBat (mW)
3: VSol (mV)
4: ISol (mA)
5: PSol (mW)
6: IConv (mA)
7: PConv (mW)
*/
#ifndef DOWNLINK_DEVICE
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
#endif
#include "uart.h"
#include "messages.h"
#include "downlink.h"
static volatile bool_t MPPT_i2c_done;
uint8_t MPPT_mode;
/** A value different from 0 is a request from this mode */
static uint8_t MPPT_status;
#define MPPT_STATUS_IDLE 0
#define MPPT_STATUS_WRITING 1
#define MPPT_STATUS_ASKING 2
#define MPPT_STATUS_READING 3
static uint8_t data_index = 0xff;
int16_t MPPT_data[NB_DATA];
void MPPT_init( void ) {
MPPT_mode = 0;
MPPT_status = MPPT_STATUS_IDLE;
MPPT_i2c_done = TRUE;
}
static void MPPT_ask( void ) {
data_index++;
if (data_index >= NB_DATA) {
/* Setting the current value */
fbw_current_milliamp = MPPT_data[MPPT_IBAT_INDEX];
DOWNLINK_SEND_MPPT(DefaultChannel, NB_DATA, MPPT_data);
data_index = 0;
}
i2c0_buf[0] = data_index;
i2c0_transmit(MPPT_SLAVE_ADDR, 1, &MPPT_i2c_done);
MPPT_i2c_done = FALSE;
MPPT_status = MPPT_STATUS_ASKING;
}
void MPPT_periodic( void ) {
// MPPT_i2c_done = TRUE;
if (MPPT_i2c_done) {
switch (MPPT_status) {
case MPPT_STATUS_IDLE:
/* If free, change mode if needed */
if (MPPT_mode) {
i2c0_buf[0] = MPPT_MODE_ADDR;
i2c0_buf[1] = 0;
i2c0_buf[2] = MPPT_mode;
i2c0_transmit(MPPT_SLAVE_ADDR, 3, &MPPT_i2c_done);
MPPT_i2c_done = FALSE;
MPPT_mode = 0;
MPPT_status = MPPT_STATUS_WRITING;
} else {
MPPT_ask();
}
break;
case MPPT_STATUS_WRITING:
MPPT_status = MPPT_STATUS_IDLE;
break;
case MPPT_STATUS_ASKING:
/* The slave should send 2 bytes */
i2c0_receive(MPPT_SLAVE_ADDR, 2, &MPPT_i2c_done);
MPPT_i2c_done = FALSE;
MPPT_status = MPPT_STATUS_READING;
break;
case MPPT_STATUS_READING:
/* We got 2 bytes */
if (data_index < NB_DATA)
MPPT_data[data_index] = (i2c0_buf[0]<<8) | i2c0_buf[1];
MPPT_status = MPPT_STATUS_IDLE;
break;
}
}
}
+46
View File
@@ -0,0 +1,46 @@
/*
* $Id$
*
* Copyright (C) 2009 ENAC, Pascal Brisset, Michel Gorraz
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
/** \file MPTT.h
* \brief Solar cells MPTT monitoring
*
*/
#ifndef MPPT_H
#define MPPT_H
#include <inttypes.h>
#define MPPT_MODE_OFF 1
#define MPPT_MODE_PASSIVE 2
#define MPPT_MODE_ACTIVE 3
extern uint8_t MPPT_mode;
void MPPT_init( void );
void MPPT_automata( void );
void MPPT_periodic( void );
#endif // MPPT_H
+32
View File
@@ -0,0 +1,32 @@
/*
* $Id$
*
* Copyright (C) 2009 ENAC, Pascal Brisset, Michel Gorraz
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include "MPPT.h"
void MPPT_init( void ) {
}
void MPPT_periodic( void ) {
}