Merge remote-tracking branch 'origin/voltage-reading' into calculate-fanspeed

This commit is contained in:
Inamr 2024-03-20 14:52:28 +01:00
commit 8b5b4e186a
4 changed files with 296 additions and 181 deletions

View File

@ -4,6 +4,15 @@
* *
* Created on March 6, 2024, 12:34 PM * Created on March 6, 2024, 12:34 PM
*/ */
#include "voltage.h"
#include "uart.h"
#define RTC_PERIOD (511)
#define DELAY_TIME 1000
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <string.h>
#include <stdbool.h>
#define F_CPU 4E6 #define F_CPU 4E6
@ -15,11 +24,13 @@
#include "themistor-temp.h" #include "themistor-temp.h"
int main() { int main() {
sensor_init();
ADC0_init();
init_uart((uint16_t)9600); init_uart((uint16_t)9600);
stdout = &USART_stream; stdout = &USART_stream;
while (1) { while (1) {
printf("Hello, world!\n"); uint16_t adcVal = voltage_values();
_delay_ms(500); printf("The values: \n%u , %u\n",VREF_REFSEL_VDD_gc , adcVal);
} }
} }

View File

@ -1,179 +1,179 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="65"> <configurationDescriptor version="65">
<logicalFolder name="root" displayName="root" projectFiles="true"> <logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles" <logicalFolder name="HeaderFiles"
displayName="Header Files" displayName="Header Files"
projectFiles="true"> projectFiles="true">
<itemPath>themistor-temp.h</itemPath> <itemPath>themistor-temp.h</itemPath>
<itemPath>fan speeeed.h</itemPath> <itemPath>fan speeeed.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>
</logicalFolder> </logicalFolder>
<logicalFolder name="LinkerScript" <logicalFolder name="LinkerScript"
displayName="Linker Files" displayName="Linker Files"
projectFiles="true"> projectFiles="true">
</logicalFolder> </logicalFolder>
<logicalFolder name="SourceFiles" <logicalFolder name="SourceFiles"
displayName="Source Files" displayName="Source Files"
projectFiles="true"> projectFiles="true">
<itemPath>main.c</itemPath> <itemPath>main.c</itemPath>
<itemPath>thermistor-temp.c</itemPath> <itemPath>thermistor-temp.c</itemPath>
</logicalFolder> </logicalFolder>
</logicalFolder> </logicalFolder>
<projectmakefile>Makefile</projectmakefile> <projectmakefile>Makefile</projectmakefile>
<confs> <confs>
<conf name="default" type="2"> <conf name="default" type="2">
<toolsSet> <toolsSet>
<developmentServer>localhost</developmentServer> <developmentServer>localhost</developmentServer>
<targetDevice>AVR128DB48</targetDevice> <targetDevice>AVR128DB48</targetDevice>
<targetHeader></targetHeader> <targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard> <targetPluginBoard></targetPluginBoard>
<platformTool>nEdbgTool</platformTool> <platformTool>nEdbgTool</platformTool>
<languageToolchain>XC8</languageToolchain> <languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>2.46</languageToolchainVersion> <languageToolchainVersion>2.46</languageToolchainVersion>
<platform>3</platform> <platform>3</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.3.272"/>
</packs> </packs>
<ScriptingSettings> <ScriptingSettings>
</ScriptingSettings> </ScriptingSettings>
<compileType> <compileType>
<linkerTool> <linkerTool>
<linkerLibItems> <linkerLibItems>
</linkerLibItems> </linkerLibItems>
</linkerTool> </linkerTool>
<archiverTool> <archiverTool>
</archiverTool> </archiverTool>
<loading> <loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile> <useAlternateLoadableFile>false</useAlternateLoadableFile>
<parseOnProdLoad>false</parseOnProdLoad> <parseOnProdLoad>false</parseOnProdLoad>
<alternateLoadableFile></alternateLoadableFile> <alternateLoadableFile></alternateLoadableFile>
</loading> </loading>
<subordinates> <subordinates>
</subordinates> </subordinates>
</compileType> </compileType>
<makeCustomizationType> <makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled> <makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeUseCleanTarget>false</makeUseCleanTarget> <makeUseCleanTarget>false</makeUseCleanTarget>
<makeCustomizationPreStep></makeCustomizationPreStep> <makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled> <makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep> <makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID> <makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines> <makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile> <makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType> </makeCustomizationType>
<HI-TECH-COMP> <HI-TECH-COMP>
<property key="additional-warnings" value="true"/> <property key="additional-warnings" value="true"/>
<property key="asmlist" value="true"/> <property key="asmlist" value="true"/>
<property key="call-prologues" value="false"/> <property key="call-prologues" value="false"/>
<property key="default-bitfield-type" value="true"/> <property key="default-bitfield-type" value="true"/>
<property key="default-char-type" value="true"/> <property key="default-char-type" value="true"/>
<property key="define-macros" value=""/> <property key="define-macros" value=""/>
<property key="disable-optimizations" value="false"/> <property key="disable-optimizations" value="false"/>
<property key="extra-include-directories" value=""/> <property key="extra-include-directories" value=""/>
<property key="favor-optimization-for" value="-speed,+space"/> <property key="favor-optimization-for" value="-speed,+space"/>
<property key="garbage-collect-data" value="true"/> <property key="garbage-collect-data" value="true"/>
<property key="garbage-collect-functions" value="true"/> <property key="garbage-collect-functions" value="true"/>
<property key="identifier-length" value="255"/> <property key="identifier-length" value="255"/>
<property key="local-generation" value="false"/> <property key="local-generation" value="false"/>
<property key="operation-mode" value="free"/> <property key="operation-mode" value="free"/>
<property key="opt-xc8-compiler-strict_ansi" value="false"/> <property key="opt-xc8-compiler-strict_ansi" value="false"/>
<property key="optimization-assembler" value="true"/> <property key="optimization-assembler" value="true"/>
<property key="optimization-assembler-files" value="true"/> <property key="optimization-assembler-files" value="true"/>
<property key="optimization-debug" value="false"/> <property key="optimization-debug" value="false"/>
<property key="optimization-invariant-enable" value="false"/> <property key="optimization-invariant-enable" value="false"/>
<property key="optimization-invariant-value" value="16"/> <property key="optimization-invariant-value" value="16"/>
<property key="optimization-level" value="-O1"/> <property key="optimization-level" value="-O1"/>
<property key="optimization-speed" value="false"/> <property key="optimization-speed" value="false"/>
<property key="optimization-stable-enable" value="false"/> <property key="optimization-stable-enable" value="false"/>
<property key="preprocess-assembler" value="true"/> <property key="preprocess-assembler" value="true"/>
<property key="short-enums" value="true"/> <property key="short-enums" value="true"/>
<property key="tentative-definitions" value="-fno-common"/> <property key="tentative-definitions" value="-fno-common"/>
<property key="undefine-macros" value=""/> <property key="undefine-macros" value=""/>
<property key="use-cci" value="false"/> <property key="use-cci" value="false"/>
<property key="use-iar" value="false"/> <property key="use-iar" value="false"/>
<property key="verbose" value="false"/> <property key="verbose" value="false"/>
<property key="warning-level" value="-3"/> <property key="warning-level" value="-3"/>
<property key="what-to-do" value="ignore"/> <property key="what-to-do" value="ignore"/>
</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-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=""/>
<property key="additional-options-extend-address" value="false"/> <property key="additional-options-extend-address" value="false"/>
<property key="additional-options-trace-type" value=""/> <property key="additional-options-trace-type" value=""/>
<property key="additional-options-use-response-files" value="false"/> <property key="additional-options-use-response-files" value="false"/>
<property key="backup-reset-condition-flags" value="false"/> <property key="backup-reset-condition-flags" value="false"/>
<property key="calibrate-oscillator" value="false"/> <property key="calibrate-oscillator" value="false"/>
<property key="calibrate-oscillator-value" value="0x3400"/> <property key="calibrate-oscillator-value" value="0x3400"/>
<property key="clear-bss" value="true"/> <property key="clear-bss" value="true"/>
<property key="code-model-external" value="wordwrite"/> <property key="code-model-external" value="wordwrite"/>
<property key="code-model-rom" value=""/> <property key="code-model-rom" value=""/>
<property key="create-html-files" value="false"/> <property key="create-html-files" value="false"/>
<property key="data-model-ram" value=""/> <property key="data-model-ram" value=""/>
<property key="data-model-size-of-double" value="24"/> <property key="data-model-size-of-double" value="24"/>
<property key="data-model-size-of-double-gcc" value="no-short-double"/> <property key="data-model-size-of-double-gcc" value="no-short-double"/>
<property key="data-model-size-of-float" value="24"/> <property key="data-model-size-of-float" value="24"/>
<property key="data-model-size-of-float-gcc" value="no-short-float"/> <property key="data-model-size-of-float-gcc" value="no-short-float"/>
<property key="display-class-usage" value="false"/> <property key="display-class-usage" value="false"/>
<property key="display-hex-usage" value="false"/> <property key="display-hex-usage" value="false"/>
<property key="display-overall-usage" value="true"/> <property key="display-overall-usage" value="true"/>
<property key="display-psect-usage" value="false"/> <property key="display-psect-usage" value="false"/>
<property key="extra-lib-directories" value=""/> <property key="extra-lib-directories" value=""/>
<property key="fill-flash-options-addr" value=""/> <property key="fill-flash-options-addr" value=""/>
<property key="fill-flash-options-const" value=""/> <property key="fill-flash-options-const" value=""/>
<property key="fill-flash-options-how" value="0"/> <property key="fill-flash-options-how" value="0"/>
<property key="fill-flash-options-inc-const" value="1"/> <property key="fill-flash-options-inc-const" value="1"/>
<property key="fill-flash-options-increment" value=""/> <property key="fill-flash-options-increment" value=""/>
<property key="fill-flash-options-seq" value=""/> <property key="fill-flash-options-seq" value=""/>
<property key="fill-flash-options-what" value="0"/> <property key="fill-flash-options-what" value="0"/>
<property key="format-hex-file-for-download" value="false"/> <property key="format-hex-file-for-download" value="false"/>
<property key="initialize-data" value="true"/> <property key="initialize-data" value="true"/>
<property key="input-libraries" value="libm"/> <property key="input-libraries" value="libm"/>
<property key="keep-generated-startup.as" value="false"/> <property key="keep-generated-startup.as" value="false"/>
<property key="link-in-c-library" value="true"/> <property key="link-in-c-library" value="true"/>
<property key="link-in-c-library-gcc" value=""/> <property key="link-in-c-library-gcc" value=""/>
<property key="link-in-peripheral-library" value="false"/> <property key="link-in-peripheral-library" value="false"/>
<property key="managed-stack" value="false"/> <property key="managed-stack" value="false"/>
<property key="opt-xc8-linker-file" value="false"/> <property key="opt-xc8-linker-file" value="false"/>
<property key="opt-xc8-linker-link_startup" value="false"/> <property key="opt-xc8-linker-link_startup" value="false"/>
<property key="opt-xc8-linker-serial" value=""/> <property key="opt-xc8-linker-serial" value=""/>
<property key="program-the-device-with-default-config-words" value="false"/> <property key="program-the-device-with-default-config-words" value="false"/>
<property key="remove-unused-sections" value="true"/> <property key="remove-unused-sections" value="true"/>
</HI-TECH-LINK> </HI-TECH-LINK>
<Tool> <Tool>
<property key="debugoptions.useswbreakpoints" value="true"/> <property key="debugoptions.useswbreakpoints" value="true"/>
</Tool> </Tool>
<XC8-CO> <XC8-CO>
<property key="coverage-enable" value=""/> <property key="coverage-enable" value=""/>
<property key="stack-guidance" value="false"/> <property key="stack-guidance" value="false"/>
</XC8-CO> </XC8-CO>
<XC8-config-global> <XC8-config-global>
<property key="advanced-elf" value="true"/> <property key="advanced-elf" value="true"/>
<property key="constdata-progmem" value="true"/> <property key="constdata-progmem" value="true"/>
<property key="gcc-opt-driver-new" value="true"/> <property key="gcc-opt-driver-new" value="true"/>
<property key="gcc-opt-std" value="-std=c99"/> <property key="gcc-opt-std" value="-std=c99"/>
<property key="gcc-output-file-format" value="dwarf-3"/> <property key="gcc-output-file-format" value="dwarf-3"/>
<property key="mapped-progmem" value="false"/> <property key="mapped-progmem" value="false"/>
<property key="omit-pack-options" value="false"/> <property key="omit-pack-options" value="false"/>
<property key="omit-pack-options-new" value="1"/> <property key="omit-pack-options-new" value="1"/>
<property key="output-file-format" value="-mcof,+elf"/> <property key="output-file-format" value="-mcof,+elf"/>
<property key="smart-io-format" value=""/> <property key="smart-io-format" value=""/>
<property key="stack-size-high" value="auto"/> <property key="stack-size-high" value="auto"/>
<property key="stack-size-low" value="auto"/> <property key="stack-size-low" value="auto"/>
<property key="stack-size-main" value="auto"/> <property key="stack-size-main" value="auto"/>
<property key="stack-type" value="compiled"/> <property key="stack-type" value="compiled"/>
<property key="user-pack-device-support" value=""/> <property key="user-pack-device-support" value=""/>
<property key="wpo-lto" value="false"/> <property key="wpo-lto" value="false"/>
</XC8-config-global> </XC8-config-global>
<nEdbgTool> <nEdbgTool>
<property key="debugoptions.useswbreakpoints" value="true"/> <property key="debugoptions.useswbreakpoints" value="true"/>
</nEdbgTool> </nEdbgTool>
</conf> </conf>
</confs> </confs>
</configurationDescriptor> </configurationDescriptor>

40
prosjekt.X/voltage.c Normal file
View File

@ -0,0 +1,40 @@
#include "voltage.h"
#include "uart.h"
void sensor_init(void) {
/* Disable digital input buffer */
}
void ADC0_init(void) {
/* Initializing ADC0 pin*/
PORTD.PIN6CTRL &= ~PORT_ISC_gm;
PORTD.PIN6CTRL |= PORT_ISC_INPUT_DISABLE_gc; /* Disable */
PORTD.PIN6CTRL &= 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;
}
uint16_t voltage_values(void) {
/* Gets values */
uint16_t adcVal = ADC0_read();
VREF.ADC0REF = VREF_REFSEL_VDD_gc;
return adcVal;
}

64
prosjekt.X/voltage.h Normal file
View File

@ -0,0 +1,64 @@
/* Microchip Technology Inc. and its subsidiaries. You may use this software
* and any derivatives exclusively with Microchip products.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
* PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
* WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
*
* IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
* INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
* WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
* BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
* FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS
* IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF
* ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
* TERMS.
*/
/*
* File:
* Author:
* Comments:
* Revision history:
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
// This is a guard condition so that contents of this file are not included
// more than once.
#ifndef XC_HEADER_TEMPLATE_H
#define XC_HEADER_TEMPLATE_H
#include <xc.h> // include processor files - each processor file is guarded.
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// Initializing of the sensor pins
void sensor_init(void);
// Initializing of the ADC0 pins
void ADC0_init(void);
//
//void ADC0_start(void);
//Start ADC conversion
uint16_t ADC0_read(void);
// Gets the value from sensor and internal voltage
uint16_t voltage_values(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* XC_HEADER_TEMPLATE_H */