7 Blinking a 3V LED with VDD at 1.8V
Following the instructions in the Hardware Configuration section to supply VDDIO2 with 3.3V and VDD with 1.8V. Make sure that VDDIO2 and VDD have the correct voltage levels by using a multi-meter.
Following the instruction in the Reading the Status Bit section, we check that VDDIO2 is within acceptable range before starting the blinking.
Make sure the LED has a forward voltage of approximately 3V by using a multimeter with diode testing capabilities. A green LED usually has a forward voltage of approximately 3V.
An external green LED in series with a resistor of at least 15 Ohms needs to be connected to PC0, like shown in the figure below.
If a different LED is used, the resistor value needs to change. This is calculated using the following formula where VLED is the voltage drop of the LED and ALED is current through the LED:
/*Blinking a 3V LED with VDD at 1.8V*/ /*Set LED pin to output*/ void LED_PC0_init(void) { PORTC.DIRSET = PIN0_bm; } /*Toggle LED pin*/ void LED_PC0_toggle(void) { PORTC.OUTTGL=PIN0_bm; } int main(void) { LED_PC0_init(); while (1) { /*Check if VDDIO2 is within acceptable range*/ if(MVIO.STATUS & MVIO_VDDIO2S_bm) { /*Blink LED at PC0 forever*/ while (1) { LED_PC0_toggle(); _delay_ms(250); } } } }
The code for this example is available in the blinking-a-3v0-led-with-vdd-at-1v8 folder in these github repositories