; TITLE count up and down, 1 to 4 to 1. ; ; count from 0-6 then repeat. DEFMOD count( rc, ic[0:2], oc[0:2] ) CHIP Inel_arch PIN ic[0:2] PIN oc[0:2] PIN rc T_TAB ( rc ic2 ic1 ic0 >> oc2 oc1 oc0 ) 1 x x x : 0 1 1; reset to 2 (which displays 3) 0 0 0 0 : 0 0 1 0 0 0 1 : 0 1 0 0 0 1 0 : 0 1 1 0 0 1 1 : 1 0 0 0 1 0 0 : 1 0 1 0 1 0 1 : 1 1 0 0 1 1 0 : 0 0 0 ENDMOD ; Offset/up down Module ; Convert 0-6 to 1-4-1 ; Sequence: 1,2,3,4,3,2,1,... ; DEFMOD translate( rt, it[0:2], ot[0:2] ) CHIP Intel_arch PIN it[0:2] ; current value of the sequence PIN ot[0:2] ; next value of the sequence PIN rt T_TAB (rt it2 it1 it0 >> ot2 ot1 ot0) 1 x x x : 0 1 1 0 0 0 0 : 0 0 1 0 0 0 1 : 0 1 0 0 0 1 0 : 0 1 1 0 0 1 1 : 1 0 0 0 1 0 0 : 0 1 1 0 1 0 1 : 0 1 0 0 1 1 0 : 0 0 1 ENDMOD CHIP FUN_SEQ NFX780_84 ; INPUTS PIN 47 clock ; Clock input on pin 77 PIN 48 reset ; Counter Reset Flag ; OUTPUTS ; +---s6---+ PIN 34 s0 ; | | PIN 35 s1 ; s5 s4 PIN 36 s2 ; | | PIN 37 s3 ; +---s3---+ PIN 39 s4 ; | | PIN 40 s5 ; s2 s1 PIN 41 s6 ; | | ; +---s0---+ PIN sequence[0:2] ; the output of translate ;PIN next[0:2] ; a local register? PIN count[0:2] ; input to counter PIN next_count[0:2] ; output from counter, input to translate ; UNUSED PINS PIN [49:51] unused[0:2] PIN [77:78] unused[3:4] ; Move to the next value of the sequence on the negative edge of the clock MODULE count( rc=reset, ic[0:2]=count[0:2], oc[0:2]=next_count[0:2] ) MODULE translate( rt=reset, it[0:2]=next_count[0:2], ot[0:2]=sequence[0:2] ) EQUATIONS count[0:2] := next_count[0:2] ;new input to counter = last output from counter count[0:2].ACLK = /clock ; Display the current sequence value on the 7-seg display T_TAB ( sequence2 sequence1 sequence0 >> s0 s1 s2 s3 s4 s5 s6 ) 0 0 0 : 1 1 1 0 1 1 1 ; 0 0 0 1 : 0 1 0 0 1 0 0 ; 1 0 1 0 : 1 0 1 1 1 0 1 ; 2 0 1 1 : 1 1 0 1 1 0 1 ; 3 1 0 0 : 0 1 0 1 1 1 0 ; 4 1 0 1 : 1 1 0 1 0 1 1 ; 5 1 1 0 : 1 1 1 1 0 1 1 ; 6 1 1 1 : 0 1 0 0 1 0 1 ; 7 SIMULATION VECTOR in_a := [ reset, count2, count1, count0 ] VECTOR seg_display := [s0, s1, s2, s3, s4, s5, s6] TRACE_ON in_a comp seg_display FOR i:=0 TO 15 DO BEGIN SETF in_a := i END