Compare commits
2 Commits
b858d29ce8
...
d215e204d4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d215e204d4 | ||
|
|
458ae00f24 |
@ -1,5 +1,5 @@
|
|||||||
#include "command-handler.h"
|
#include "command-handler.h"
|
||||||
#include "fan_speeeed.h"
|
#include "fan-speed.h"
|
||||||
|
|
||||||
// Initialize empty, global command context
|
// Initialize empty, global command context
|
||||||
volatile command_context_t context = {UNKNOWN_COMMAND, SRC_NONE, FAN_NONE,
|
volatile command_context_t context = {UNKNOWN_COMMAND, SRC_NONE, FAN_NONE,
|
||||||
@ -169,6 +169,10 @@ uint8_t route_command(int pos) {
|
|||||||
|
|
||||||
// Set the flag to store it in the EEPROM
|
// Set the flag to store it in the EEPROM
|
||||||
store_config = true;
|
store_config = true;
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
case CNF_NONE:
|
||||||
|
return 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -273,6 +277,7 @@ uint8_t route_command(int pos) {
|
|||||||
} else if (context.fan == FAN2) {
|
} else if (context.fan == FAN2) {
|
||||||
memset(fan2_history, 0, sizeof(fan2_history));
|
memset(fan2_history, 0, sizeof(fan2_history));
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
break;
|
break;
|
||||||
case UNKNOWN_COMMAND:
|
case UNKNOWN_COMMAND:
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -67,8 +67,8 @@ typedef struct {
|
|||||||
extern volatile uint16_t fan1_history[512];
|
extern volatile uint16_t fan1_history[512];
|
||||||
extern volatile uint16_t fan2_history[512];
|
extern volatile uint16_t fan2_history[512];
|
||||||
// Fan history index variable
|
// Fan history index variable
|
||||||
volatile uint16_t fan1_history_index = 0;
|
extern volatile uint16_t fan1_history_index;
|
||||||
volatile uint16_t fan2_history_index = 0;
|
extern volatile uint16_t fan2_history_index;
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
extern volatile config_t config;
|
extern volatile config_t config;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#include "fan_speeeed.h"
|
#include "fan-speed.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
|
||||||
uint16_t timer_period_ms = 1;
|
uint16_t timer_period_ms = 1;
|
||||||
@ -33,8 +33,8 @@ extern "C" {
|
|||||||
extern volatile uint16_t fan1_history[512];
|
extern volatile uint16_t fan1_history[512];
|
||||||
extern volatile uint16_t fan2_history[512];
|
extern volatile uint16_t fan2_history[512];
|
||||||
// Fan history index variable
|
// Fan history index variable
|
||||||
volatile uint16_t fan1_history_index = 0;
|
extern volatile uint16_t fan1_history_index;
|
||||||
volatile uint16_t fan2_history_index = 0;
|
extern volatile uint16_t fan2_history_index;
|
||||||
|
|
||||||
// INITALICE TIMER COUNTER
|
// INITALICE TIMER COUNTER
|
||||||
void init_TCA0();
|
void init_TCA0();
|
||||||
@ -14,7 +14,6 @@ extern "C" {
|
|||||||
|
|
||||||
// Include the IO for I2C
|
// Include the IO for I2C
|
||||||
#include "command-handler.h"
|
#include "command-handler.h"
|
||||||
#include "uart.h"
|
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|||||||
@ -4,28 +4,39 @@
|
|||||||
*
|
*
|
||||||
* Created on March 6, 2024, 12:34 PM
|
* Created on March 6, 2024, 12:34 PM
|
||||||
*/
|
*/
|
||||||
#include "uart.h"
|
#define F_CPU 4E6
|
||||||
#include "voltage.h"
|
|
||||||
#include <stdbool.h>
|
// Include AVR specific libs
|
||||||
#define RTC_PERIOD (511)
|
|
||||||
#define DELAY_TIME 1000
|
|
||||||
#include "eeprom.h"
|
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
// Include standard C libraries
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#define F_CPU 4E6
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// Include custom source files
|
||||||
|
#include "eeprom.h"
|
||||||
|
#include "voltage.h"
|
||||||
#include "command-handler.h"
|
#include "command-handler.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "themistor-temp.h"
|
#include "themistor-temp.h"
|
||||||
|
#include "fan-speed.h"
|
||||||
|
|
||||||
|
// Only enable UART when required for debugging
|
||||||
|
#ifdef ENABLE_UART
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include <avr/io.h>
|
#endif
|
||||||
#include <stdint.h>
|
|
||||||
#include <util/delay.h>
|
|
||||||
|
|
||||||
// Fan history variables
|
// Fan history variables
|
||||||
volatile uint16_t fan1_history[512] = {0};
|
volatile uint16_t fan1_history[512] = {0};
|
||||||
volatile uint16_t fan2_history[512] = {0};
|
volatile uint16_t fan2_history[512] = {0};
|
||||||
|
// Fan history index variable
|
||||||
|
volatile uint16_t fan1_history_index = 0;
|
||||||
|
volatile uint16_t fan2_history_index = 0;
|
||||||
|
|
||||||
// Default config is 500ms sample rate
|
// Default config is 500ms sample rate
|
||||||
volatile config_t config = {500};
|
volatile config_t config = {500};
|
||||||
@ -33,17 +44,25 @@ volatile bool store_config = false;
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// Initialize functionality
|
// Initialize functionality
|
||||||
init_uart((uint16_t)9600);
|
|
||||||
ADC0_init();
|
ADC0_init();
|
||||||
init_led();
|
init_alarm_gpio();
|
||||||
init_i2c();
|
init_i2c();
|
||||||
|
|
||||||
|
// Fanspeed
|
||||||
|
init_AC0();
|
||||||
|
init_AC1();
|
||||||
|
init_TCA0();
|
||||||
|
|
||||||
|
// Only enable UART when required for debugging
|
||||||
|
#ifdef ENABLE_UART
|
||||||
|
init_uart((uint16_t)9600);
|
||||||
stdout = &USART_stream;
|
stdout = &USART_stream;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Read the stored config struct
|
// Read the stored config struct
|
||||||
config = read_struct_from_EEPROM();
|
config = read_struct_from_EEPROM();
|
||||||
|
|
||||||
PORTB.DIRSET = PIN3_bm;
|
// Enable interrupts
|
||||||
|
|
||||||
sei();
|
sei();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|||||||
@ -6,11 +6,11 @@
|
|||||||
projectFiles="true">
|
projectFiles="true">
|
||||||
<itemPath>uart.h</itemPath>
|
<itemPath>uart.h</itemPath>
|
||||||
<itemPath>voltage.h</itemPath>
|
<itemPath>voltage.h</itemPath>
|
||||||
<itemPath>fan_speeeed.h</itemPath>
|
|
||||||
<itemPath>themistor-temp.h</itemPath>
|
<itemPath>themistor-temp.h</itemPath>
|
||||||
<itemPath>command-handler.h</itemPath>
|
<itemPath>command-handler.h</itemPath>
|
||||||
<itemPath>eeprom.h</itemPath>
|
<itemPath>eeprom.h</itemPath>
|
||||||
<itemPath>i2c.h</itemPath>
|
<itemPath>i2c.h</itemPath>
|
||||||
|
<itemPath>fan-speed.h</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="ExternalFiles"
|
<logicalFolder name="ExternalFiles"
|
||||||
displayName="Important Files"
|
displayName="Important Files"
|
||||||
@ -28,11 +28,11 @@
|
|||||||
<itemPath>main.c</itemPath>
|
<itemPath>main.c</itemPath>
|
||||||
<itemPath>uart.c</itemPath>
|
<itemPath>uart.c</itemPath>
|
||||||
<itemPath>voltage.c</itemPath>
|
<itemPath>voltage.c</itemPath>
|
||||||
<itemPath>fan_speeeed.c</itemPath>
|
|
||||||
<itemPath>thermistor-temp.c</itemPath>
|
<itemPath>thermistor-temp.c</itemPath>
|
||||||
<itemPath>command-handler.c</itemPath>
|
<itemPath>command-handler.c</itemPath>
|
||||||
<itemPath>i2c.c</itemPath>
|
<itemPath>i2c.c</itemPath>
|
||||||
<itemPath>eeprom.c</itemPath>
|
<itemPath>eeprom.c</itemPath>
|
||||||
|
<itemPath>fan-speed.c</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<projectmakefile>Makefile</projectmakefile>
|
<projectmakefile>Makefile</projectmakefile>
|
||||||
|
|||||||
@ -23,7 +23,8 @@ extern "C" {
|
|||||||
#define T_0 298.15
|
#define T_0 298.15
|
||||||
#define B 3950
|
#define B 3950
|
||||||
#define R_1 1000
|
#define R_1 1000
|
||||||
#define ledpin PIN3_bm
|
|
||||||
|
#define ALERT_PIN PIN3_bm
|
||||||
|
|
||||||
// Takes inn messured value
|
// Takes inn messured value
|
||||||
// Calculates the temperature in celcius
|
// Calculates the temperature in celcius
|
||||||
@ -36,8 +37,8 @@ bool voltage_threshold_bool(float thermistor_temp, uint8_t max_temp);
|
|||||||
|
|
||||||
void alert_voltage_threshold_exceeded(bool voltage_threshold_bool);
|
void alert_voltage_threshold_exceeded(bool voltage_threshold_bool);
|
||||||
|
|
||||||
// Initialise led
|
// Initialise alarm GPIO
|
||||||
void init_led();
|
void init_alarm_gpio();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#include "themistor-temp.h"
|
#include "themistor-temp.h"
|
||||||
|
|
||||||
|
|
||||||
void init_led(){
|
void init_alarm_gpio(){
|
||||||
PORTB.DIRSET = ledpin;
|
PORTB.DIRSET = ALERT_PIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
float calculate_thermistor_temp(float thermistor_voltage){
|
float calculate_thermistor_temp(float thermistor_voltage){
|
||||||
@ -42,8 +42,8 @@ bool voltage_threshold_bool(float thermistor_temp, uint8_t max_temp){
|
|||||||
void alert_voltage_threshold_exceeded(bool voltage_threshold_bool){
|
void alert_voltage_threshold_exceeded(bool voltage_threshold_bool){
|
||||||
if (voltage_threshold_bool){
|
if (voltage_threshold_bool){
|
||||||
printf("Error: maximum temperature exceeded");
|
printf("Error: maximum temperature exceeded");
|
||||||
PORTB.OUTSET = ledpin;
|
PORTB.OUTSET = ALERT_PIN;
|
||||||
} else{
|
} else{
|
||||||
PORTB.OUTCLR = ledpin;
|
PORTB.OUTCLR = ALERT_PIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user