The following is a PicoBlaze program in psm format that com
: The following is a PicoBlaze program in psm format that computes seconds, minutes and hours and display them on six seven segments. Do the followings:
Change the program to speed up 10 times faster (for example, display seconds in 0.1 of a second rate).
Display in Hex rather than in Decimal.
The Port_id for the sec, min, and hour must be 4, 8, and 16, respectively.
;Program operation: Time
;
constant sec, 04
constant min, 08
constant hour, 10
;------------I/O port definitions--
constant sw0, 00 ; sw0
constant seg0, 00 ; seg[7:0]
constant seg1, 01 ; seg[15:8]
constant seg2, 02 ; seg[23:16]
; Register alias
;commonly used local variables
namereg s9, data
namereg sa, addr
namereg sb, i
; Main program
call init
GO:
call swx
call time1
jump GO
;
init:
;clear memory
load i, 40
load data, 00
clr_mem_loop:
store data, (i)
sub i, 01
jump nz, clr_mem_loop
return
;
swx:
input sc, sw0 ;get flag
test sc, 01 ;check sw0
jump z, swx ;flag not set
call init
return
;
time1:
fetch s6, sec ; 00 is fetched first
fetch s7, min ; 00 is fetched first
fetch s8, hour ; 00 is fetched first
hours:
minute:
second:
call delay_hs
call delay_hs
call disp_led ;output to led after each second
add s6, 01 ; increment seconds
load se, s6
and se, 0f
compare se, 0a
jump c, jmp1
add s6, 06
jmp1:
store s6, sec ; store seconds
compare s6, 60 ;
jump nz, second ; less than 60
load s6, 00
store s6, sec
; a minite is done
add s7, 01 ; increment minutes
load se, s7
and se, 0f
compare se, 0a
jump c, jmp2
add s7, 06
jmp2:
store s7, min ; store minutes
compare s7, 60 ;
jump nz, minute ; less than 60
load s7, 00
store s7, min
; an hour is done
add s8, 01 ; increment hours
load se, s8
and se, 0f
compare se, 0a
jump c, jmp3
add s8, 06
jmp3:
store s8, hour ; store hours
compare s8, 24 ;
jump nz, hours ; less than 24
load s8, 00
store s8, hour
; 24 hours is done
return
;
disp_led:
fetch data, sec
output data, 00
fetch data, min
output data, 01
fetch data, hour
output data, 02
return
;
delay_10us: LOAD s0, EB
wait_10us: SUB s0, 01
JUMP NZ, wait_10us
RETURN
;
delay_2ms: LOAD s1, C8
wait_2ms: CALL delay_10us
SUB s1, 01
JUMP NZ, wait_2ms
RETURN
delay_hs: LOAD s2, FA
wait_hs: CALL delay_2ms
SUB s2, 01
JUMP NZ, wait_hs
RETURN
Solution
This is the dealy function that gives 0.5s of dealy :
delay_hs: LOAD s2, FA
wait_hs: CALL delay_2ms
SUB s2, 01
JUMP NZ, wait_hs
RETURN
This function is called twice to generate 1 sec delay. If you want to speed up the clock to 0.1s i.e 100 ms, then the delay_hs module should produce 50 ms delay. Therefore, it must call delay_2ms (i,e function for 2 ms delay) only 25 times. To do so, the delay_hs module is changed as follows. Rest of the program is same.
delay_hs: LOAD s2, 19 // Now load 0x19 i.e 25 into register s2 instead of 0xFA (250). This calls // wait_2ms only 25 times as opposed to 250 times. Rest is same.




