| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| en:multiasm:exercisesbook:arduinouno [2026/03/26 23:03] – [Instructions] pczekalski | en:multiasm:exercisesbook:arduinouno [2026/03/26 23:42] (current) – [Reading analogue values] pczekalski |
|---|
| |
| ==== Instructions ==== | ==== Instructions ==== |
| There is a set of assembler instructions that operate on port registers, represented in table {{ref>assemblergpioinstructions}}. Assembler-level operations are much faster than C++.\\ | There is a set of assembler instructions that operate on Ports (I/O registers), as shown in table {{ref>assemblergpioinstructions}}. |
| | <note>Assembler-level operations using ports are much faster than ''DigitalRead'', ''DigitalWrite'', and other instructions in C++, roughly 50 times faster.</note> |
| |
| <table assemblergpioinstructions> | <table assemblergpioinstructions> |
| <caption>Common GPIO-operating, bit level instructions</caption> | <caption>Common GPIO-related, I/O instructions</caption> |
| ^ Instruction ^ Description ^ | ^ Instruction ^ Description ^ |
| | ''SBI'' | Set bit in register | | | ''SBI'' | Set bit in register | |
| | ''IN'' | Read hardware register to the general-purpose register (R0-R31) | | | ''IN'' | Read hardware register to the general-purpose register (R0-R31) | |
| | ''OUT'' | Write the general-purpose register to the hardware register. | | | ''OUT'' | Write the general-purpose register to the hardware register. | |
| | | ''ANDI'' | Masks a bit | |
| | | ''ORI'' | Sets a bit | |
| </table> | </table> |
| |
| A common scenario is to first set either the GPIO is input or output (using the correct DDRx register), then either set (''SBI''), reset (''CBI''), check (''SBIS'', ''SBIC''), read the whole register (''IN'') or write the whole register (''OUT''). | A common scenario is to first set either the GPIO is input or output (using the correct DDRx register), then either set (''SBI''), reset (''CBI''), check (''SBIS'', ''SBIC''), read the whole register (''IN'') or write the whole register (''OUT''). |
| <note tip>''IN'' and ''OUT'' instructions operate on whole, 8-bit registers rather than on single bits. Those are general-purpose instructions, covering the whole range of IO registers (0-63), beyond aforementioned DDRx, PORTx and PINx registers.</note> | <note tip>''IN'' and ''OUT'' instructions operate on whole, 8-bit registers rather than on single bits. Those are general-purpose instructions, covering the whole range of IO registers (0-63), beyond aforementioned DDRx, PORTx and PINx registers.</note> |
| | |
| | ==== Examples ==== |
| | Below are sections representing common usage scenarios: |
| | |
| | ==== Reading analogue values ==== |
| | Reading of the analogue values is not so straightforward as in the case of binary ones. |
| | Built-in ADC converter uses 10-bit resolution, has 6 channels (A0-A5, respectively). It also uses a reference voltage (configurable), typically 5V.\\ |
| | The low-level ADC register-based operations use the following formula to obtain an ADC value (figure {{ref>avreq1}}, based on the input value ''Vgpio'' and the reference value ''Vref''). |
| | |
| | <figure avreq1> |
| | {{:en:multiasm:exercisesbook:screenshot_from_2026-03-26_22-41-59.png?200|}} |
| | <caption>ADC value calculation based on the input voltage and reference voltage</caption> |
| | </figure> |
| | |
| | Analogue reading uses a complex setup of ADC-related registers as presented in table {{ref>tabadcregisters}}: |
| | |
| | <table tabadcregisters> |
| | <caption>ADC-related registers used for reading the analogue values of GPIOs</caption> |
| | ^ Register ^ Description ^ |
| | | ''ADMUX'' | Selects voltage reference and | |
| | | | | |
| | | | | |
| | | | | |
| | </table> |
| | |