Compare commits
37 Commits
495cbbba44
...
275c40498f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
275c40498f | ||
| 772960d046 | |||
| ac5a054f8b | |||
| f0a435d578 | |||
| e01c4d41ad | |||
| 10c82d001e | |||
| f2019dd57a | |||
| 022ccb13a0 | |||
| 6528a82b04 | |||
| eb7d96dd82 | |||
| 8649d59d8d | |||
| c9b220616d | |||
| a48a089a3c | |||
| 57a35a483d | |||
| abc13364ec | |||
| 58014e17d1 | |||
| 9cf37461d2 | |||
| 14c09f63a9 | |||
|
|
23904b03ea | ||
|
|
63aa397b78 | ||
| cd97face0f | |||
|
|
a6d1afb0bf | ||
|
|
f1c9a0707e | ||
|
|
9b23172eba | ||
|
|
48308b9b75 | ||
|
|
ce58f79c6f | ||
|
|
dc8a858204 | ||
|
|
8b5b4e186a | ||
|
|
427000ff9e | ||
|
|
88415ddec1 | ||
|
|
df3d0c6ce6 | ||
|
|
9aa9c444c1 | ||
|
|
d14044e8df | ||
|
|
49c0874445 | ||
|
|
b7e6bb6d04 | ||
|
|
a0fa78405a | ||
|
|
a4a760a870 |
107
prosjekt.X/fan_speeeed.c
Normal file
107
prosjekt.X/fan_speeeed.c
Normal 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
57
prosjekt.X/fan_speeeed.h
Normal 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 */
|
||||
|
||||
@ -4,9 +4,9 @@
|
||||
*
|
||||
* Created on March 6, 2024, 12:34 PM
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include "uart.h"
|
||||
#include "voltage.h"
|
||||
#include <stdbool.h>
|
||||
#define RTC_PERIOD (511)
|
||||
#define DELAY_TIME 1000
|
||||
#include "eeprom.h"
|
||||
@ -24,11 +24,11 @@
|
||||
#include <util/delay.h>
|
||||
|
||||
// Fan history variables
|
||||
volatile uint16_t fan1_history[512] = { 0 };
|
||||
volatile uint16_t fan2_history[512] = { 0 };
|
||||
volatile uint16_t fan1_history[512] = {0};
|
||||
volatile uint16_t fan2_history[512] = {0};
|
||||
|
||||
// Default config is 500ms sample rate
|
||||
volatile config_t config = { 500 };
|
||||
volatile config_t config = {500};
|
||||
volatile bool store_config = false;
|
||||
|
||||
int main() {
|
||||
@ -41,16 +41,16 @@ int main() {
|
||||
|
||||
// Read the stored config struct
|
||||
config = read_struct_from_EEPROM();
|
||||
|
||||
|
||||
PORTB.DIRSET = PIN3_bm;
|
||||
|
||||
|
||||
sei();
|
||||
|
||||
while (1) {
|
||||
// If we have made a config change, store it.
|
||||
if (store_config) {
|
||||
write_struct_from_EEPROM(config);
|
||||
store_config = false;
|
||||
}
|
||||
// If we have made a config change, store it.
|
||||
if (store_config) {
|
||||
write_struct_from_EEPROM(config);
|
||||
store_config = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,17 +4,19 @@
|
||||
<logicalFolder name="HeaderFiles"
|
||||
displayName="Header Files"
|
||||
projectFiles="true">
|
||||
<itemPath>command-handler.h</itemPath>
|
||||
<itemPath>i2c.h</itemPath>
|
||||
<itemPath>themistor-temp.h</itemPath>
|
||||
<itemPath>uart.h</itemPath>
|
||||
<itemPath>eeprom.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 name="ExternalFiles"
|
||||
displayName="Important Files"
|
||||
projectFiles="true">
|
||||
<itemPath>Makefile</itemPath>
|
||||
<itemPath>prosjekt.mc3</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="LinkerScript"
|
||||
displayName="Linker Files"
|
||||
@ -25,11 +27,12 @@
|
||||
projectFiles="true">
|
||||
<itemPath>main.c</itemPath>
|
||||
<itemPath>uart.c</itemPath>
|
||||
<itemPath>eeprom.c</itemPath>
|
||||
<itemPath>voltage.c</itemPath>
|
||||
<itemPath>i2c.c</itemPath>
|
||||
<itemPath>command-handler.c</itemPath>
|
||||
<itemPath>fan_speeeed.c</itemPath>
|
||||
<itemPath>thermistor-temp.c</itemPath>
|
||||
<itemPath>command-handler.c</itemPath>
|
||||
<itemPath>i2c.c</itemPath>
|
||||
<itemPath>eeprom.c</itemPath>
|
||||
</logicalFolder>
|
||||
</logicalFolder>
|
||||
<projectmakefile>Makefile</projectmakefile>
|
||||
@ -42,11 +45,11 @@
|
||||
<targetPluginBoard></targetPluginBoard>
|
||||
<platformTool>nEdbgTool</platformTool>
|
||||
<languageToolchain>XC8</languageToolchain>
|
||||
<languageToolchainVersion>2.46</languageToolchainVersion>
|
||||
<languageToolchainVersion>2.45</languageToolchainVersion>
|
||||
<platform>2</platform>
|
||||
</toolsSet>
|
||||
<packs>
|
||||
<pack name="AVR-Dx_DFP" vendor="Microchip" version="2.3.272"/>
|
||||
<pack name="AVR-Dx_DFP" vendor="Microchip" version="2.4.286"/>
|
||||
</packs>
|
||||
<ScriptingSettings>
|
||||
</ScriptingSettings>
|
||||
@ -111,6 +114,7 @@
|
||||
</HI-TECH-COMP>
|
||||
<HI-TECH-LINK>
|
||||
<property key="additional-options-checksum" value=""/>
|
||||
<property key="additional-options-checksumAVR" value=""/>
|
||||
<property key="additional-options-code-offset" value=""/>
|
||||
<property key="additional-options-command-line" value=""/>
|
||||
<property key="additional-options-errata" value=""/>
|
||||
@ -156,7 +160,54 @@
|
||||
<property key="remove-unused-sections" value="true"/>
|
||||
</HI-TECH-LINK>
|
||||
<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="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>
|
||||
<XC8-CO>
|
||||
<property key="coverage-enable" value=""/>
|
||||
@ -181,7 +232,52 @@
|
||||
<property key="wpo-lto" value="false"/>
|
||||
</XC8-config-global>
|
||||
<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="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>
|
||||
</conf>
|
||||
</confs>
|
||||
|
||||
8047
prosjekt.X/prosjekt.mc3
Normal file
8047
prosjekt.X/prosjekt.mc3
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,68 +2,57 @@
|
||||
#include "uart.h"
|
||||
|
||||
void ADC0_init(void) {
|
||||
/* Initializing ADC0 pin*/
|
||||
/*Voltage reading on pin pd6*/
|
||||
PORTD.PIN6CTRL &= ~PORT_ISC_gm;
|
||||
PORTD.PIN6CTRL |= PORT_ISC_INPUT_DISABLE_gc; /* Disable */
|
||||
PORTD.PIN6CTRL &= PORT_PULLUPEN_bm;
|
||||
|
||||
/* Thermistor */
|
||||
PORTD.PIN3CTRL &= ~PORT_ISC_gm;
|
||||
PORTD.PIN3CTRL |= PORT_ISC_INPUT_DISABLE_gc; /* Disable */
|
||||
PORTD.PIN3CTRL &= PORT_PULLUPEN_bm;
|
||||
|
||||
ADC0.CTRLC = ADC_PRESC_DIV4_gc;
|
||||
VREF.ADC0REF = VREF_REFSEL_VDD_gc; /* Internal reference */
|
||||
ADC0.CTRLA = ADC_ENABLE_bm /* ADC Enable: enabled */
|
||||
| ADC_RESSEL_10BIT_gc; /* 10-bit mode */
|
||||
/* Select ADC channel */
|
||||
ADC0.MUXPOS = ADC_MUXPOS_AIN6_gc;
|
||||
/* Initializing ADC0 pin*/
|
||||
/*Voltage reading on pin pd6*/
|
||||
PORTD.PIN6CTRL &= ~PORT_ISC_gm;
|
||||
PORTD.PIN6CTRL |= PORT_ISC_INPUT_DISABLE_gc; /* Disable */
|
||||
PORTD.PIN6CTRL &= PORT_PULLUPEN_bm;
|
||||
|
||||
/* Thermistor */
|
||||
PORTD.PIN3CTRL &= ~PORT_ISC_gm;
|
||||
PORTD.PIN3CTRL |= PORT_ISC_INPUT_DISABLE_gc; /* Disable */
|
||||
PORTD.PIN3CTRL &= PORT_PULLUPEN_bm;
|
||||
|
||||
ADC0.CTRLC = ADC_PRESC_DIV4_gc;
|
||||
VREF.ADC0REF = VREF_REFSEL_VDD_gc; /* Internal reference */
|
||||
ADC0.CTRLA = ADC_ENABLE_bm /* ADC Enable: enabled */
|
||||
| ADC_RESSEL_10BIT_gc; /* 10-bit mode */
|
||||
/* Select ADC channel */
|
||||
ADC0.MUXPOS = ADC_MUXPOS_AIN6_gc;
|
||||
}
|
||||
|
||||
uint16_t ADC0_read(void) {
|
||||
/* Start ADC conversion */
|
||||
ADC0.COMMAND = ADC_STCONV_bm;
|
||||
/* Wait until ADC conversion done */
|
||||
while (!(ADC0.INTFLAGS & ADC_RESRDY_bm)) {
|
||||
;
|
||||
}
|
||||
// Clear the interrupt flag by writing 1:
|
||||
ADC0.INTFLAGS = ADC_RESRDY_bm;
|
||||
return ADC0.RES;
|
||||
/* Start ADC conversion */
|
||||
ADC0.COMMAND = ADC_STCONV_bm;
|
||||
/* Wait until ADC conversion done */
|
||||
while (!(ADC0.INTFLAGS & ADC_RESRDY_bm)) {
|
||||
;
|
||||
}
|
||||
// Clear the interrupt flag by writing 1:
|
||||
ADC0.INTFLAGS = ADC_RESRDY_bm;
|
||||
return ADC0.RES;
|
||||
}
|
||||
|
||||
uint16_t thermistor_voltage_read() {
|
||||
/* Gets value for the diode */
|
||||
ADC0.MUXPOS = 0x03; // Read PD3
|
||||
uint16_t adc_val = ADC0_read();
|
||||
/* Gets value for the diode */
|
||||
ADC0.MUXPOS = 0x03; // Read PD3
|
||||
uint16_t adc_val = ADC0_read();
|
||||
|
||||
return adc_val;
|
||||
return adc_val;
|
||||
}
|
||||
// Gets the value over thermistor
|
||||
uint16_t external_voltage_read(){
|
||||
ADC0.MUXPOS = 0x06; // Read PD6
|
||||
uint16_t adc_val = ADC0_read();
|
||||
|
||||
return adc_val;
|
||||
uint16_t external_voltage_read() {
|
||||
ADC0.MUXPOS = 0x06; // Read PD6
|
||||
uint16_t adc_val = ADC0_read();
|
||||
|
||||
return adc_val;
|
||||
}
|
||||
|
||||
uint16_t internal_voltage_read() {
|
||||
/* Gets value for the internal voltage reffreance*/
|
||||
|
||||
ADC0.MUXPOS = 0x44;
|
||||
uint8_t adc_val = ADC0_read();
|
||||
|
||||
return adc_val*10;
|
||||
}
|
||||
/* Gets value for the internal voltage reffreance*/
|
||||
|
||||
/* 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;
|
||||
|
||||
}
|
||||
ADC0.MUXPOS = 0x44;
|
||||
uint8_t adc_val = ADC0_read();
|
||||
|
||||
return adc_val * 10;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user