EE234_hw3_sol_24S

docx

School

Western Washington University *

*We aren’t endorsed by this school

Course

234

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

docx

Pages

4

Uploaded by zerogaming0723

Report
EE234 Homework 3 Name : 1. Write an instruction sequence to configure PA7 pin with the following characteristics: (a) input (b) enable slew rate limit (bit 7) (c) sense rising edge (bit 2 ~ bit 0) (d) set to bus keeper if it is configured for output (not for this problem) Solution: Bit 7: set to 1 Bit 6: set to 0 Bit 5~3: 001 for bus keeper Bit 2~0: 001 detect rising edge ldi r16, 0x80 sts PORTA_DIRCLR, r16; make PA7 pin an input ldi r16, 0x89 sts PORTA_PIN7CTRL, r16 2. Write an instruction sequence to configure PB6, PB2 pins with wired OR, sense falling edge, , disable slew rate limit, and configure them for output. Solution: Bit 7: 0 Bit 6: 0 Bit 5~3: 100 wired-OR for output Bit 2~0: 010 detect falling edge. ldi r16, 0x44 sts PORTB_DIRSET, r16 ; configure PB6 & PB2 for output. sts PORTCFG_MPCMASK, r16 ; configure pin 6 & 2 simultaneously. ldi r16, 0x22 sts PORTB_PIN2CTRL, r16 3. Write down the value to be written PORTC_OUT register to display 0, 1, …9 for the following circuit: Solution: 0: 0x3F 1: 0x06 2: 0x5B 3: 0x4F 4: 0x66 5: 0x6D 6: 0x7D 7: 0x07 8: 0x7F 1
9: 0x6F 4. Write a program to generate a staircase waveform (periodic, shown in Figure HW3.4) from the circuit shown in Figure 8.22. The subroutine delay1ms that generates 1 ms delay is available to you to call. Solution: The value to generate 1.1 V, 2.2 V, and 3.3 V output from V OUT A pin are N(1.1V) = 255 x 1.1 / 3.3 = 85 , N(2.2V) = 255 x 2.2 / 3.3 = 166 , N(3.3 V) = 255 x 3.3 / 3.3 = 255 , respectively. .include <atxmega128A1Udef.inc> .def lpCnt = r20 .equ NN = 3 2
.def temp = r21 .cseg .org 0x00 jmp start .org 0xF6 start: ldi temp, low (RAMEND) out CPU_SPL, temp ldi temp, high(RAMEND) out CPU_SPH, temp call setCPUClkto32Mwith32MIntOsc ser temp sts PORTA_DIR, temp sts PORTB_DIR, temp forever: ldi ZL, low(stair << 1) ldi ZH, high(stair << 1) ldi lpCnt, NN ldi temp, 0x02 sts PORTB_OUTCLR, r20 ; select channel A ldi temp, 0x01 sloop: sts PORTB_OUTCLR, temp ; enable write to AD7302 lpm r16, Z+ sts PORTA_OUT, r16 ; send a value to be converted. sts PORTB_OUTSET, temp ; start DAC. call delay1ms dec lpCnt brne sloop jmp forever stair: .db 85, 166, 255 5. Use PORTC pins PC5, PC4, PC3, PC2, PC1, and PC0 to drive green, yellow, red, green, yellow, and red LEDs, respectively. Write a program to simulate the traffic light controller. The light patterns and duration of east-west bound and south-north bound traffic light and duration are listed in the table HW3.5. The delayby100ms subroutine is available to you to call. The multiple is to be passed in r16 . 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Solution: .include <atxmega128A1Udef.inc> .def temp = r21 .def lpCnt = r20 .equ NN = 4 .cseg .org 0x00 jmp start .org 0xF6 start: ldi temp, low (RAMEND) out CPU_SPL, temp ldi temp, high(RAMEND) out CPU_SPH, temp call setCPUClkto32Mwith32MIntOsc ldi temp, 0x3F sts PORTC_DIR, temp ; configure PC5~PC0 for output forever: ldi lpCnt, NN ldi ZL, low (lightTab << 1) ldi ZH, high (lightTab << 1) loop: lpm temp, Z+ sts PORTC_OUT, temp lpm r16, Z+ call delayby100ms dec lpCnt brne loop jmp forever lightTab: .db 0x21, 250, 0x11, 50, 0x0C, 200, 0x0A, 40 4