This is an old revision of the document!


SUT AVR Assembler Laboratory Node Hardware Reference

Introduction

Each laboratory node is equipped with an Arduino Uno R3 development board, based on the ATmega328P MCU. It also has two extension boards:

  • external, analogue and digital communication board,
  • user interface board presented on the image 1.

There are 10 laboratory nodes. They can be used independently, but for collaboration, nodes are interconnected symmetrically, with GPIOs described in the hardware reference section below.

Hardware reference

The table 1 lists all hardware components and details. Note that some elements are accessible, but their use is not supported via the remote lab, e.g., buttons and a buzzer.
The node is depicted in the figure 1 and its interface visual schematic is presented in the figure 2. The schematic presents only components used in scenarios and accessible via the VREL NextGen environment (controllable and observable via video stream), omitting unused components such as buttons, a buzzer, and a potentiometer.

Figure 1: AVR (Arduino Uno) SUT Node
Figure 2: SUT node's visual interface components schematic
Table 1: AVR (Arduino Uno) SUT Node Hardware Details
Component ID Component Hardware Details (controller) Control method GPIOs (as mapped to the Arduno Uno) Remarks
D1 LED (red) direct via GPIO binary (0→on, 1→off) GPIO13
D2 LED (red) direct via GPIO binary (0→on, 1→off) GPIO12
D3 LED (red) direct via GPIO binary (0→on, 1→off) GPIO11
D4 LED (red) direct via GPIO binary (0→on, 1→off) GPIO10 shared with interconnection with another module
LED4 4x 7-segment display(+DP) indirect, via two 74HC575 registers serial load to 2 registers, daisy-chained GPIO8 - serial input of the controller (SER_PORT)
GPIO7 - shift data internally (CLK_PIN), raising edge (write next bit and shift data in serial)
GPIO4 - store data to internal buffer, in 74H575, stores only one digit(LAT_PIN)

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).

The 7-segment display is a common-anode (you use zero to turn the segment on), and thus 0..9 digit definitions are declared below:

; Common Anode 7-segment masks (Active LOW)
; Segments:     DP,g,f,e,d,c,b,a (Bit 7 -> Bit 0)
; Indices:       0     1     2     3     4     5     6     7     8     9
segment_masks:
    .byte      0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90
Naturally, it is possible to expand those definitions to display other symbols, e.g., hexadecimal digits such as A,b,C,d,E,F.

The way the display works is similar to a typical matrix dot display: instead of having to control 32 independent digital lines to control each LED composing the display independently (8 per digit, 4 digits), we use a digit selector (lines 0,1,2,3) and common symbol lines (lines DP,g,f,e,d,c,b,a).
This way, the display “flashes” because, to display more than one digit, you need to iterate over the lines instantly and set the appropriate symbol definitions. However, the human eye is slow enough not to notice it, and thus we see all 4 digits in parallel, not being displayed one by one that in fact is a real scenario.
The schematic in Figure 1 shows an idea of how to control a single digit over a serial port pin (SER_PIN): you need to inject bit by bit, starting from the least significant bit of the symbol representing a digit, then 8 bits of the digit number - selected by lines 1,2,3,4, so only 0001b, 0010b, 0100b and 1000b combinations are used. A 0→1→0 pulse on the clock (SER_CLK) writes the data to the left registers and shifts the contents right (including passing from the left register to the right one). This way, after 16 cycles (8+8) the left register holds the line to select the digit (1,2,3,4) and the right register holds the combination representing a symbol at this postion.
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). Note: those registers 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.

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.

; Pin definitions using direct I/O addresses for ATmega328P
.equ SER_PORT, 0x05  ; PORTB I/O address
.equ SER_PIN,  0
.equ CLK_PORT, 0x0B  ; PORTD I/O address
.equ CLK_PIN,  7
.equ LAT_PORT, 0x0B  ; PORTD I/O address
.equ LAT_PIN,  4
 
.global display_digit
 
; void display_digit(uint8_t pos, uint8_t number);
; r24 = position (0 to 3)
; r22 = number (0 to 9)
display_digit:
    push r16
    push r17
    push r18
    push zl
    push zh
 
    ; 1. Load Segment Mask (for U3) from flash
    ldi zl, lo8(segment_masks)
    ldi zh, hi8(segment_masks)
    add zl, r22               ; Add number index to Z pointer
    adc zh, r1                ; r1 is assumed to be 0 (gcc standard)
    lpm r16, Z                ; r16 now holds segment data
 
    ; 2. Load Digit Select Mask (for U2) from flash
    ldi zl, lo8(digit_masks)
    ldi zh, hi8(digit_masks)
    add zl, r24               ; Add position index to Z pointer
    adc zh, r1
    lpm r17, Z                ; r17 now holds digit select data
 
    ; 3. Shift out Segment Data (r16) -> Ends up in U3
    ldi r18, 8                ; Loop counter for 8 bits
shift_segments:
    lsl r16                   ; Shift MSB into Carry flag
    brcs set_ser_seg          ; If Carry is 1, branch to set SER high
    cbi SER_PORT, SER_PIN     ; Clear SER low
    rjmp clock_seg
set_ser_seg:
    sbi SER_PORT, SER_PIN     ; Set SER high
clock_seg:
    ; Pulse SRCLK
    sbi CLK_PORT, CLK_PIN
    cbi CLK_PORT, CLK_PIN
    dec r18
    brne shift_segments
 
    ; 4. Shift out Digit Select Data (r17) -> Ends up in U2
    ldi r18, 8                ; Loop counter for 8 bits
shift_digits:
    lsl r17                   ; Shift MSB into Carry flag
    brcs set_ser_dig
    cbi SER_PORT, SER_PIN
    rjmp clock_dig
set_ser_dig:
    sbi SER_PORT, SER_PIN
clock_dig:
    ; Pulse SRCLK
    sbi CLK_PORT, CLK_PIN
    cbi CLK_PORT, CLK_PIN
    dec r18
    brne shift_digits
 
    ; 5. Pulse Latch (RCLK) to update the output displays
    sbi LAT_PORT, LAT_PIN
    cbi LAT_PORT, LAT_PIN
 
    pop zh
    pop zl
    pop r18
    pop r17
    pop r16
    ret
 
; ---------------------------------------------------------
; Data stored in Program Memory (Flash)
; ---------------------------------------------------------
.section .progmem.data, "a", @progbits
 
; Common Anode 7-segment masks (Active LOW)
; Segments:     DP,g,f,e,d,c,b,a (Bit 7 -> Bit 0)
; Indices:       0     1     2     3     4     5     6     7     8     9
segment_masks:
    .byte      0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90
 
; Digit select masks (Assuming active high on QA-QD for digits 1-4)
digit_masks:
    .byte 0x01, 0x02, 0x04, 0x08

Communication

Devices (laboratory nodes) are interconnected in pairs, so it is possible to work in groups and implement scenarios involving more than one device:

  • node 1 with node 2,
  • node 3 with node 4,
  • node 5 with node 6,
  • node 7 with node 8,
  • node 9 with node 10.

Interconnections are symmetrical, so that device 1 can send data to device 2 and vice versa (similar to serial communication). Note that analogue inputs are also involved in the interconnection interface. See image 3 for details.

Figure 3: SUT AVR nodes interconnection diagram

The in-series resistors protect the Arduino boards' outputs from excessive current when both pins are configured as outputs with opposite logic states.

The capacitors on the analogue lines filter the PWM signal, providing a stable voltage for the analogue-to-digital converter to measure.

Table 2: AVR (Arduino Uno) SUT Node Interconnections
Arduino Uno pin name AVR pin name Alternate function Comment
D2 PD2 INT0 Interrupt input
D5 PD5 T1 Timer/counter input
D6 PD6 OC0A PWM output to generate analogue voltage
D9 PB1 OC1A Digital output / Timer output
D10 PB2 OC1B Digital output / Timer output
A5 PC5 ADC5 Analogue input

Such a connection makes it possible to implement a variety of scenarios:

  • Connection of OC0A to ADC5 allows you to generate a voltage for measuring on input 5 of the analogue-to-digital converter.
  • Connection of OC1A to INT0 allows you to generate a digital periodic signal that can trigger hardware interrupts.
  • Connection of OC1B to T1 allows you to generate a digital periodic signal, the pulse count of which can be counted using timer T1.
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.
en/multiasm/exercisesbook/avr/sut.1777474368.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