0 evaluări0% au considerat acest document util (0 voturi)
62 vizualizări9 pagini
This document is a lab report for an electrical engineering course on microcontroller systems design. It details an experiment using assembly language to program different delay methods on a SLK-PB microcontroller using CodeWarrior IDE. The methods tested were software delays using loops, polling delays by checking a flag, and interrupt delays. The document includes the theoretical design, synthesized code design with subroutines for initialization, delay functions, and a main routine to test the different modes. It also provides sample calculations for setting delay values.
This document is a lab report for an electrical engineering course on microcontroller systems design. It details an experiment using assembly language to program different delay methods on a SLK-PB microcontroller using CodeWarrior IDE. The methods tested were software delays using loops, polling delays by checking a flag, and interrupt delays. The document includes the theoretical design, synthesized code design with subroutines for initialization, delay functions, and a main routine to test the different modes. It also provides sample calculations for setting delay values.
This document is a lab report for an electrical engineering course on microcontroller systems design. It details an experiment using assembly language to program different delay methods on a SLK-PB microcontroller using CodeWarrior IDE. The methods tested were software delays using loops, polling delays by checking a flag, and interrupt delays. The document includes the theoretical design, synthesized code design with subroutines for initialization, delay functions, and a main routine to test the different modes. It also provides sample calculations for setting delay values.
EEL-4746L Microcontroller Based Systems Design Laboratory Report
Jigar Patel Page 3 of 9
1. Introduction The purpose of this lab was to give student knowledge on the use of Assembly programming language to implement delays using the different methods. The methods introduced in this lab to create delays were as follows: I. Software Delays II. Polling Delays III. Interrupt Delays 2. Requirements
3. Theoretical Design
/
SW [1:0] 4-bit HEX Counter 00
01
10 Hold Mode Count with Software Delay Count with Polling Hex to LED Display LED 1 LED 2 LED 3 LED 4 SLK PB LEDS LED 2 LED 1 A p p l i c a t i o n
B o a r d
L E D S
EEL-4746L Microcontroller Based Systems Design Laboratory Report
Jigar Patel Page 4 of 9
4. Synthesized Design ; export symbols XDEF Entry, _Startup ; export 'Entry' symbol ABSENTRY Entry ; for absolute assembly: mark this as application entry point
; Include derivative-specific definitions INCLUDE 'derivative.inc'
ROMStart EQU $4000 ; absolute address to place my code/constant data ;**************************************************** ; Enter your equates here ;**************************************************** EOS EQU $00 PACONF EQU %00001111 ;conf bits 0:3 (active low) PBCONF EQU %00110000 ;conf bit 4:5 (active high) BIT7 EQU %10000000 BIT6 EQU %01000000 BIT5 EQU %00100000 BIT4 EQU %00010000 BIT3 EQU %00001000 BIT2 EQU %00000100 BIT1 EQU %00000010 BIT0 EQU %00000001 ; variable/data section
ORG RAMStart ;********************************************* ; Place your variables here ;********************************************** SW1 DC.B 1 SW2 DC.B 1 Count DC.B 2 value DC.B 1 ;Count_Seq DC.B $1,$3,$5,$9,$B,$D,$F,$0 ; code section ORG ROMStart
;***************************************************** ; Enter your constants here ;****************************************************** PUCRCONF EQU BIT0 ;conf bit 0 of PUCR DDRPCONF EQU PBCONF ;conf bit 4:5 of DDRP POLL_CONF EQU %00000000 ;interrupt off prescale at 1 INT_CONF EQU BIT7 ;Use these values to get the specified software delay: ;*~~~* N =M *~~~* ;Delay =(60sec)/(Count) ;LED Delay =(Delay / (Sequence #s) ;N Value =sqrt{[(2E6)(LED Delay)] / 3} ;******************************************** ;| Count | Delay | LED Delay | N Val. | ;| 03 | 20s | 02.50s | 1291 | ;| 06 | 10s | 01.25s | 912.87 | ;| 12 | 05s | 0.625s | 645.49 | EEL-4746L Microcontroller Based Systems Design Laboratory Report
Jigar Patel Page 5 of 9
;| 18 | ~3s | 0.417s | 527.05 | ;******************************************** SOFT_1 EQU 1291 ;correct number to get 60 sec delay N=M=6324 SOFT_2 EQU SOFT_1 ;Use these values to get the specified polling delay: ;******************************************** ;| Count | Delay | LED Delay | N Val. | ;| 03 | 20s | 02.50s | 76.294 | ;| 06 | 10s | 01.25s | 38.147 | ;| 12 | 05s | 0.625s | 19.073 | ;| 18 | ~3s | 0.417s | 12.716 | ;******************************************** POLL_CNT EQU 76 ;correct number to get 60 sec delay N=M=6324 INT_CNT EQU POLL_CNT ;use the correct set of declarations based on the ;intput or output in lab
;***************************************************** ; Place Timer ISR here ;***************************************************** TIMER_ISR: SEI DEC Count ; Fixed global variable BNE Reset ; Time has not expired yet J SR Update_Counter ; Delay time has expired, Update Display LDAA #INT_CNT STAA Count ; Reset Counter for next time interrupt occurs BCLR TSCR2,BIT7 BRA Return1 Reset: LDAA #BIT7 STAA TFLG2 ; Reset TOF flag BSET TFLG2,BIT7 CLI Return1: RTI ; Need to Return from interrupt
;***************************************************** ; Place your subroutines here ;***************************************************** Init_IO: CLRB ; " STAB DDRA ; " BSET DDRA,PACONF ;sets bits 0:3 in DDRA CLRB STAB DDRB BSET DDRB,PBCONF ;sets bits 4:5 of DDRB BSET PUCR,PUCRCONF ;sets bit 0 of PUCR BSET DDRP,DDRPCONF ;sets bits 4:5 of DDRP RTS ;returns to main
Polling_Delay: PSHA ;saves counter to register PSHB LDX #POLL_CNT ;Need to wait POLL delay cycles L2: TST TFLG2 ;Tests TOF (Bit7 of T Flag) BPL L2 ;Branch to L2 if TOF =0 LDAB #BIT7 ;Reset TOF, need to write 1 in TFLG2 STAB TFLG2 DBNE X,L2 PULB PULA RTS
;****************************************************** ; Place your main routine here ;******************************************************* Entry: _Startup: LDS #RAMEnd+1 CLI J SR Init_IO ;calling subroutine INIT_IO CLRA ;initilize counter using register A LDY #Count_Seq J SR Update_Counter ;calls subroutine Update counter LDAA #INT_CNT STAA Count ; Set #of loops
EEL-4746L Microcontroller Based Systems Design Laboratory Report
Jigar Patel Page 7 of 9
Main: J SR Count_Reset BRSET PORTA,BIT7, Polling BRSET PORTA,BIT6, Software ;Hold Mode Hold: BCLR TSCR2,BIT7 ;disables interrupts BSET PORTB,BIT4 ;turns LED1 OFF on Application board BSET PORTB,BIT5 ;turns LED2 OFF on Application board J SR Count_Reset BRA Main ;Software Mode Software: BCLR TSCR2,BIT7 ;disables interrupts BCLR PORTB,BIT4 ;turns LED1 ON on Application board BSET PORTB,BIT5 ;turns LED2 OFF on Application board J SR Software_Delay J SR Update_Counter BRA Main ;Polling Mode Polling: BRSET PORTA,BIT6,Interrupt BCLR TSCR2,BIT7 ;disables interrupts BSET PORTB,BIT4 ;turns LED1 OFF on Application board BCLR PORTB,BIT5 ;turns LED2 OFF on Application board J SR Polling_Config J SR Polling_Delay ;calls subroutine J SR Update_Counter BRA Main
;Interrupt Mode ;Did not do this mode Spin: BRA Spin
EEL-4746L Microcontroller Based Systems Design Laboratory Report
Jigar Patel Page 8 of 9
6. Experimental Results
EEL-4746L Microcontroller Based Systems Design Laboratory Report
Jigar Patel Page 9 of 9
7. Summary
As seen above the lab was a success. The coding wasnt too bad with minor speed bumps on the way. Interrupt Mode was not done resulting in a fail for section 7. Section 6 however was working but it wasnt correctly done. The value does get reset but only after the delay loop has been exited. Meaning one has to hold PB4 down until count resets to first count due to the fact that the PB4 check wasnt in the delay loops. 8. Lessons Learned This lab was fairly easy a few things to watch out for were making sure that the checks for the switches were done in the correct spots, also knowing the LEDs and their orientation was important. i.e knowing which LEDs are active low and which ones are active high helped a lot. All in all an easy lab provided the pseudo code which was in the lab. The pseudo code was followed closely to obtain the results making it a fairly easy lab.