├── .gitignore ├── ADC_Event_Triggered ├── ADC_Event_Triggered.componentinfo.xml ├── ADC_Event_Triggered.cproj └── main.c ├── ADC_Free_Running ├── ADC_Free_Running.componentinfo.xml ├── ADC_Free_Running.cproj └── main.c ├── ADC_Sample_Accumulator ├── ADC_Sample_Accumulator.componentinfo.xml ├── ADC_Sample_Accumulator.cproj └── main.c ├── ADC_Single_Conversion ├── ADC_Single_Conversion.componentinfo.xml ├── ADC_Single_Conversion.cproj └── main.c ├── ADC_Window_Comparator ├── ADC_Window_Comparator.componentinfo.xml ├── ADC_Window_Comparator.cproj └── main.c ├── ATMEGA4809_ADC_Examples.atsln └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | */Debug 2 | .vs 3 | avr-tb-code-formatter.jar 4 | -------------------------------------------------------------------------------- /ADC_Event_Triggered/ADC_Event_Triggered.componentinfo.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Device 8 | Startup 9 | 10 | 11 | Atmel 12 | 1.2.0 13 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs 14 | 15 | 16 | 17 | 18 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include 19 | 20 | include 21 | C 22 | 23 | 24 | include 25 | 26 | 27 | 28 | 29 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom4809.h 30 | 31 | header 32 | C 33 | mWiFIOAGwUPlW0rYsXcjkg== 34 | 35 | include/avr/iom4809.h 36 | 37 | 38 | 39 | 40 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.c 41 | template 42 | source 43 | C Exe 44 | nmRb1n3GvDh5AJNdv9qePw== 45 | 46 | templates/main.c 47 | Main file (.c) 48 | 49 | 50 | 51 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.cpp 52 | template 53 | source 54 | C Exe 55 | YXFphlh0CtZJU+ebktABgQ== 56 | 57 | templates/main.cpp 58 | Main file (.cpp) 59 | 60 | 61 | 62 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809 63 | 64 | libraryPrefix 65 | GCC 66 | 67 | 68 | gcc/dev/atmega4809 69 | 70 | 71 | 72 | 73 | ATmega_DFP 74 | C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc 75 | 1.2.209 76 | true 77 | ATmega4809 78 | 79 | 80 | 81 | Resolved 82 | Fixed 83 | true 84 | 85 | 86 | -------------------------------------------------------------------------------- /ADC_Event_Triggered/ADC_Event_Triggered.cproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 2.0 5 | 7.0 6 | com.Atmel.AVRGCC8.C 7 | dce6c7e3-ee26-4d79-826b-08594b9ad897 8 | ATmega4809 9 | none 10 | Executable 11 | C 12 | $(MSBuildProjectName) 13 | .elf 14 | $(MSBuildProjectDirectory)\$(Configuration) 15 | 4809-adc-event-triggered 16 | ADC_Event_Triggered 17 | 4809-adc-event-triggered 18 | Native 19 | true 20 | false 21 | true 22 | true 23 | 24 | 25 | true 26 | 27 | 2 28 | 0 29 | 0 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809" 48 | True 49 | True 50 | True 51 | True 52 | False 53 | True 54 | True 55 | 56 | 57 | NDEBUG 58 | 59 | 60 | 61 | 62 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 63 | 64 | 65 | Optimize for size (-Os) 66 | True 67 | True 68 | True 69 | 70 | 71 | libm 72 | 73 | 74 | 75 | 76 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809" 86 | True 87 | True 88 | True 89 | True 90 | False 91 | True 92 | True 93 | 94 | 95 | DEBUG 96 | 97 | 98 | 99 | 100 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 101 | 102 | 103 | Optimize (-O1) 104 | True 105 | True 106 | Default (-g2) 107 | True 108 | 109 | 110 | libm 111 | 112 | 113 | 114 | 115 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 116 | 117 | 118 | Default (-Wa,-g) 119 | 120 | 121 | 122 | 123 | 124 | compile 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /ADC_Event_Triggered/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | \file main.c 3 | 4 | \brief ADC triggered by RTC Overflow 5 | 6 | (c) 2018 Microchip Technology Inc. and its subsidiaries. 7 | 8 | Subject to your compliance with these terms, you may use Microchip software and any 9 | derivatives exclusively with Microchip products. It is your responsibility to comply with third party 10 | license terms applicable to your use of third party software (including open source software) that 11 | may accompany Microchip software. 12 | 13 | THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 14 | EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 15 | IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 16 | FOR A PARTICULAR PURPOSE. 17 | 18 | IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 19 | INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 20 | WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 21 | HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 22 | THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 23 | CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 24 | OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 25 | SOFTWARE. 26 | */ 27 | 28 | /* RTC Period */ 29 | #define RTC_PERIOD (511) 30 | 31 | #include 32 | #include 33 | 34 | uint16_t adcVal; 35 | 36 | void ADC0_init(void); 37 | void LED0_init(void); 38 | void LED0_toggle(void); 39 | void RTC_init(void); 40 | void EVSYS_init(void); 41 | 42 | void ADC0_init(void) 43 | { 44 | /* Disable digital input buffer */ 45 | PORTD.PIN6CTRL &= ~PORT_ISC_gm; 46 | PORTD.PIN6CTRL |= PORT_ISC_INPUT_DISABLE_gc; 47 | 48 | /* Disable pull-up resistor */ 49 | PORTD.PIN6CTRL &= ~PORT_PULLUPEN_bm; 50 | 51 | ADC0.CTRLC = ADC_PRESC_DIV4_gc /* CLK_PER divided by 4 */ 52 | | ADC_REFSEL_INTREF_gc; /* Internal reference */ 53 | 54 | ADC0.CTRLA = ADC_ENABLE_bm /* ADC Enable: enabled */ 55 | | ADC_RESSEL_10BIT_gc; /* 10-bit mode */ 56 | 57 | /* Select ADC channel */ 58 | ADC0.MUXPOS = ADC_MUXPOS_AIN6_gc; 59 | 60 | /* Enable interrupts */ 61 | ADC0.INTCTRL |= ADC_RESRDY_bm; 62 | 63 | /* Enable event triggered conversion */ 64 | ADC0.EVCTRL |= ADC_STARTEI_bm; 65 | } 66 | 67 | void LED0_init(void) 68 | { 69 | /* Make High (OFF) */ 70 | PORTB.OUT |= PIN5_bm; 71 | /* Make output */ 72 | PORTB.DIR |= PIN5_bm; 73 | } 74 | 75 | void LED0_toggle(void) 76 | { 77 | PORTB.IN |= PIN5_bm; 78 | } 79 | 80 | ISR(ADC0_RESRDY_vect) 81 | { 82 | /* Clear flag by writing '1': */ 83 | ADC0.INTFLAGS = ADC_RESRDY_bm; 84 | adcVal = ADC0.RES; 85 | LED0_toggle(); 86 | } 87 | 88 | void RTC_init(void) 89 | { 90 | uint8_t temp; 91 | 92 | /* Initialize 32.768kHz Oscillator: */ 93 | /* Disable oscillator: */ 94 | temp = CLKCTRL.XOSC32KCTRLA; 95 | temp &= ~CLKCTRL_ENABLE_bm; 96 | /* Enable writing to protected register */ 97 | CPU_CCP = CCP_IOREG_gc; 98 | CLKCTRL.XOSC32KCTRLA = temp; 99 | 100 | while(CLKCTRL.MCLKSTATUS & CLKCTRL_XOSC32KS_bm) 101 | { 102 | ; /* Wait until XOSC32KS becomes 0 */ 103 | } 104 | 105 | /* SEL = 0 (Use External Crystal): */ 106 | temp = CLKCTRL.XOSC32KCTRLA; 107 | temp &= ~CLKCTRL_SEL_bm; 108 | /* Enable writing to protected register */ 109 | CPU_CCP = CCP_IOREG_gc; 110 | CLKCTRL.XOSC32KCTRLA = temp; 111 | 112 | /* Enable oscillator: */ 113 | temp = CLKCTRL.XOSC32KCTRLA; 114 | temp |= CLKCTRL_ENABLE_bm; 115 | /* Enable writing to protected register */ 116 | CPU_CCP = CCP_IOREG_gc; 117 | CLKCTRL.XOSC32KCTRLA = temp; 118 | 119 | /* Initialize RTC: */ 120 | while (RTC.STATUS > 0) 121 | { 122 | ; /* Wait for all register to be synchronized */ 123 | } 124 | 125 | RTC.CTRLA = RTC_PRESCALER_DIV32_gc /* 32 */ 126 | | RTC_RTCEN_bm /* Enable: enabled */ 127 | | RTC_RUNSTDBY_bm; /* Run In Standby: enabled */ 128 | 129 | /* Set period */ 130 | RTC.PER = RTC_PERIOD; 131 | 132 | /* 32.768kHz External Crystal Oscillator (XOSC32K) */ 133 | RTC.CLKSEL = RTC_CLKSEL_TOSC32K_gc; 134 | 135 | /* Run in debug: enabled */ 136 | RTC.DBGCTRL |= RTC_DBGRUN_bm; 137 | } 138 | 139 | void EVSYS_init(void) 140 | { 141 | /* Real Time Counter overflow */ 142 | EVSYS.CHANNEL0 = EVSYS_GENERATOR_RTC_OVF_gc; 143 | /* Connect user to event channel 0 */ 144 | EVSYS.USERADC0 = EVSYS_CHANNEL_CHANNEL0_gc; 145 | } 146 | 147 | int main(void) 148 | { 149 | ADC0_init(); 150 | LED0_init(); 151 | RTC_init(); 152 | EVSYS_init(); 153 | 154 | /* Enable Global Interrupts */ 155 | sei(); 156 | 157 | while (1) 158 | { 159 | ; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /ADC_Free_Running/ADC_Free_Running.componentinfo.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Device 8 | Startup 9 | 10 | 11 | Atmel 12 | 1.2.0 13 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs 14 | 15 | 16 | 17 | 18 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include 19 | 20 | include 21 | C 22 | 23 | 24 | include 25 | 26 | 27 | 28 | 29 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom4809.h 30 | 31 | header 32 | C 33 | mWiFIOAGwUPlW0rYsXcjkg== 34 | 35 | include/avr/iom4809.h 36 | 37 | 38 | 39 | 40 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.c 41 | template 42 | source 43 | C Exe 44 | iVLLm0mDzCpNtG4XOrRxog== 45 | 46 | templates/main.c 47 | Main file (.c) 48 | 49 | 50 | 51 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.cpp 52 | template 53 | source 54 | C Exe 55 | YXFphlh0CtZJU+ebktABgQ== 56 | 57 | templates/main.cpp 58 | Main file (.cpp) 59 | 60 | 61 | 62 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809 63 | 64 | libraryPrefix 65 | GCC 66 | 67 | 68 | gcc/dev/atmega4809 69 | 70 | 71 | 72 | 73 | ATmega_DFP 74 | C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc 75 | 1.2.209 76 | true 77 | ATmega4809 78 | 79 | 80 | 81 | Resolved 82 | Fixed 83 | true 84 | 85 | 86 | -------------------------------------------------------------------------------- /ADC_Free_Running/ADC_Free_Running.cproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 2.0 5 | 7.0 6 | com.Atmel.AVRGCC8.C 7 | {d5ba22cf-da73-43d5-bcf3-4fbb589fdb38} 8 | ATmega4809 9 | none 10 | Executable 11 | C 12 | $(MSBuildProjectName) 13 | .elf 14 | $(MSBuildProjectDirectory)\$(Configuration) 15 | ADC_Free_Running 16 | ADC_Free_Running 17 | ADC_Free_Running 18 | Native 19 | true 20 | false 21 | true 22 | true 23 | 24 | 25 | true 26 | 27 | 2 28 | 0 29 | 0 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809" 48 | True 49 | True 50 | True 51 | True 52 | False 53 | True 54 | True 55 | 56 | 57 | NDEBUG 58 | 59 | 60 | 61 | 62 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 63 | 64 | 65 | Optimize for size (-Os) 66 | True 67 | True 68 | True 69 | 70 | 71 | libm 72 | 73 | 74 | 75 | 76 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809" 86 | True 87 | True 88 | True 89 | True 90 | False 91 | True 92 | True 93 | 94 | 95 | DEBUG 96 | 97 | 98 | 99 | 100 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 101 | 102 | 103 | Optimize (-O1) 104 | True 105 | True 106 | Default (-g2) 107 | True 108 | 109 | 110 | libm 111 | 112 | 113 | 114 | 115 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 116 | 117 | 118 | Default (-Wa,-g) 119 | 120 | 121 | 122 | 123 | 124 | compile 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /ADC_Free_Running/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | \file main.c 3 | 4 | \brief ADC free running 5 | 6 | (c) 2018 Microchip Technology Inc. and its subsidiaries. 7 | 8 | Subject to your compliance with these terms, you may use Microchip software and any 9 | derivatives exclusively with Microchip products. It is your responsibility to comply with third party 10 | license terms applicable to your use of third party software (including open source software) that 11 | may accompany Microchip software. 12 | 13 | THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 14 | EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 15 | IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 16 | FOR A PARTICULAR PURPOSE. 17 | 18 | IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 19 | INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 20 | WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 21 | HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 22 | THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 23 | CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 24 | OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 25 | SOFTWARE. 26 | */ 27 | 28 | #include 29 | #include 30 | 31 | uint16_t adcVal; 32 | 33 | void ADC0_init(void); 34 | uint16_t ADC0_read(void); 35 | void ADC0_start(void); 36 | bool ADC0_conersionDone(void); 37 | 38 | void ADC0_init(void) 39 | { 40 | /* Disable digital input buffer */ 41 | PORTD.PIN6CTRL &= ~PORT_ISC_gm; 42 | PORTD.PIN6CTRL |= PORT_ISC_INPUT_DISABLE_gc; 43 | 44 | /* Disable pull-up resistor */ 45 | PORTD.PIN6CTRL &= ~PORT_PULLUPEN_bm; 46 | 47 | ADC0.CTRLC = ADC_PRESC_DIV4_gc /* CLK_PER divided by 4 */ 48 | | ADC_REFSEL_INTREF_gc; /* Internal reference */ 49 | 50 | ADC0.CTRLA = ADC_ENABLE_bm /* ADC Enable: enabled */ 51 | | ADC_RESSEL_10BIT_gc; /* 10-bit mode */ 52 | 53 | /* Select ADC channel */ 54 | ADC0.MUXPOS = ADC_MUXPOS_AIN6_gc; 55 | 56 | /* Enable FreeRun mode */ 57 | ADC0.CTRLA |= ADC_FREERUN_bm; 58 | } 59 | 60 | uint16_t ADC0_read(void) 61 | { 62 | /* Clear the interrupt flag by writing 1: */ 63 | ADC0.INTFLAGS = ADC_RESRDY_bm; 64 | 65 | return ADC0.RES; 66 | } 67 | 68 | void ADC0_start(void) 69 | { 70 | /* Start conversion */ 71 | ADC0.COMMAND = ADC_STCONV_bm; 72 | } 73 | 74 | bool ADC0_conersionDone(void) 75 | { 76 | return (ADC0.INTFLAGS & ADC_RESRDY_bm); 77 | } 78 | 79 | int main(void) 80 | { 81 | ADC0_init(); 82 | ADC0_start(); 83 | 84 | while(1) 85 | { 86 | if (ADC0_conersionDone()) 87 | { 88 | adcVal = ADC0_read(); 89 | /* In FreeRun mode, the next conversion starts automatically */ 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /ADC_Sample_Accumulator/ADC_Sample_Accumulator.componentinfo.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Device 8 | Startup 9 | 10 | 11 | Atmel 12 | 1.2.0 13 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs 14 | 15 | 16 | 17 | 18 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include 19 | 20 | include 21 | C 22 | 23 | 24 | include 25 | 26 | 27 | 28 | 29 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom4809.h 30 | 31 | header 32 | C 33 | mWiFIOAGwUPlW0rYsXcjkg== 34 | 35 | include/avr/iom4809.h 36 | 37 | 38 | 39 | 40 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.c 41 | template 42 | source 43 | C Exe 44 | gAlvX73Ct3aYEgyb9eQNEg== 45 | 46 | templates/main.c 47 | Main file (.c) 48 | 49 | 50 | 51 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.cpp 52 | template 53 | source 54 | C Exe 55 | YXFphlh0CtZJU+ebktABgQ== 56 | 57 | templates/main.cpp 58 | Main file (.cpp) 59 | 60 | 61 | 62 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809 63 | 64 | libraryPrefix 65 | GCC 66 | 67 | 68 | gcc/dev/atmega4809 69 | 70 | 71 | 72 | 73 | ATmega_DFP 74 | C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc 75 | 1.2.209 76 | true 77 | ATmega4809 78 | 79 | 80 | 81 | Resolved 82 | Fixed 83 | true 84 | 85 | 86 | -------------------------------------------------------------------------------- /ADC_Sample_Accumulator/ADC_Sample_Accumulator.cproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 2.0 5 | 7.0 6 | com.Atmel.AVRGCC8.C 7 | {a55cf060-e086-4189-840a-907b6737b0bc} 8 | ATmega4809 9 | none 10 | Executable 11 | C 12 | $(MSBuildProjectName) 13 | .elf 14 | $(MSBuildProjectDirectory)\$(Configuration) 15 | ADC_Sample_Accumulator 16 | ADC_Sample_Accumulator 17 | ADC_Sample_Accumulator 18 | Native 19 | true 20 | false 21 | true 22 | true 23 | 24 | 25 | true 26 | 27 | 2 28 | 0 29 | 0 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809" 48 | True 49 | True 50 | True 51 | True 52 | False 53 | True 54 | True 55 | 56 | 57 | NDEBUG 58 | 59 | 60 | 61 | 62 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 63 | 64 | 65 | Optimize for size (-Os) 66 | True 67 | True 68 | True 69 | 70 | 71 | libm 72 | 73 | 74 | 75 | 76 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809" 86 | True 87 | True 88 | True 89 | True 90 | False 91 | True 92 | True 93 | 94 | 95 | DEBUG 96 | 97 | 98 | 99 | 100 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 101 | 102 | 103 | Optimize (-O1) 104 | True 105 | True 106 | Default (-g2) 107 | True 108 | 109 | 110 | libm 111 | 112 | 113 | 114 | 115 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 116 | 117 | 118 | Default (-Wa,-g) 119 | 120 | 121 | 122 | 123 | 124 | compile 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /ADC_Sample_Accumulator/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | \file main.c 3 | 4 | \brief ADC sample accumulator 5 | 6 | (c) 2018 Microchip Technology Inc. and its subsidiaries. 7 | 8 | Subject to your compliance with these terms, you may use Microchip software and any 9 | derivatives exclusively with Microchip products. It is your responsibility to comply with third party 10 | license terms applicable to your use of third party software (including open source software) that 11 | may accompany Microchip software. 12 | 13 | THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 14 | EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 15 | IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 16 | FOR A PARTICULAR PURPOSE. 17 | 18 | IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 19 | INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 20 | WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 21 | HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 22 | THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 23 | CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 24 | OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 25 | SOFTWARE. 26 | */ 27 | 28 | #define ADC_SHIFT_DIV64 (6) 29 | 30 | #include 31 | 32 | uint16_t adcVal; 33 | 34 | void ADC0_init(void); 35 | uint16_t ADC0_read(void); 36 | 37 | void ADC0_init(void) 38 | { 39 | /* Disable digital input buffer */ 40 | PORTD.PIN6CTRL &= ~PORT_ISC_gm; 41 | PORTD.PIN6CTRL |= PORT_ISC_INPUT_DISABLE_gc; 42 | 43 | /* Disable pull-up resistor */ 44 | PORTD.PIN6CTRL &= ~PORT_PULLUPEN_bm; 45 | 46 | ADC0.CTRLC = ADC_PRESC_DIV4_gc /* CLK_PER divided by 4 */ 47 | | ADC_REFSEL_INTREF_gc; /* Internal reference */ 48 | 49 | ADC0.CTRLA = ADC_ENABLE_bm /* ADC Enable: enabled */ 50 | | ADC_RESSEL_10BIT_gc; /* 10-bit mode */ 51 | 52 | /* Select ADC channel */ 53 | ADC0.MUXPOS = ADC_MUXPOS_AIN6_gc; 54 | 55 | /* Set the accumulator mode to accumulate 64 samples */ 56 | ADC0.CTRLB = ADC_SAMPNUM_ACC64_gc; 57 | } 58 | 59 | uint16_t ADC0_read(void) 60 | { 61 | /* Start ADC conversion */ 62 | ADC0.COMMAND = ADC_STCONV_bm; 63 | 64 | /* Wait until ADC conversion done */ 65 | while ( !(ADC0.INTFLAGS & ADC_RESRDY_bm) ) 66 | { 67 | ; 68 | } 69 | 70 | /* Clear the interrupt flag by writing 1: */ 71 | ADC0.INTFLAGS = ADC_RESRDY_bm; 72 | 73 | return ADC0.RES; 74 | } 75 | 76 | int main(void) 77 | { 78 | ADC0_init(); 79 | 80 | while (1) 81 | { 82 | adcVal = ADC0_read(); 83 | 84 | /* divide by 64 */ 85 | adcVal = adcVal >> ADC_SHIFT_DIV64; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /ADC_Single_Conversion/ADC_Single_Conversion.componentinfo.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Device 8 | Startup 9 | 10 | 11 | Atmel 12 | 1.2.0 13 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs 14 | 15 | 16 | 17 | 18 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include 19 | 20 | include 21 | C 22 | 23 | 24 | include 25 | 26 | 27 | 28 | 29 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom4809.h 30 | 31 | header 32 | C 33 | mWiFIOAGwUPlW0rYsXcjkg== 34 | 35 | include/avr/iom4809.h 36 | 37 | 38 | 39 | 40 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.c 41 | template 42 | source 43 | C Exe 44 | ZR41ynsG6FtFCoq2IL36DA== 45 | 46 | templates/main.c 47 | Main file (.c) 48 | 49 | 50 | 51 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.cpp 52 | template 53 | source 54 | C Exe 55 | YXFphlh0CtZJU+ebktABgQ== 56 | 57 | templates/main.cpp 58 | Main file (.cpp) 59 | 60 | 61 | 62 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809 63 | 64 | libraryPrefix 65 | GCC 66 | 67 | 68 | gcc/dev/atmega4809 69 | 70 | 71 | 72 | 73 | ATmega_DFP 74 | C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc 75 | 1.2.209 76 | true 77 | ATmega4809 78 | 79 | 80 | 81 | Resolved 82 | Fixed 83 | true 84 | 85 | 86 | -------------------------------------------------------------------------------- /ADC_Single_Conversion/ADC_Single_Conversion.cproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 2.0 5 | 7.0 6 | com.Atmel.AVRGCC8.C 7 | {1e855a65-a866-40de-abfb-b071eb72bba2} 8 | ATmega4809 9 | none 10 | Executable 11 | C 12 | $(MSBuildProjectName) 13 | .elf 14 | $(MSBuildProjectDirectory)\$(Configuration) 15 | ADC_Single_Conversion 16 | ADC_Single_Conversion 17 | ADC_Single_Conversion 18 | Native 19 | true 20 | false 21 | true 22 | true 23 | 24 | 25 | true 26 | 27 | 2 28 | 0 29 | 0 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809" 48 | True 49 | True 50 | True 51 | True 52 | False 53 | True 54 | True 55 | 56 | 57 | NDEBUG 58 | 59 | 60 | 61 | 62 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 63 | 64 | 65 | Optimize for size (-Os) 66 | True 67 | True 68 | True 69 | 70 | 71 | libm 72 | 73 | 74 | 75 | 76 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809" 86 | True 87 | True 88 | True 89 | True 90 | False 91 | True 92 | True 93 | 94 | 95 | DEBUG 96 | 97 | 98 | 99 | 100 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 101 | 102 | 103 | Optimize (-O1) 104 | True 105 | True 106 | Default (-g2) 107 | True 108 | 109 | 110 | libm 111 | 112 | 113 | 114 | 115 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 116 | 117 | 118 | Default (-Wa,-g) 119 | 120 | 121 | 122 | 123 | 124 | compile 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /ADC_Single_Conversion/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | \file main.c 3 | 4 | \brief ADC single conversion 5 | 6 | (c) 2018 Microchip Technology Inc. and its subsidiaries. 7 | 8 | Subject to your compliance with these terms, you may use Microchip software and any 9 | derivatives exclusively with Microchip products. It is your responsibility to comply with third party 10 | license terms applicable to your use of third party software (including open source software) that 11 | may accompany Microchip software. 12 | 13 | THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 14 | EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 15 | IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 16 | FOR A PARTICULAR PURPOSE. 17 | 18 | IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 19 | INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 20 | WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 21 | HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 22 | THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 23 | CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 24 | OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 25 | SOFTWARE. 26 | */ 27 | 28 | /* RTC Period */ 29 | #define RTC_PERIOD (511) 30 | 31 | #include 32 | #include 33 | 34 | uint16_t adcVal; 35 | 36 | void ADC0_init(void); 37 | uint16_t ADC0_read(void); 38 | 39 | void ADC0_init(void) 40 | { 41 | /* Disable digital input buffer */ 42 | PORTD.PIN6CTRL &= ~PORT_ISC_gm; 43 | PORTD.PIN6CTRL |= PORT_ISC_INPUT_DISABLE_gc; 44 | 45 | /* Disable pull-up resistor */ 46 | PORTD.PIN6CTRL &= ~PORT_PULLUPEN_bm; 47 | 48 | ADC0.CTRLC = ADC_PRESC_DIV4_gc /* CLK_PER divided by 4 */ 49 | | ADC_REFSEL_INTREF_gc; /* Internal reference */ 50 | 51 | ADC0.CTRLA = ADC_ENABLE_bm /* ADC Enable: enabled */ 52 | | ADC_RESSEL_10BIT_gc; /* 10-bit mode */ 53 | 54 | /* Select ADC channel */ 55 | ADC0.MUXPOS = ADC_MUXPOS_AIN6_gc; 56 | } 57 | 58 | uint16_t ADC0_read(void) 59 | { 60 | /* Start ADC conversion */ 61 | ADC0.COMMAND = ADC_STCONV_bm; 62 | 63 | /* Wait until ADC conversion done */ 64 | while ( !(ADC0.INTFLAGS & ADC_RESRDY_bm) ) 65 | { 66 | ; 67 | } 68 | 69 | /* Clear the interrupt flag by writing 1: */ 70 | ADC0.INTFLAGS = ADC_RESRDY_bm; 71 | 72 | return ADC0.RES; 73 | } 74 | 75 | int main(void) 76 | { 77 | ADC0_init(); 78 | 79 | adcVal = ADC0_read(); 80 | 81 | while (1) 82 | { 83 | ; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /ADC_Window_Comparator/ADC_Window_Comparator.componentinfo.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Device 8 | Startup 9 | 10 | 11 | Atmel 12 | 1.2.0 13 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs 14 | 15 | 16 | 17 | 18 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include 19 | 20 | include 21 | C 22 | 23 | 24 | include 25 | 26 | 27 | 28 | 29 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom4809.h 30 | 31 | header 32 | C 33 | mWiFIOAGwUPlW0rYsXcjkg== 34 | 35 | include/avr/iom4809.h 36 | 37 | 38 | 39 | 40 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.c 41 | template 42 | source 43 | C Exe 44 | v3U1msAxXNAhMCpa27NzpQ== 45 | 46 | templates/main.c 47 | Main file (.c) 48 | 49 | 50 | 51 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.cpp 52 | template 53 | source 54 | C Exe 55 | YXFphlh0CtZJU+ebktABgQ== 56 | 57 | templates/main.cpp 58 | Main file (.cpp) 59 | 60 | 61 | 62 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809 63 | 64 | libraryPrefix 65 | GCC 66 | 67 | 68 | gcc/dev/atmega4809 69 | 70 | 71 | 72 | 73 | ATmega_DFP 74 | C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc 75 | 1.2.209 76 | true 77 | ATmega4809 78 | 79 | 80 | 81 | Resolved 82 | Fixed 83 | true 84 | 85 | 86 | -------------------------------------------------------------------------------- /ADC_Window_Comparator/ADC_Window_Comparator.cproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 2.0 5 | 7.0 6 | com.Atmel.AVRGCC8.C 7 | {1b80530a-a910-45c9-a1b8-9f69783a1b09} 8 | ATmega4809 9 | none 10 | Executable 11 | C 12 | $(MSBuildProjectName) 13 | .elf 14 | $(MSBuildProjectDirectory)\$(Configuration) 15 | ADC_Window_Comparator 16 | ADC_Window_Comparator 17 | ADC_Window_Comparator 18 | Native 19 | true 20 | false 21 | true 22 | true 23 | 24 | 25 | true 26 | 27 | 2 28 | 0 29 | 0 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809" 48 | True 49 | True 50 | True 51 | True 52 | False 53 | True 54 | True 55 | 56 | 57 | NDEBUG 58 | 59 | 60 | 61 | 62 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 63 | 64 | 65 | Optimize for size (-Os) 66 | True 67 | True 68 | True 69 | 70 | 71 | libm 72 | 73 | 74 | 75 | 76 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809" 86 | True 87 | True 88 | True 89 | True 90 | False 91 | True 92 | True 93 | 94 | 95 | DEBUG 96 | 97 | 98 | 99 | 100 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 101 | 102 | 103 | Optimize (-O1) 104 | True 105 | True 106 | Default (-g2) 107 | True 108 | 109 | 110 | libm 111 | 112 | 113 | 114 | 115 | %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include 116 | 117 | 118 | Default (-Wa,-g) 119 | 120 | 121 | 122 | 123 | 124 | compile 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /ADC_Window_Comparator/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | \file main.c 3 | 4 | \brief ADC window comparator 5 | 6 | (c) 2018 Microchip Technology Inc. and its subsidiaries. 7 | 8 | Subject to your compliance with these terms, you may use Microchip software and any 9 | derivatives exclusively with Microchip products. It is your responsibility to comply with third party 10 | license terms applicable to your use of third party software (including open source software) that 11 | may accompany Microchip software. 12 | 13 | THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 14 | EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 15 | IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 16 | FOR A PARTICULAR PURPOSE. 17 | 18 | IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 19 | INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 20 | WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 21 | HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 22 | THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 23 | CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 24 | OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 25 | SOFTWARE. 26 | */ 27 | 28 | #define WINDOW_CMP_LOW_TH_EXAMPLE (0x100) 29 | 30 | #include 31 | #include 32 | 33 | uint16_t adcVal; 34 | 35 | void ADC0_init(void); 36 | uint16_t ADC0_read(void); 37 | void ADC0_start(void); 38 | bool ADC0_conersionDone(void); 39 | bool ADC0_resultBelowTreshold(void); 40 | void ADC0_clearWindowCmpIntFlag(void); 41 | void LED0_init(void); 42 | void LED0_on(void); 43 | void LED0_off(void); 44 | 45 | void ADC0_init(void) 46 | { 47 | /* Disable digital input buffer */ 48 | PORTD.PIN6CTRL &= ~PORT_ISC_gm; 49 | PORTD.PIN6CTRL |= PORT_ISC_INPUT_DISABLE_gc; 50 | 51 | /* Disable pull-up resistor */ 52 | PORTD.PIN6CTRL &= ~PORT_PULLUPEN_bm; 53 | 54 | ADC0.CTRLC = ADC_PRESC_DIV4_gc /* CLK_PER divided by 4 */ 55 | | ADC_REFSEL_INTREF_gc; /* Internal reference */ 56 | 57 | ADC0.CTRLA = ADC_ENABLE_bm /* ADC Enable: enabled */ 58 | | ADC_RESSEL_10BIT_gc; /* 10-bit mode */ 59 | 60 | /* Select ADC channel */ 61 | ADC0.MUXPOS = ADC_MUXPOS_AIN6_gc; 62 | 63 | /* Set conversion window comparator low threshold */ 64 | ADC0.WINLT = WINDOW_CMP_LOW_TH_EXAMPLE; 65 | 66 | /* Set conversion window mode */ 67 | ADC0.CTRLE = ADC_WINCM_BELOW_gc; 68 | 69 | /* Enable FreeRun mode */ 70 | ADC0.CTRLA |= ADC_FREERUN_bm; 71 | } 72 | 73 | uint16_t ADC0_read(void) 74 | { 75 | /* Clear the interrupt flag by writing 1: */ 76 | ADC0.INTFLAGS = ADC_RESRDY_bm; 77 | 78 | return ADC0.RES; 79 | } 80 | 81 | void ADC0_start(void) 82 | { 83 | /* Start conversion */ 84 | ADC0.COMMAND = ADC_STCONV_bm; 85 | } 86 | 87 | bool ADC0_conersionDone(void) 88 | { 89 | return (ADC0.INTFLAGS & ADC_RESRDY_bm); 90 | } 91 | 92 | bool ADC0_resultBelowTreshold(void) 93 | { 94 | return (ADC0.INTFLAGS & ADC_WCMP_bm); 95 | } 96 | 97 | void ADC0_clearWindowCmpIntFlag(void) 98 | { 99 | /* Clear the interrupt flag by writing 1: */ 100 | ADC0.INTFLAGS = ADC_WCMP_bm; 101 | } 102 | 103 | void LED0_init(void) 104 | { 105 | /* Make High (OFF) */ 106 | PORTB.OUT |= PIN5_bm; 107 | /* Make output */ 108 | PORTB.DIR |= PIN5_bm; 109 | } 110 | 111 | void LED0_on(void) 112 | { 113 | /* Make Low (ON) */ 114 | PORTB.OUT &= ~PIN5_bm; 115 | } 116 | 117 | void LED0_off(void) 118 | { 119 | /* Make High (OFF) */ 120 | PORTB.OUT |= PIN5_bm; 121 | } 122 | 123 | int main(void) 124 | { 125 | ADC0_init(); 126 | LED0_init(); 127 | 128 | ADC0_start(); 129 | 130 | while(1) 131 | { 132 | if (ADC0_conersionDone()) 133 | { 134 | if(ADC0_resultBelowTreshold()) 135 | { 136 | LED0_on(); 137 | ADC0_clearWindowCmpIntFlag(); 138 | } 139 | else 140 | { 141 | LED0_off(); 142 | } 143 | 144 | adcVal = ADC0_read(); 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /ATMEGA4809_ADC_Examples.atsln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Atmel Studio Solution File, Format Version 11.00 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "ADC_Event_Triggered", "ADC_Event_Triggered\ADC_Event_Triggered.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}" 7 | EndProject 8 | Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "ADC_Single_Conversion", "ADC_Single_Conversion\ADC_Single_Conversion.cproj", "{1E855A65-A866-40DE-ABFB-B071EB72BBA2}" 9 | EndProject 10 | Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "ADC_Free_Running", "ADC_Free_Running\ADC_Free_Running.cproj", "{D5BA22CF-DA73-43D5-BCF3-4FBB589FDB38}" 11 | EndProject 12 | Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "ADC_Sample_Accumulator", "ADC_Sample_Accumulator\ADC_Sample_Accumulator.cproj", "{A55CF060-E086-4189-840A-907B6737B0BC}" 13 | EndProject 14 | Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "ADC_Window_Comparator", "ADC_Window_Comparator\ADC_Window_Comparator.cproj", "{1B80530A-A910-45C9-A1B8-9F69783A1B09}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|AVR = Debug|AVR 19 | Release|AVR = Release|AVR 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR 23 | {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR 24 | {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR 25 | {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR 26 | {1E855A65-A866-40DE-ABFB-B071EB72BBA2}.Debug|AVR.ActiveCfg = Debug|AVR 27 | {1E855A65-A866-40DE-ABFB-B071EB72BBA2}.Debug|AVR.Build.0 = Debug|AVR 28 | {1E855A65-A866-40DE-ABFB-B071EB72BBA2}.Release|AVR.ActiveCfg = Release|AVR 29 | {1E855A65-A866-40DE-ABFB-B071EB72BBA2}.Release|AVR.Build.0 = Release|AVR 30 | {D5BA22CF-DA73-43D5-BCF3-4FBB589FDB38}.Debug|AVR.ActiveCfg = Debug|AVR 31 | {D5BA22CF-DA73-43D5-BCF3-4FBB589FDB38}.Debug|AVR.Build.0 = Debug|AVR 32 | {D5BA22CF-DA73-43D5-BCF3-4FBB589FDB38}.Release|AVR.ActiveCfg = Release|AVR 33 | {D5BA22CF-DA73-43D5-BCF3-4FBB589FDB38}.Release|AVR.Build.0 = Release|AVR 34 | {A55CF060-E086-4189-840A-907B6737B0BC}.Debug|AVR.ActiveCfg = Debug|AVR 35 | {A55CF060-E086-4189-840A-907B6737B0BC}.Debug|AVR.Build.0 = Debug|AVR 36 | {A55CF060-E086-4189-840A-907B6737B0BC}.Release|AVR.ActiveCfg = Release|AVR 37 | {A55CF060-E086-4189-840A-907B6737B0BC}.Release|AVR.Build.0 = Release|AVR 38 | {1B80530A-A910-45C9-A1B8-9F69783A1B09}.Debug|AVR.ActiveCfg = Debug|AVR 39 | {1B80530A-A910-45C9-A1B8-9F69783A1B09}.Debug|AVR.Build.0 = Debug|AVR 40 | {1B80530A-A910-45C9-A1B8-9F69783A1B09}.Release|AVR.ActiveCfg = Release|AVR 41 | {1B80530A-A910-45C9-A1B8-9F69783A1B09}.Release|AVR.Build.0 = Release|AVR 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | EndGlobal 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | The content of this repository has been moved to https://github.com/microchip-pic-avr-examples/atmega4809-getting-started-with-adc-studio . Additionally, a repository containing MCC generated code examples for AVR128DA48 with the same functionality can be found at https://github.com/microchip-pic-avr-examples/avr128da48-getting-started-with-adc-mplab-mcc . This repository is obsolete and it will not be maintained. 2 | 3 | ATMEGA4809_ADC_Examples 4 | === 5 | 6 | This repository contains examples of bare metal source code for ADC as described in TB3209 document from Microchip. 7 | The repository contains an Atmel Studio Solution with multiple projects inside. Make sure you have the necessary tools: 8 | 1. ATmega4809 device (or evaluation board ATmega4809 Xplained PRO) 9 | 2. Atmel Studio 10 | 3. ATmega4809 Device Packs 11 | 12 | The following examples are inside this repository: 13 | 1. ADC Single Conversion 14 | 2. ADC Free Running 15 | 3. ADC Sample Accumulator 16 | 4. ADC Window Comparator 17 | 5. ADC Event Triggered --------------------------------------------------------------------------------