Author Topic: How to draw/depict event sequences?  (Read 1361 times)

0 Members and 1 Guest are viewing this topic.

Offline wekTopic starter

  • Frequent Contributor
  • **
  • Posts: 476
  • Country: sk
How to draw/depict event sequences?
« on: March 19, 2023, 08:44:06 pm »
I am trying to describe seuqences of events in mcus, but I am fighting with finding the proper format and tool. It always ends up as an entangled mess of registers values, timing marks, arrows depicting events and their consequences, and some explanatory text.

I don't even know if it's better to draw these horizontally, where one quickly runs out of "paper" for longer sequences, or vertically, which is perhaps a bit less natural.

Please, comment, recommend.

Thanks,

JW
 

Offline jpanhalt

  • Super Contributor
  • ***
  • Posts: 3378
  • Country: us
Re: How to draw/depict event sequences?
« Reply #1 on: March 19, 2023, 08:47:14 pm »
 I don't quite understand your issue.  Most MCU's are sequential processors.  Can you post a flowchart of what  you describe? (Timers are an exception.)
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14230
  • Country: fr
Re: How to draw/depict event sequences?
« Reply #2 on: March 19, 2023, 09:01:05 pm »
What you describe sounds like you just need sequence diagrams, which is a classic type of diagrams.
There is an online editor which you can try: https://sequencediagram.org/
You can also have a look at Mermaid, which can render various types of diagrams including sequence diagrams: https://mermaid.js.org/syntax/sequenceDiagram.html
Probably a bunch of other tools, all you have to look for is "sequence diagrams" really.

As you can see, the most common way of displaying a sequence diagram is to lay out the sequence itself vertically.

 
The following users thanked this post: tellurium

Offline Benta

  • Super Contributor
  • ***
  • Posts: 5817
  • Country: de
Re: How to draw/depict event sequences?
« Reply #3 on: March 19, 2023, 10:59:42 pm »
For basics, search for:
State diagram
Mealy machine
 

Offline WattsThat

  • Frequent Contributor
  • **
  • Posts: 763
  • Country: us
Re: How to draw/depict event sequences?
« Reply #4 on: March 20, 2023, 06:20:20 am »
Isn’t there an ISO standard for how to draw state charts? I believe Visio and other graphic drawing tools provide a library of symbols.
 

Offline wekTopic starter

  • Frequent Contributor
  • **
  • Posts: 476
  • Country: sk
Re: How to draw/depict event sequences?
« Reply #5 on: March 20, 2023, 07:05:16 am »
Thanks all for comments. It confirmed my suspicion: this is hard and there's no good solution out there.

I tried to play with https://sequencediagram.org/, thanks for the link. Impressive for an online and free tool. It has a fundamental flaw in that it does not allow multiple "boxes" at one row, i.e. can't depict simultaneous state changes appropriately.

What I'm trying to display is fundamentally a change of several registers (state holders) in time with internal (stemming from combinations of those registers) and external signals resulting in those registers changing their states. This is parallel, so state diagrams/flowcharts don't really cut it - it's the same problem as the hardware description languages (Verilog, VHDL) - they hide the parallelism which I'd like to highlight. One additional issue is, that time does not necessarily flow linearly - think of waiting for an external signal, or for lengthy increments of a timer until some value is reached.

Horizontal displays are more natural, as we usually imagine time flowing from left to right and most timing graphs are depicted in that way, but the descriptions of events rendered horizontally tend to "cross time domains" while rendered vertically are essentially unreadable.

Vertical displays are just unnatural. The advantage of "more natural scrolling direction" quickly disappears as soon as they get wider than "paper width". And in this case they do. This is my latest attempt (which prompted me to make this post/request), primarily "layed out" in an exceloid (LO's Calc) but then text-edited (adding breaks) to match the horizontal limitation of the code box available over there:
Code: [Select]
    CNT           acting-CCR1   buffer-CCR1   
    1999          2001          2001          acting-CCR1 and buffer-CCR1 from
                                              previous DMA transfers
    2000          2001          2001          CNT==ARR => update event,
                                              at the same time CC1 event
                                              (because CCR1>ARR)
                                              => request towards DMA
    0             2001          2001          buffer-CCR1 was transferred to
                                              acting-CCR1 because of Update
                                              (because CCMR1.OC1PE=1)
    1                                         
    ...                                       
    5             2001          1200          it took some time for DMA to be
                                              triggered and perform transfer
                                              - maybe not 5 timer ticks, but
                                              lets say this is a good rough
                                              estimate -  so buffer-CCR1 now
                                              holds the new value DMA moved
                                              from the array in memory
    ...                                       
    1999          2001          1200         
    2000          2001          1200          CNT==ARR => update event,
                                              at the same time CC1 event
                                              (because CCR1>ARR)
                                              => request towards DMA
    0             1200          1200          buffer-CCR1 transferred to
                                              acting-CCR1
    1             1200          1200         
    ...                                       
    5             1200          first 1500    DMA transferred the first 1500
    ...                                       
    1190          1200          first 1500   
    1200          1200          first 1500    CC1 event => request towards DMA
    ...                                       
    1205          1200          second 1500   DMA transferred the second 1500
                                              -- note, that the first 1500 is
                                              at this point overwritten without
                                              having been used
    ...                                       
    2000          1200          second 1500   CNT==ARR => update event
    0             second 1500   second 1500   buffer-CCR1 transferred
                                              to acting-CCR1
     
    etc. - in this period, pulse is output at 1500 as expected,
    but there were two DMA transfers in the previous period
    thus one value (the "first 1500") was already "lost",
    which is exactly what was observed
     
    Using Update for DMA triggering, instead of CC1, ensures
    that there is exactly one DMA transfer each period,
    avoiding this problem.



Both horizontal and vertical layout fundamentally suffer from clutter, as there are typically many "players" in such games, and "messages" stem from combinations of those players and go across the whole playfield. Explanations of some of the events (i.e. "annotation" of "messages") tend to be lengthy, which adds to the clutter.

I also don't have time etc. to learn to use something more complicated just to make these things nice (see the hand drawing in the horizontal example in opening post - ugly but quick - this was IIRC the third or fourth attempt. It still lacks one fundamental description - that the "cross" indicating failure of TR's shadow copy (roughly middle of timeline) was because of TR lock is high at that moment - it's in the accompanying narrative but still).

Maybe I'd need something dynamic, rather than a static picture/textual description. Maybe something like a LA (or mixed scope/LA) display, with annotations, and zoomable/scrollable/rotatable. It's the 21th century, after all.

JW
« Last Edit: March 20, 2023, 07:10:14 am by wek »
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1706
  • Country: se
Re: How to draw/depict event sequences?
« Reply #6 on: March 20, 2023, 09:46:29 am »
Some of the UML defined diagrams might be helpful.

For drawing UML based diagrams, PlantUML is probably the most widely used language, very well supported by a VS Code extension with live preview, syntax highlight, formatting etc..

For timing diagrams, an alternative to PlantUML is WaveDrom, a VS Code extension exists for this too.
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline eutectique

  • Frequent Contributor
  • **
  • Posts: 357
  • Country: be
Re: How to draw/depict event sequences?
« Reply #7 on: March 20, 2023, 09:55:14 am »
PlantUML could be a tool. It implements sequence and state diagrams (already suggested), and timing diagrams. Useful for documenting the design. CLion has a plugin, if that matters.

Though, it's drawback is lack of dynamism and interactiveness.
 

Offline wekTopic starter

  • Frequent Contributor
  • **
  • Posts: 476
  • Country: sk
Re: How to draw/depict event sequences?
« Reply #8 on: March 20, 2023, 10:45:21 am »
Thanks for the further comments.

> WaveDrom

I know that one and is impressive too; unfortunately a bit limited towards what I'd like to use it (i.e. no annotations, no cross-references)

> UML defined diagrams

I don't think so, although did not give more than a glimpse. Time (ticks) is a strong requirement for what I am talking about here.

> PlantUML

Oh, that looks much like sequencediagram mentioned previously. I went all the way to the bottom of the description mumbling that this can't do the multiple labels at the same row thing either - and lo and behold, the very last example contains something like that, with the following syntax
Quote
note left S1: msg\nS2 to S1
& note right S2: msg\nS1 to S2
i.e. line starting with ampersand won't "CRLF". Okay, so I went back to https://sequencediagram.org/ and tried this syntax, but it did not work. Then I went to the sequencediagram's info/help page, and this time went through it more carefully... and there it is, a parallel keyword! :-)

So maybe these will turn out to be usable for this purpose.

Thanks, again.

JW
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26682
  • Country: nl
    • NCT Developments
Re: How to draw/depict event sequences?
« Reply #9 on: March 20, 2023, 11:01:38 am »
Isn’t there an ISO standard for how to draw state charts? I believe Visio and other graphic drawing tools provide a library of symbols.
Not really. For simple statemachine I use circles with state transactions. For more complex statemachines I use SDL. For complex systems it helps to add a diagram that shows an overview of the flow through the various primary states (*) with only the major events.

* stable states where the system is doing something. Not the 'simple' states that transition from one state to the other after waiting for something to happen or a timeout.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 3989
  • Country: gb
Re: How to draw/depict event sequences?
« Reply #10 on: March 21, 2023, 10:33:05 am »
A diagram is a picture.

A model takes many pictures.

Don't try and put everything on one diagram.  Have a highlevel block system diagram and then for the complex state machine you can have a "full view" sans of all detail and then multiple sub diagrams which drill into the detail.

Just the same as schematics.

Don't get caught up in formal design tools.  Know your audience.  As long as the diagram communicates the concept well, it's good.

I'm not 100%, but I'm pretty sure I have used multiple "life cycle" boxes and possibly even nested life cycle blocks with https://sequencediagram.org/

Sequence diagrams are great, but do not handle "state" well.  State machine diagrams, state is a box, events and transitions are lines.  Beyond that most of the diagrams I am familiar with are entity relationship and object/class OOP modelling stuff.

https://training-course-material.com/training/UML_State_Machine_Diagram 
Do NOT go down the UML modelling rabbit hole.  Just the diagram high level structure would be enough.
« Last Edit: March 21, 2023, 10:38:07 am by paulca »
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9885
  • Country: us
Re: How to draw/depict event sequences?
« Reply #11 on: March 21, 2023, 02:09:18 pm »
Included is the state machine diagram

/https://people.cs.georgetown.edu/~squier/Teaching/HardwareFundamentals/LC3-trunk/docs/LC3-uArch-PPappendC.pdf

This is the way I have seen these diagrams done but I don't know what tool is being used.
 

Offline zilp

  • Regular Contributor
  • *
  • Posts: 182
  • Country: de
Re: How to draw/depict event sequences?
« Reply #12 on: March 21, 2023, 02:26:37 pm »
I am not entirely sure what exactly it is that you are trying to achieve, but as you among other things said that you need to represent simultaneous events and that that supposedly can be difficult in sequence diagrams, may I suggest that your own conceptualization of what you are trying to draw might be confusing you?

The whole point of sequence diagrams is that all state changes in between messages are conceptually simultaneous (i.e., atomic), while at the same time simultaneity between time lines just isn't a thing, because all synchronization is represented by the messages in the diagram, and those are only causal relationships. The purpose of sequence diagrams is to represent interactions in a distributed system, i.e., between components that operate asynchronously, so that's how you have to split up your system to meaningfully represent it in a sequence diagram.

Now, I am getting the impression that you maybe want to explain race conditions somehow, i.e., how the indeterminacy of the ordering of message delivery can influence system behaviour? In that case it might be useful to just draw multiple arrows for the possible delivery orderings, or possibly multiple instances of the diagram showing the possible orderings? However, in principle the concurrency of anything that isn't causally related is already implied by the diagram. But, well, I am mostly guessing here.

As for tools for drawing diagrams with a lot of control over details, you might want to have a look at PGF/TikZ.

 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 3989
  • Country: gb
Re: How to draw/depict event sequences?
« Reply #13 on: March 21, 2023, 06:06:32 pm »
Simultaneous (aka concurrent) state machines use different types of diagrams.  Last time I did that shit (interoperability state machines) was in Uni many moons ago in Jean Bacon's book.
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 3989
  • Country: gb
Re: How to draw/depict event sequences?
« Reply #14 on: March 21, 2023, 06:10:15 pm »
I would say... again... divide.  Divide the aspects you are trying to show into multiple diagrams.  A diagram showing snapshots of state is fine.  You just need quite a few at times.  I tend to have a happy path for each scenario and a set of example corners cases.  Sequences and State diagrams for each "Thread" and one showing the 'basics' of how they sync as a separate diagram.

The idea of a diagam, nor a model , is to capture everything.  It's just a conceptual tool to aid communication and development.
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline wekTopic starter

  • Frequent Contributor
  • **
  • Posts: 476
  • Country: sk
Re: How to draw/depict event sequences?
« Reply #15 on: March 22, 2023, 10:19:27 am »
Turns out, it pays out to read documentation to the end... Wavedrom does have "arrows" to denote causal relationships.

OTOH, whether the result is more illustrative than the textual version above, is questionable... it also took me considerably more time to generate it.

JW

[picture would come here, but embedding pictures doesn't work for me, sorry, please click on the thumbnail]

Code: [Select]
a, f, k, t, y -- when CNT==ARR, CNT is zeroed and UPdate event is generated
d, i, n, u, z -- UPdate event causes the value from buffer-CCR1
  to be transferred into acting-CCR1
b, g, l -- if acting-CCR1>ARR, Compare (CC1) event is generated at UPdate
q, v -- if acting-CCR1<=ARR (as is usual), CC1 event is generated
  when CNT==acting_CCR1
c, h, m, r, w -- DMA is set so that it is triggered by the CC1 event;
  it takes some time until DMA fulfills the request by transferring data from
  memory to buffer-CCR1, here we used as an example 5 timer-cycles
e, j, o, s, x -- DMA transfers value from buffer in RAM into buffer-CCR1
  and increments the pointer into memory (DMA_MAR)

Note, that in the period between k and t there are two DMA transfers. This means,
that there's one less timer period than total DMA transfers, thus one less pulse
in the observed pulsetrain. The value 1500 from memory buffer position 8 (marked
as 1500 [1]) gets overwritten in the buffer-CCR1 by the next value (1500 [2])
before UPdate, i.e. it never contributes to pulse generation, so between
the 1200- and 500-pulse there are only two 1500-pulses, instead of three.

Remedy is simple, for PWM, perform the DMA-to-CCRx transfer upon UPdate event,
not upon the CCRx event. In that way, there's exactly one transfer per period.
CCRx buffering ensures that whatever the DMA transfer delay is, the new value
won't be used in this particular period, but in the next period (after the next
UPdate event transfers this value from buffer-CCRx into acting-CCR).
« Last Edit: March 22, 2023, 10:23:14 am by wek »
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14230
  • Country: fr
Re: How to draw/depict event sequences?
« Reply #16 on: March 22, 2023, 08:07:58 pm »
Wavedrom is a nice tool.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf