Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:multiasm:exercisesbook:avr:sut [2026/04/30 09:51] – [Hardware reference] pczekalskien:multiasm:exercisesbook:avr:sut [2026/05/04 14:50] (current) – [Visualising Instruction Execution Time Using an Oscilloscope] pczekalski
Line 30: Line 30:
 </table> </table>
  
 +
 +==== Handling of the buffered 4-digit, 7-segment display ====
 To display a digit in the 4x7seg. display, there are two definitions needed: the shape of a digit (or other symbol), and its position (1,2,3,4: a binary mask). To display a digit in the 4x7seg. display, there are two definitions needed: the shape of a digit (or other symbol), and its position (1,2,3,4: a binary mask).
  
Line 40: Line 42:
     .byte      0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90     .byte      0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90
 </code> </code>
 +In a common-anode configuration, the active signal to turn on a segment is LOW (0), and to turn it off, it is HIGH (1). The state of a single digit is represented by an 8-bit mask: 7 segments to build the symbol and a DP (decimal point). For example, a digit 7 is represented by bits corresponding to segments "a", "b", and "c" set to 0 (to turn segments "a", "b", and "c" on) and the remaining bits set to 1 (to turn them off), so the corresponding binary value looks as follows: 11111000b, hence the hexadecimal value is 0xF8 (as in the code above). The MSB bit represents DP, and the LSB segment "a". This definition affects how one loads data into the shift register: starting from MSB towards LSB, because of the way the register is built and connected to the segments - refer to the function ''display_digit'' below.
 +
 <note tip>Naturally, it is possible to expand those definitions to display other symbols, e.g., hexadecimal digits such as A,b,C,d,E,F.</note>  <note tip>Naturally, it is possible to expand those definitions to display other symbols, e.g., hexadecimal digits such as A,b,C,d,E,F.</note> 
  
Line 47: Line 51:
 When binary combinations in both registers (line and symbol) are ready to be represented, a LAT_PORT  0->1->0 pulse rewrites register counters to the internal buffer, and it instantly causes displays to light according to the symbol definition loaded into the right register (only current digit, others are off at this time).  When binary combinations in both registers (line and symbol) are ready to be represented, a LAT_PORT  0->1->0 pulse rewrites register counters to the internal buffer, and it instantly causes displays to light according to the symbol definition loaded into the right register (only current digit, others are off at this time). 
  
 +** Display single digit: function definition **\\
 To handle display, a sample function that displays a digit in a selected position is presented below. Note that it does not check parameters and thus assumes that the digit position is a number between 0 and 3, and that a digit to display is 0..9. Going beyond these limits causes unpredictable behaviour and usually an MCU program crash. To handle display, a sample function that displays a digit in a selected position is presented below. Note that it does not check parameters and thus assumes that the digit position is a number between 0 and 3, and that a digit to display is 0..9. Going beyond these limits causes unpredictable behaviour and usually an MCU program crash.
 <code asm> <code asm>
Line 142: Line 147:
 </code> </code>
  
-Note: registers in this schema store data for only ONE digit. Iterating over digits and displaying them allows it to represent a full, multi-digit number. To display, e.g., 1023, it is necessary to handle each digit separately: "1", "0", "2", and "3", and to repeat this process continuously. If you stop, only the last digit will be visible.\\+<note important>Note: registers in this schema store data for only ONE digit. Iterating over digits and displaying them allows it to represent a full, multi-digit number. To display, e.g., 1023, it is necessary to handle each digit separately: "1", "0", "2", and "3", and to repeat this process continuously. If you stop, only the last digit will be visible.</note> 
 +<note tip>Changing the definitions of the symbols stored in ''segment_masks'' enables you to easily present characters other than numbers. Think about ''segment_masks'' as a font definition that defines how a symbol looks.</note>
  
 +** Display single digit: how to use it to display a number? **\\
 Sample code that uses the function declared above and displays 1975 is presented below. Note, the MCU runs here at full speed, constantly updating the display. While it is not necessary to (a minimum, comfortable LED display refresh rate should be around 10Hz), we do not present such a solution here for the sake of simplicity. It is common to address timers for this job to periodically refresh the screen. Sample code that uses the function declared above and displays 1975 is presented below. Note, the MCU runs here at full speed, constantly updating the display. While it is not necessary to (a minimum, comfortable LED display refresh rate should be around 10Hz), we do not present such a solution here for the sake of simplicity. It is common to address timers for this job to periodically refresh the screen.
 <code asm> <code asm>
Line 183: Line 190:
     clr r25     clr r25
     clr r23     clr r23
-    ; --- Idle Main Loop ---+    ; --- Main Loop, displays in sequence 1->9->7->---
 LOOP: LOOP:
     ldi r24,0     ldi r24,0
Line 206: Line 213:
 </code> </code>
 In the function above, we used fixed (constant) digits to display. A common scenario, however, is when the number is stored in some register or in a memory variable. In the function above, we used fixed (constant) digits to display. A common scenario, however, is when the number is stored in some register or in a memory variable.
 +
 +** Convert number to digits: function definition **\\
 To display a number on this kind of display, you need to convert it into an array of bytes, each representing a digit. A function below does the trick. To display a number on this kind of display, you need to convert it into an array of bytes, each representing a digit. A function below does the trick.
 <code asm> <code asm>
Line 331: Line 340:
  
 <note tip>Nodes are interconnected in pairs: 1-2, 3-4, 5-6, 7-8, 9-10. Scenarios for data transmission between MCUs require booking and the use of correct nodes for sending and receiving messages.</note> <note tip>Nodes are interconnected in pairs: 1-2, 3-4, 5-6, 7-8, 9-10. Scenarios for data transmission between MCUs require booking and the use of correct nodes for sending and receiving messages.</note>
 +
 +==== Visualising Instruction Execution Time Using an Oscilloscope ====
 +Let's try to visualise how code operates the GPIO. Naturally, in the remote lab, it is not possible to do it remotely, so here we present some desk-based experiments.\\
 +The ''LAT_PIN'' is GPIO4, and an oscilloscope is connected to it.
 +In the function that displays a single digit, there is a section that loads a binary mask into the internal registers, enabling the LED segments that constitute the digit to be turned on and off. It is:
 +<code asm>
 +...
 +    sbi LAT_PORT, LAT_PIN
 +    cbi LAT_PORT, LAT_PIN
 +...
 +</code>
 +
 +The figures {{ref>arduinounodigitoscilloscope1}} and {{ref>arduinounodigitoscilloscope2}} present the ''LAT_PIN'' signal, called periodically during the display of the consecutive digits (they represent the same signal but differ by the oscilloscope time base for better observation).\\
 +''SBI'' causes the signal to rise, while ''CBI'' to fall. Thus, the HIGH time is the exact time during which the CBI instruction executes. It takes about 120-130ns.\\
 +The Arduino Uno operates at 16 MHz, so each cycle is 1/16000000 s, which is about 63 ns. According to the documentation, ''CBI'' takes 2 cycles, which is ~126ns.
 +
 +<figure arduinounodigitoscilloscope1>
 +{{:en:multiasm:exercisesbook:avr:pic_1054.png?300|}}
 +<caption>''LAT_PIN'' signal (50ns time base)</caption>
 +</figure>
 +
 +<figure arduinounodigitoscilloscope2>
 +{{:en:multiasm:exercisesbook:avr:pic_1055.png?300|}}
 +<caption>''LAT_PIN'' signal (25ns time base)</caption>
 +</figure>
en/multiasm/exercisesbook/avr/sut.1777531902.txt.gz · Last modified: by pczekalski
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0