How to simulate 0.5Hz clock in Timing-diagram

0 votes
asked Feb 15 in Question / help by PackElend (120 points)

Hello,

how can I create cloack using floating numbers? For example a 0.5Hz clock.

clock  clk with period 0.5

throws an error.

Faking a clock using a binary signal in the preprocessor is not working either as %string(...) can convert integers or strings to string form — but it cannot evaluate or stringify a non‑integer expression.
See the code below. 

@startuml


binary "CLK" as CLK

!$t     = 0
!$state = 0
!$max   = 8

!while $t <= $max
  @%string($t)
  !if $state == 0
    CLK is low
    !$state = 1
  !else
    CLK is high
    !$state = 0
  !endif
  !$t = $t + 1
!endwhile


@enduml

1 Answer

+1 vote
answered Feb 15 by The-Lu (88,340 points)

Hello P.,

Here is a proposal, for a workaround:

@startuml
clock clk with period 1
binary "CLK" as CLK

!$t     = 0
!$state = 0
!$max   = 8

!while $t <= $max

  @%string($t)
  CLK is high
  @%string($t.25)
  CLK is low
  @%string($t.5)
  CLK is high
  @%string($t.75)
  CLK is low
  
  !$t = $t + 1
!endwhile

@enduml

Enjoy,

Regards,
Th.

commented Feb 15 by PackElend (120 points)
edited Feb 15 by PackElend

great and thx for the quick answer

should it possible to use floating for period defination fo a clock (+defining the pattern for the horizontal lines) ?

 

...