This repository has been archived on 2024-01-25. You can view files and clone it, but cannot push or open issues or pull requests.
Solar-Panel/main.c

71 lines
1.9 KiB
C
Raw Normal View History

2023-03-15 11:55:57 +00:00
/*!
* @file main.c
* @authors Simon Donnet-Monay & Remi Heredero
* @date 14 march 2023
* @brief Main is in two part.
* First for setup everything
* Second for loop on measure and set duty cycle for PWM
*/
2023-03-09 15:06:17 +00:00
#include "mcc_generated_files/mcc.h"
#include "lcd/lcd.h"
#include "measure.h"
#include "modbus.h"
2023-03-15 11:55:57 +00:00
#define MAX_COL 16 //!< columns for lcd screen (and 2 rows)
2023-03-10 12:39:55 +00:00
2023-03-15 11:55:57 +00:00
void main(void) {
/*!
* SETUP FUNCTIONS:
*/
//! Initialize the system with all mcc default configs
2023-03-09 15:06:17 +00:00
SYSTEM_Initialize();
2023-03-15 11:55:57 +00:00
Lcd_Init(); //! Initialize lcd screen
adc_init(); //! Initialize adc for measures
modbus_init(0x80); //! Initialize all specific modbus function
2023-03-09 15:06:17 +00:00
2023-03-15 11:55:57 +00:00
//! Enable the Global Interrupts
2023-03-09 15:06:17 +00:00
INTERRUPT_GlobalInterruptEnable();
2023-03-15 11:55:57 +00:00
//! Enable the Peripheral Interrupts
2023-03-09 15:06:17 +00:00
INTERRUPT_PeripheralInterruptEnable();
2023-03-15 11:55:57 +00:00
/*!
* Initialize offset current.
* 1. disable load
* 2. Measure current without load
*
* The goal it's to remove the offset due to the electronics parts
*/
EPWM1_LoadDutyValue(0);
const uint16_t offsetCurrent = measure_current(offsetCurrent);
2023-03-15 11:55:57 +00:00
//! create a char array for display on lcd (with space for '\0')
char msg[MAX_COL+1];
2023-03-15 11:55:57 +00:00
/*!
* LOOP MAIN PROGRAM:
*/
while (1) {
//! Get the measure and save it and the appropriate register
input_registers[0] = measure_voltage();
input_registers[1] = measure_current(offsetCurrent);
2023-03-09 15:06:17 +00:00
2023-03-15 11:55:57 +00:00
//! Print on the first row of the lcd the Voltage
sprintf(msg, "U = %04d [mV] ", input_registers[0]);
2023-03-09 15:06:17 +00:00
LCD_2x16_WriteMsg(msg,0);
2023-03-15 11:55:57 +00:00
//! Print on the second row of the lcd the current
sprintf(msg, "I = %04d [uA] ", input_registers[1]);
2023-03-09 15:06:17 +00:00
LCD_2x16_WriteMsg(msg,1);
2023-03-15 11:55:57 +00:00
//! Write the duty cycle for pwm from the appropriate register
EPWM1_LoadDutyValue(holding_registers[0]);
2023-03-09 15:06:17 +00:00
}
2023-03-15 11:55:57 +00:00
}