Loading Session3-LF/Task1_LF/Task1_LF/Task1_LF.cproj +84 −74 Original line number Diff line number Diff line Loading @@ -34,14 +34,13 @@ <documentation help="" /> <offline-documentation help="" /> <dependencies> <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.34.1" /> <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.37" /> </dependencies> </framework-data> </AsfFrameworkConfig> <avrtool> </avrtool> <avrtoolserialnumber>ATML2654041800000542</avrtoolserialnumber> <avrdeviceexpectedsignature>0x1E9320</avrdeviceexpectedsignature> <avrtool>com.atmel.avrdbg.tool.nedbg</avrtool> <avrtoolserialnumber>ATML3094051800000371</avrtoolserialnumber> <avrdeviceexpectedsignature>0x1E9651</avrdeviceexpectedsignature> <avrtoolinterface>UPDI</avrtoolinterface> <com_atmel_avrdbg_tool_edbg> <ToolOptions> Loading @@ -54,9 +53,20 @@ <ToolNumber>ATML2654041800000542</ToolNumber> <ToolName>EDBG</ToolName> </com_atmel_avrdbg_tool_edbg> <avrtoolinterfaceclock>100000</avrtoolinterfaceclock> <avrtoolinterfaceclock>750000</avrtoolinterfaceclock> <ResetRule>0</ResetRule> <EraseKey /> <com_atmel_avrdbg_tool_nedbg> <ToolOptions> <InterfaceProperties> <UpdiClock>750000</UpdiClock> </InterfaceProperties> <InterfaceName>UPDI</InterfaceName> </ToolOptions> <ToolType>com.atmel.avrdbg.tool.nedbg</ToolType> <ToolNumber>ATML3094051800000371</ToolNumber> <ToolName>nEDBG</ToolName> </com_atmel_avrdbg_tool_nedbg> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <ToolchainSettings> Loading Session3-LF/Task1_LF/Task1_LF/adc.c +4 −4 Original line number Diff line number Diff line Loading @@ -8,10 +8,10 @@ #include <avr/io.h> void adc_init(){ ADC0.CTRLA |= (ADC_RESSEL_8BIT_gc); //Set resolution, we choose 8 bits ADC0.CTRLA |= (ADC_RESSEL_10BIT_gc); //Set resolution, we choose 8 bits ADC0.CTRLB |= (ADC_SAMPNUM_ACC4_gc); //OPTIONAL: We can use multiple samples if we like, example here with 4 //More samples gives a better result but takes longer //More samples gives a better result but takes longer. ADC0.CTRLC |= (ADC_REFSEL_VDDREF_gc); //We select to use the supply voltage (VDD) as voltage reference ADC0.CTRLC |= (ADC_PRESC_DIV2_gc); //ADC clock prescaler, best accuracy when run below 2MHz. (Here div2 ~1.46 MHz) Loading @@ -19,7 +19,7 @@ void adc_init(){ } uint8_t adc_read(uint8_t channel){ uint16_t adc_read(uint8_t channel){ ADC0.MUXPOS = channel; //Select input on the ADC mux //NOTE: We can use = here because this is the only thing the register holds. Neat! Loading @@ -30,6 +30,6 @@ uint8_t adc_read(uint8_t channel){ while(!(ADC0.INTFLAGS & ADC_RESRDY_bm)){ //Wait for the results ready flag to be set } return ADC0.RESL; //Return 8 bit result return ADC0.RES; //Return 10 bit result } Session3-LF/Task1_LF/Task1_LF/adc.h +1 −1 Original line number Diff line number Diff line Loading @@ -11,6 +11,6 @@ void adc_init(void); uint8_t adc_read(uint8_t channel); uint16_t adc_read(uint8_t channel); #endif /* ADC_H_ */ No newline at end of file Session3-LF/Task1_LF/Task1_LF/main.c +8 −10 Original line number Diff line number Diff line Loading @@ -16,30 +16,28 @@ #include "uart.h" #define LIGHT 0x01 // Light sensor is connected to ADC channel 1 (which is on port D pin 1) #define KLAKK 0x01 // OV-POT KLAKK is connected to ADC channel 1 (which is on port D pin 1) uint8_t data = 0; uint16_t data = 0; int main(void) { uart_init(BAUD_9600); //Initiate the uart (provided in uart.c) with a baudrate of 9600 uart_init(BAUD_9600); //Initiate the usart (provided in usart.c) with a baudrate of 9600 adc_init(); //Initiate the adc (The student has to write this function) sei(); //If we want to receive via UART we need interrupts enabled. //NOTE: UART isn't used to receive here and as such this isn't required. sei(); //If we want to receive via usart we need interrupts enabled. //NOTE: usart isn't used to receive here and as such this isn't required. while (1) { data = adc_read(LIGHT); //Read the analog voltage on channel 6, connected to light sensor data = adc_read(KLAKK); //Read the analog voltage on channel 6, connected to OV-POT KLAKK //The light sensor returns the ones complement (the opposite) of the brightness: data = 0xff - data; printf("Light intensity is currently %d brightness points!\r\n", data); //Print out the value neatly using printf printf("ADC is reading %u from OV-POT KLAKK!\r\n", data); //Print out the value neatly using printf /* About printf: Handles formatting of your print to terminal. This includes special characters, values of variables and more. It takes one string and any variables you want to print. Loading Session3-LF/Task2_LF - Copy/.gitignore 0 → 100644 +2 −0 Original line number Diff line number Diff line Task2_LF/Debug .vs Loading
Session3-LF/Task1_LF/Task1_LF/Task1_LF.cproj +84 −74 Original line number Diff line number Diff line Loading @@ -34,14 +34,13 @@ <documentation help="" /> <offline-documentation help="" /> <dependencies> <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.34.1" /> <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.37" /> </dependencies> </framework-data> </AsfFrameworkConfig> <avrtool> </avrtool> <avrtoolserialnumber>ATML2654041800000542</avrtoolserialnumber> <avrdeviceexpectedsignature>0x1E9320</avrdeviceexpectedsignature> <avrtool>com.atmel.avrdbg.tool.nedbg</avrtool> <avrtoolserialnumber>ATML3094051800000371</avrtoolserialnumber> <avrdeviceexpectedsignature>0x1E9651</avrdeviceexpectedsignature> <avrtoolinterface>UPDI</avrtoolinterface> <com_atmel_avrdbg_tool_edbg> <ToolOptions> Loading @@ -54,9 +53,20 @@ <ToolNumber>ATML2654041800000542</ToolNumber> <ToolName>EDBG</ToolName> </com_atmel_avrdbg_tool_edbg> <avrtoolinterfaceclock>100000</avrtoolinterfaceclock> <avrtoolinterfaceclock>750000</avrtoolinterfaceclock> <ResetRule>0</ResetRule> <EraseKey /> <com_atmel_avrdbg_tool_nedbg> <ToolOptions> <InterfaceProperties> <UpdiClock>750000</UpdiClock> </InterfaceProperties> <InterfaceName>UPDI</InterfaceName> </ToolOptions> <ToolType>com.atmel.avrdbg.tool.nedbg</ToolType> <ToolNumber>ATML3094051800000371</ToolNumber> <ToolName>nEDBG</ToolName> </com_atmel_avrdbg_tool_nedbg> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <ToolchainSettings> Loading
Session3-LF/Task1_LF/Task1_LF/adc.c +4 −4 Original line number Diff line number Diff line Loading @@ -8,10 +8,10 @@ #include <avr/io.h> void adc_init(){ ADC0.CTRLA |= (ADC_RESSEL_8BIT_gc); //Set resolution, we choose 8 bits ADC0.CTRLA |= (ADC_RESSEL_10BIT_gc); //Set resolution, we choose 8 bits ADC0.CTRLB |= (ADC_SAMPNUM_ACC4_gc); //OPTIONAL: We can use multiple samples if we like, example here with 4 //More samples gives a better result but takes longer //More samples gives a better result but takes longer. ADC0.CTRLC |= (ADC_REFSEL_VDDREF_gc); //We select to use the supply voltage (VDD) as voltage reference ADC0.CTRLC |= (ADC_PRESC_DIV2_gc); //ADC clock prescaler, best accuracy when run below 2MHz. (Here div2 ~1.46 MHz) Loading @@ -19,7 +19,7 @@ void adc_init(){ } uint8_t adc_read(uint8_t channel){ uint16_t adc_read(uint8_t channel){ ADC0.MUXPOS = channel; //Select input on the ADC mux //NOTE: We can use = here because this is the only thing the register holds. Neat! Loading @@ -30,6 +30,6 @@ uint8_t adc_read(uint8_t channel){ while(!(ADC0.INTFLAGS & ADC_RESRDY_bm)){ //Wait for the results ready flag to be set } return ADC0.RESL; //Return 8 bit result return ADC0.RES; //Return 10 bit result }
Session3-LF/Task1_LF/Task1_LF/adc.h +1 −1 Original line number Diff line number Diff line Loading @@ -11,6 +11,6 @@ void adc_init(void); uint8_t adc_read(uint8_t channel); uint16_t adc_read(uint8_t channel); #endif /* ADC_H_ */ No newline at end of file
Session3-LF/Task1_LF/Task1_LF/main.c +8 −10 Original line number Diff line number Diff line Loading @@ -16,30 +16,28 @@ #include "uart.h" #define LIGHT 0x01 // Light sensor is connected to ADC channel 1 (which is on port D pin 1) #define KLAKK 0x01 // OV-POT KLAKK is connected to ADC channel 1 (which is on port D pin 1) uint8_t data = 0; uint16_t data = 0; int main(void) { uart_init(BAUD_9600); //Initiate the uart (provided in uart.c) with a baudrate of 9600 uart_init(BAUD_9600); //Initiate the usart (provided in usart.c) with a baudrate of 9600 adc_init(); //Initiate the adc (The student has to write this function) sei(); //If we want to receive via UART we need interrupts enabled. //NOTE: UART isn't used to receive here and as such this isn't required. sei(); //If we want to receive via usart we need interrupts enabled. //NOTE: usart isn't used to receive here and as such this isn't required. while (1) { data = adc_read(LIGHT); //Read the analog voltage on channel 6, connected to light sensor data = adc_read(KLAKK); //Read the analog voltage on channel 6, connected to OV-POT KLAKK //The light sensor returns the ones complement (the opposite) of the brightness: data = 0xff - data; printf("Light intensity is currently %d brightness points!\r\n", data); //Print out the value neatly using printf printf("ADC is reading %u from OV-POT KLAKK!\r\n", data); //Print out the value neatly using printf /* About printf: Handles formatting of your print to terminal. This includes special characters, values of variables and more. It takes one string and any variables you want to print. Loading
Session3-LF/Task2_LF - Copy/.gitignore 0 → 100644 +2 −0 Original line number Diff line number Diff line Task2_LF/Debug .vs