Compare commits

..

37 Commits

Author SHA1 Message Date
Sebastian H. Gabrielli
275c40498f Merge branch 'fanspeed-comparator' 2024-04-30 10:59:47 +02:00
772960d046 Fix comment, variables and function
add referance
2024-04-29 08:57:02 +02:00
ac5a054f8b no worries 2024-04-27 18:45:04 +02:00
f0a435d578 add comment 2024-04-27 17:31:00 +02:00
e01c4d41ad add second fan 2024-04-27 17:26:35 +02:00
10c82d001e Fixed fanspeed 2024-04-26 17:00:04 +02:00
f2019dd57a timer not worke 2024-04-26 15:47:02 +02:00
022ccb13a0 timer 2024-04-26 15:20:28 +02:00
6528a82b04 works 2024-04-26 15:13:45 +02:00
eb7d96dd82 maybe 2024-04-25 14:06:51 +02:00
8649d59d8d add positive edge 2024-04-25 12:29:10 +02:00
c9b220616d clean comments 2024-04-24 14:24:40 +02:00
a48a089a3c works but not freq 2024-04-21 12:43:51 +02:00
57a35a483d Merge branch 'tmp' into calculate-fanspeed 2024-04-17 15:03:34 +02:00
abc13364ec comment somehting 2024-04-17 14:59:46 +02:00
58014e17d1 not this 2024-04-16 13:25:51 +02:00
9cf37461d2 Add something stuff, not work 2024-04-10 15:52:07 +02:00
14c09f63a9 MCC does not work 2024-04-10 14:53:17 +02:00
Inamr
23904b03ea right pins 2024-04-09 16:46:54 +02:00
Inamr
63aa397b78 testing with hardware
cli and function names
2024-04-09 16:17:34 +02:00
cd97face0f Fix xml file (maybe) 2024-04-09 15:39:11 +02:00
Inamr
a6d1afb0bf removed old funv from main. copied config from main 2024-04-09 15:26:13 +02:00
Inamr
f1c9a0707e made code for fan speed 2024-04-09 14:53:32 +02:00
Inamr
9b23172eba Merge branch 'voltage-reading' into calculate-fanspeed 2024-04-09 12:38:34 +02:00
Inamr
48308b9b75 renames files 2024-03-20 15:27:59 +01:00
Inamr
ce58f79c6f renamed files 2024-03-20 15:27:41 +01:00
Inamr
dc8a858204 resets array and puts diode readings in array 2024-03-20 15:25:59 +01:00
Inamr
8b5b4e186a Merge remote-tracking branch 'origin/voltage-reading' into calculate-fanspeed 2024-03-20 14:52:28 +01:00
Inamr
427000ff9e made array 2024-03-20 14:36:58 +01:00
Inamr
88415ddec1 RTC init and timer 2024-03-20 12:33:03 +01:00
Inamr
df3d0c6ce6 made interrupts as timer 2024-03-19 14:29:57 +01:00
Inamr
9aa9c444c1 Fix libaries 2024-03-19 13:11:52 +01:00
Inamr
d14044e8df Made a formula for calc speed 2024-03-19 12:59:56 +01:00
Inamr
49c0874445 delete unused source file 2024-03-19 12:30:20 +01:00
Inamr
b7e6bb6d04 made func 2024-03-13 13:58:14 +01:00
Inamr
a0fa78405a made func 2024-03-13 13:57:38 +01:00
Inamr
a4a760a870 Made files 2024-03-13 13:39:35 +01:00
6 changed files with 8368 additions and 72 deletions

107
prosjekt.X/fan_speeeed.c Normal file
View File

@ -0,0 +1,107 @@
#include "fan_speeeed.h"
#include "uart.h"
uint16_t timer_period_ms = 1;
uint16_t fan_speed = 0;
volatile uint16_t fan1_edge_counter = 0;
volatile uint16_t fan2_edge_counter = 0;
void init_TCA0() {
TCA0.SINGLE.INTCTRL = TCA_SINGLE_OVF_bm ;
TCA0.SINGLE.CTRLA = TCA_SINGLE_ENABLE_bm | TCA_SINGLE_CLKSEL_DIV1024_gc ; /* Sysclk /1024 */
TCA0_update_period(timer_period_ms);
}
void TCA0_update_period(uint16_t timer_period) {
TCA0.SINGLE.PERBUF = (F_CPU * (1 / timer_period) / 1024); /* F_CPU * F_IRQ / TCA_prescaler */
}
// COUNTINGS / TIME = FREQUENCY
// FREQ / 2 = GIVES ACTUAL FREQ
// FREQ * SEC-IN-A-MINUTE(60) / FAN-BLADES
uint16_t RPM_calculation(uint16_t edge_counter, uint16_t time_ms) {
fan_speed = (edge_counter / time_ms);
fan_speed = fan_speed/2;
fan_speed = fan_speed * 60/5;
edge_counter = 0;
return fan_speed;
}
void init_fan_gpio() {
// CONFIGURE PINS AS ANALOG INPUTS
// PIN FOR FAN 1
PORTD.DIRSET &= ~PIN6_bm;
PORTD.PIN6CTRL &= ~ PORT_ISC_gm;
PORTD.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc;
// PIN FOR FAN 2
PORTD.DIRSET &= ~PIN4_bm;
PORTD.PIN4CTRL &= ~ PORT_ISC_gm ;
PORTD.PIN4CTRL = PORT_ISC_INPUT_DISABLE_gc;
// PIN FOR REFRENCE
PORTD.DIRSET &= PIN7_bm;
PORTD.PIN7CTRL &= ~ PORT_ISC_gm ;
PORTD.PIN7CTRL = PORT_ISC_INPUT_DISABLE_gc;
}
void init_AC0(){
//Wincontroll disabled
AC0.CTRLB = 0x00;
//SELECT POSITIVE AND NEGATIVE INPUTS FOR COMPARRISON
// FAN USE PD6 COMPARE WITH PD3
AC0.MUXCTRL = AC_MUXPOS_AINP3_gc | AC_MUXNEG_AINN2_gc;
// ENABLE AC BY WRITING 1 TO ENABLE BIT IN ACN.CTRLA
AC0.CTRLA = AC_ENABLE_bm | AC_INTMODE_NORMAL_POSEDGE_gc | AC_OUTEN_bm;
// TURN ON INTERUPT
AC0.INTCTRL = 0x01;
}
void init_AC1(){
//Wincontroll disabled
AC1.CTRLB = 0x00;
//SELECT POSITIVE AND NEGATIVE INPUTS FOR COMPARRISON
// FAN USE PD4, COMPARE WITH PD3
AC1.MUXCTRL = AC_MUXPOS_AINP2_gc | AC_MUXNEG_AINN2_gc;
// ENABLE AC BY WRITING 1 TO ENABLE BIT IN ACN.CTRLA
AC1.CTRLA = AC_ENABLE_bm | AC_INTMODE_NORMAL_POSEDGE_gc | AC_OUTEN_bm;
// TURN ON INTERUPT
AC1.INTCTRL = 0x01;
}
ISR(AC0_AC_vect){ // AC0 vec flag
cli();
fan1_edge_counter++;
AC0.STATUS |= 0x10; //CMP flag to 0
sei();
}
ISR(AC1_AC_vect){ // AC1 vec flag
cli();
fan2_edge_counter++;
AC1.STATUS |= 0x10; //CMP flag to 0
sei();
}
// TIMER INTERUPT
ISR (TCA0_OVF_vect) {
cli();
RPM_calculation(fan1_edge_counter,timer_period_ms);
RPM_calculation(fan2_edge_counter,timer_period_ms);
fan1_edge_counter = 0;
fan2_edge_counter = 0;
TCA0.SINGLE.INTFLAGS = TCA_SINGLE_OVF_bm ;
sei();
}

57
prosjekt.X/fan_speeeed.h Normal file
View File

@ -0,0 +1,57 @@
/*
* File: fanseeeed.h
* Author: inami, Helle Augland Grasmo
*
* Created on 13. mars 2024, 13:38
*/
#ifndef FANSEEEED_H
#define FANSEEEED_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <float.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <avr/interrupt.h>
#include <avr/io.h>
/*
The code has inspiration from "Getting Started with Analog comparator(AC)" by Microchip for setting up analog comparrator.
* web link: https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ApplicationNotes/ApplicationNotes/TB3211-Getting-Started-with-AC-DS90003211.pdf
* and inspiration form practice 6 for TCA0 setup
*/
// INITALICE TIMER COUNTER
void init_TCA0();
// UPDATE TIMER PERIOD
void TCA0_update_period_ms (uint16_t timer_period);
// TAKES INN A TIME AND A THE COUNTED FAN DIPS
// RETURNS THE RPM OF THE FAN
uint16_t RPM_calculation(uint16_t edge_counter, uint16_t time_ms);
// INITIALISING FAN PORTS
void init_fan_gpio();
// INIT AC0 TO COMPARE PD6 AND PD7
void init_AC0();
// INIT AC1 TO COMPARE PD4 AND PD7
void init_AC1();
#ifdef __cplusplus
}
#endif
#endif /* FANSEEEED_H */

View File

@ -4,9 +4,9 @@
* *
* Created on March 6, 2024, 12:34 PM * Created on March 6, 2024, 12:34 PM
*/ */
#include <stdbool.h>
#include "uart.h" #include "uart.h"
#include "voltage.h" #include "voltage.h"
#include <stdbool.h>
#define RTC_PERIOD (511) #define RTC_PERIOD (511)
#define DELAY_TIME 1000 #define DELAY_TIME 1000
#include "eeprom.h" #include "eeprom.h"

View File

@ -4,17 +4,19 @@
<logicalFolder name="HeaderFiles" <logicalFolder name="HeaderFiles"
displayName="Header Files" displayName="Header Files"
projectFiles="true"> projectFiles="true">
<itemPath>command-handler.h</itemPath>
<itemPath>i2c.h</itemPath>
<itemPath>themistor-temp.h</itemPath>
<itemPath>uart.h</itemPath> <itemPath>uart.h</itemPath>
<itemPath>eeprom.h</itemPath>
<itemPath>voltage.h</itemPath> <itemPath>voltage.h</itemPath>
<itemPath>fan_speeeed.h</itemPath>
<itemPath>themistor-temp.h</itemPath>
<itemPath>command-handler.h</itemPath>
<itemPath>eeprom.h</itemPath>
<itemPath>i2c.h</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="ExternalFiles" <logicalFolder name="ExternalFiles"
displayName="Important Files" displayName="Important Files"
projectFiles="true"> projectFiles="true">
<itemPath>Makefile</itemPath> <itemPath>Makefile</itemPath>
<itemPath>prosjekt.mc3</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="LinkerScript" <logicalFolder name="LinkerScript"
displayName="Linker Files" displayName="Linker Files"
@ -25,11 +27,12 @@
projectFiles="true"> projectFiles="true">
<itemPath>main.c</itemPath> <itemPath>main.c</itemPath>
<itemPath>uart.c</itemPath> <itemPath>uart.c</itemPath>
<itemPath>eeprom.c</itemPath>
<itemPath>voltage.c</itemPath> <itemPath>voltage.c</itemPath>
<itemPath>i2c.c</itemPath> <itemPath>fan_speeeed.c</itemPath>
<itemPath>command-handler.c</itemPath>
<itemPath>thermistor-temp.c</itemPath> <itemPath>thermistor-temp.c</itemPath>
<itemPath>command-handler.c</itemPath>
<itemPath>i2c.c</itemPath>
<itemPath>eeprom.c</itemPath>
</logicalFolder> </logicalFolder>
</logicalFolder> </logicalFolder>
<projectmakefile>Makefile</projectmakefile> <projectmakefile>Makefile</projectmakefile>
@ -42,11 +45,11 @@
<targetPluginBoard></targetPluginBoard> <targetPluginBoard></targetPluginBoard>
<platformTool>nEdbgTool</platformTool> <platformTool>nEdbgTool</platformTool>
<languageToolchain>XC8</languageToolchain> <languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>2.46</languageToolchainVersion> <languageToolchainVersion>2.45</languageToolchainVersion>
<platform>2</platform> <platform>2</platform>
</toolsSet> </toolsSet>
<packs> <packs>
<pack name="AVR-Dx_DFP" vendor="Microchip" version="2.3.272"/> <pack name="AVR-Dx_DFP" vendor="Microchip" version="2.4.286"/>
</packs> </packs>
<ScriptingSettings> <ScriptingSettings>
</ScriptingSettings> </ScriptingSettings>
@ -111,6 +114,7 @@
</HI-TECH-COMP> </HI-TECH-COMP>
<HI-TECH-LINK> <HI-TECH-LINK>
<property key="additional-options-checksum" value=""/> <property key="additional-options-checksum" value=""/>
<property key="additional-options-checksumAVR" value=""/>
<property key="additional-options-code-offset" value=""/> <property key="additional-options-code-offset" value=""/>
<property key="additional-options-command-line" value=""/> <property key="additional-options-command-line" value=""/>
<property key="additional-options-errata" value=""/> <property key="additional-options-errata" value=""/>
@ -156,7 +160,54 @@
<property key="remove-unused-sections" value="true"/> <property key="remove-unused-sections" value="true"/>
</HI-TECH-LINK> </HI-TECH-LINK>
<Tool> <Tool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="communication.activationmode" value="nohv"/>
<property key="communication.interface" value="updi"/>
<property key="communication.speed" value="0,500"/>
<property key="debugoptions.debug-startup" value="Use system settings"/>
<property key="debugoptions.reset-behaviour" value="Use system settings"/>
<property key="debugoptions.useswbreakpoints" value="true"/> <property key="debugoptions.useswbreakpoints" value="true"/>
<property key="event.recorder.debugger.behavior" value="Running"/>
<property key="event.recorder.enabled" value="false"/>
<property key="event.recorder.scvd.files" value=""/>
<property key="firmware.path"
value="Press to browse for a specific firmware version"/>
<property key="firmware.toolpack"
value="Press to select which tool pack to use"/>
<property key="firmware.update.action" value="firmware.update.use.latest"/>
<property key="freeze.timers" value="false"/>
<property key="lastid" value=""/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="true"/>
<property key="memories.configurationmemory" value="true"/>
<property key="memories.configurationmemory2" value="true"/>
<property key="memories.dataflash" value="true"/>
<property key="memories.eeprom" value="true"/>
<property key="memories.exclude.configurationmemory" value="true"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="true"/>
<property key="memories.instruction.ram.ranges"
value="${memories.instruction.ram.ranges}"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.ranges" value="0-ffff"/>
<property key="poweroptions.powerenable" value="false"/>
<property key="programmerToGoFilePath"
value="C:/Users/inami/Documents/mikrokontrollersystemer-prosjekt/prosjekt.X/debug/default/prosjekt_ptg"/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.preservedataflash" value="false"/>
<property key="programoptions.preservedataflash.ranges"
value="${memories.dataflash.default}"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveeeprom.ranges" value="1400-15ff"/>
<property key="programoptions.preserveprogram.ranges" value=""/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.programuserotp" value="false"/>
<property key="toolpack.updateoptions"
value="toolpack.updateoptions.uselatestoolpack"/>
<property key="toolpack.updateoptions.packversion"
value="Press to select which tool pack to use"/>
<property key="voltagevalue" value=""/>
</Tool> </Tool>
<XC8-CO> <XC8-CO>
<property key="coverage-enable" value=""/> <property key="coverage-enable" value=""/>
@ -181,7 +232,52 @@
<property key="wpo-lto" value="false"/> <property key="wpo-lto" value="false"/>
</XC8-config-global> </XC8-config-global>
<nEdbgTool> <nEdbgTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="communication.activationmode" value="nohv"/>
<property key="communication.interface" value="updi"/>
<property key="communication.speed" value="0,500"/>
<property key="debugoptions.debug-startup" value="Use system settings"/>
<property key="debugoptions.reset-behaviour" value="Use system settings"/>
<property key="debugoptions.useswbreakpoints" value="true"/> <property key="debugoptions.useswbreakpoints" value="true"/>
<property key="event.recorder.debugger.behavior" value="Running"/>
<property key="event.recorder.enabled" value="false"/>
<property key="event.recorder.scvd.files" value=""/>
<property key="firmware.path"
value="Press to browse for a specific firmware version"/>
<property key="firmware.toolpack"
value="Press to select which tool pack to use"/>
<property key="firmware.update.action" value="firmware.update.use.latest"/>
<property key="freeze.timers" value="false"/>
<property key="lastid" value=""/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="true"/>
<property key="memories.configurationmemory" value="true"/>
<property key="memories.configurationmemory2" value="true"/>
<property key="memories.dataflash" value="true"/>
<property key="memories.eeprom" value="true"/>
<property key="memories.exclude.configurationmemory" value="true"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="true"/>
<property key="memories.instruction.ram.ranges"
value="${memories.instruction.ram.ranges}"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.ranges" value="0-ffff"/>
<property key="poweroptions.powerenable" value="false"/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.preservedataflash" value="false"/>
<property key="programoptions.preservedataflash.ranges"
value="${memories.dataflash.default}"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveeeprom.ranges" value="1400-15ff"/>
<property key="programoptions.preserveprogram.ranges" value=""/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.programuserotp" value="false"/>
<property key="toolpack.updateoptions"
value="toolpack.updateoptions.uselatestoolpack"/>
<property key="toolpack.updateoptions.packversion"
value="Press to select which tool pack to use"/>
<property key="voltagevalue" value=""/>
</nEdbgTool> </nEdbgTool>
</conf> </conf>
</confs> </confs>

8047
prosjekt.X/prosjekt.mc3 Normal file

File diff suppressed because it is too large Load Diff

View File

@ -56,14 +56,3 @@ uint16_t internal_voltage_read() {
return adc_val * 10; return adc_val * 10;
} }
/* Takes inn a messured value and converts it to voltage */
uint16_t convert_to_voltage(uint16_t adc_val){
uint16_t min_in= 0;
uint16_t min_out= 0;
uint16_t max_in= 1023;
uint16_t max_out= 3.3;
uint16_t voltage = (adc_val-min_in)*(max_out-min_out)/(max_in-min_in) + min_out;
return voltage;
}