How to draw/depict event sequences? - Page 1
Forum section: electronics / general

author: wek
author_rank: Frequent Contributor
timestamp: March 19, 2023, 08:44:06 pm
content: 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 thesehorizontally, where one quickly runs out of "paper" for longer sequences, orvertically, which is perhaps a bit less natural.Please, comment, recommend.Thanks,JW

author: jpanhalt
author_rank: Super Contributor
timestamp: March 19, 2023, 08:47:14 pm
content: 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.)

author: SiliconWizard
author_rank: Super Contributor
timestamp: March 19, 2023, 09:01:05 pm
content: 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.htmlProbably 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.

author: Benta
author_rank: Super Contributor
timestamp: March 19, 2023, 10:59:42 pm
content: For basics, search for:State diagramMealy machine

author: WattsThat
author_rank: Frequent Contributor
timestamp: March 20, 2023, 06:20:20 am
content: 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.

author: wek
author_rank: Frequent Contributor
timestamp: March 20, 2023, 07:05:16 am
content: Thanks all for comments. It confirmed my suspicion: this is hard and there's no good solution out there.I tried to play withhttps://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.Thisis 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:CNT acting-CCR1 buffer-CCR11999 2001 2001 acting-CCR1 and buffer-CCR1 fromprevious DMA transfers2000 2001 2001 CNT==ARR => update event,at the same time CC1 event(because CCR1>ARR)=> request towards DMA0 2001 2001 buffer-CCR1 was transferred toacting-CCR1 because of Update(because CCMR1.OC1PE=1)1...5 2001 1200 it took some time for DMA to betriggered and perform transfer- maybe not 5 timer ticks, butlets say this is a good roughestimate - so buffer-CCR1 nowholds the new value DMA movedfrom the array in memory...1999 2001 12002000 2001 1200 CNT==ARR => update event,at the same time CC1 event(because CCR1>ARR)=> request towards DMA0 1200 1200 buffer-CCR1 transferred toacting-CCR11 1200 1200...5 1200 first 1500 DMA transferred the first 1500...1190 1200 first 15001200 1200 first 1500 CC1 event => request towards DMA...1205 1200 second 1500 DMA transferred the second 1500-- note, that the first 1500 isat this point overwritten withouthaving been used...2000 1200 second 1500 CNT==ARR => update event0 second 1500 second 1500 buffer-CCR1 transferredto acting-CCR1etc. - in this period, pulse is output at 1500 as expected,but there were two DMA transfers in the previous periodthus one value (the "first 1500") was already "lost",which is exactly what was observedUsing Update for DMA triggering, instead of CC1, ensuresthat 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

author: newbrain
author_rank: Super Contributor
timestamp: March 20, 2023, 09:46:29 am
content: Some of theUML defined diagramsmight be helpful.For drawing UML based diagrams,PlantUMLis 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 isWaveDrom, a VS Code extension exists for this too.

author: eutectique
author_rank: Frequent Contributor
timestamp: March 20, 2023, 09:55:14 am
content: PlantUMLcould 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.

author: wek
author_rank: Frequent Contributor
timestamp: March 20, 2023, 10:45:21 am
content: Thanks for the further comments.> WaveDromI 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 diagramsI 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.> PlantUMLOh, 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 syntaxQuotei.e. line starting with ampersand won't "CRLF". Okay, so I went back tohttps://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, aparallelkeyword! :-)So maybe these will turn out to be usable for this purpose.Thanks, again.JW

author: nctnico
author_rank: Super Contributor
timestamp: March 20, 2023, 11:01:38 am
content: Quote from: WattsThat on March 20, 2023, 06:20:20 amNot 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.

author: paulca
author_rank: Super Contributor
timestamp: March 21, 2023, 10:33:05 am
content: 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 withhttps://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_DiagramDo NOT go down the UML modelling rabbit hole. Just the diagram high level structure would be enough.

author: rstofer
author_rank: Super Contributor
timestamp: March 21, 2023, 02:09:18 pm
content: Included is the state machine diagram/https://people.cs.georgetown.edu/~squier/Teaching/HardwareFundamentals/LC3-trunk/docs/LC3-uArch-PPappendC.pdfThis is the way I have seen these diagrams done but I don't know what tool is being used.

author: zilp
author_rank: Frequent Contributor
timestamp: March 21, 2023, 02:26:37 pm
content: 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.

author: paulca
author_rank: Super Contributor
timestamp: March 21, 2023, 06:06:32 pm
content: 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.

author: paulca
author_rank: Super Contributor
timestamp: March 21, 2023, 06:10:15 pm
content: 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.

author: wek
author_rank: Frequent Contributor
timestamp: March 22, 2023, 10:19:27 am
content: 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:a, f, k, t, y -- when CNT==ARR, CNT is zeroed and UPdate event is generatedd, i, n, u, z -- UPdate event causes the value from buffer-CCR1to be transferred into acting-CCR1b, g, l -- if acting-CCR1>ARR, Compare (CC1) event is generated at UPdateq, v -- if acting-CCR1<=ARR (as is usual), CC1 event is generatedwhen CNT==acting_CCR1c, 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 frommemory to buffer-CCR1, here we used as an example 5 timer-cyclese, j, o, s, x -- DMA transfers value from buffer in RAM into buffer-CCR1and 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 pulsein the observed pulsetrain. The value 1500 from memory buffer position 8 (markedas 1500 ) gets overwritten in the buffer-CCR1 by the next value (1500 )before UPdate, i.e. it never contributes to pulse generation, so betweenthe 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 valuewon't be used in this particular period, but in the next period (after the nextUPdate event transfers this value from buffer-CCRx into acting-CCR).

author: SiliconWizard
author_rank: Super Contributor
timestamp: March 22, 2023, 08:07:58 pm
content: Wavedrom is a nice tool.