Skip to content

Conversation

@lp6m
Copy link

@lp6m lp6m commented Apr 27, 2020

  • Add update interval option to stypes.Counter
    • add interval option argument to stypes._Accumulator and its derived class.
    • The expected value cannot be obtained by setting the update interval with nesting a counter with the enable argument of other counter.
main = vthread.Stream(m, 'main', clk, rst)
xcounter = main.Counter(initval=0, size=4) #0,1,2,3..
ycounter = main.Counter(initval=1, enable=(xcounter == 3))#0,0,0,0,1,1,1,1..

Step: 0 1 2 3 4 5 6 7
x   : x x 0 1 2 3 4 5
y   : x x x x 0 0 0 1 #we want four zero!

The processing of xcounter==3 takes 2 clock cycles, so counter y is reset at 3rd clock cycle, 2 cycles after the xcounter reset. And at 4th clock cycle, xcounter==3 holds, after two cycle, the value of y counter is updated to 1.

This update can define counter with interval as following.

cnt1 = strm.Counter()
cnt2 = strm.Counter(initval=1)
cnt3 = strm.Counter(initval=2, size=3)
cnt4 = strm.Counter(initval=3, interval=3)
cnt5 = strm.Counter(initval=4, interval=3, size=4)
cnt6 = strm.Counter(initval=4, step=2, interval=2)
step,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33
cnt1,x,x,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
cnt2,x,x,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32
cnt3,x,x,2,3,4,2,3,4,2,3,4,2,3,4,2,3,4,2,3,4,2,3,4,2,3,4,2,3,4,2,3,4,2,3
cnt4,x,x,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13
cnt5,x,x,4,4,4,5,5,5,6,6,6,7,7,7,4,4,4,5,5,5,6,6,6,7,7,7,4,4,4,5,5,5,6,6
cnt6,x,x,4,4,6,6,8,8,10,10,12,12,14,14,16,16,18,18,20,20,22,22,24,24,26,26,28,28,30,30,32,32,34,34
  • Fixed the problem that the counter initial value is 1 larger than the expected value when size is not specified.
    • the initial counter value with no option arguments is changed to zero. This modification was applied to some tests. c7a4d8a

@shtaxxx
Copy link
Member

shtaxxx commented Apr 27, 2020

Thank you very much for very nice suggestion and implementation!

@shtaxxx shtaxxx merged commit 7d37670 into PyHDI:develop Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants