Converting picaxe basic codes to a flowchart diagram

Pauldesign

Senior Member
Hi Guys

Is there a feature in the picaxe programming editor to convert a working picaxe basic code into flow charts block diagrams? if not is there any idea of how this can be somehow easily done.

Thanks
 

hippy

Technical Support
Staff member
It would be possible but it might not be entirely satisfactory. At best you'll get blocks within the flowchart, one per line of code with paths linking between the various parts. A sort of PCB 'rats nest' but for code rather than components.

The question has to be what you are hoping to achieve ? In most cases flowcharts are used in addition to source code to present an overview of what the program does rather than how and this would be very difficult to achieve automatically.
 

BeanieBots

Moderator
This is a very unusual thing to do!
What are you really trying to do?

When writing code, it is more normal to start with a flow diagram (even if it's just in your head) and then write the code from that.

The best way to reverse that is by going through the code methodically and break it down into decisions and functions. How easy that is to do depends a lot on how well it was written and how good the comments and symbol definitions are.

Consider the following code:
Code:
readADC10 1,w0
If w0 > 1234 then 
   high 1
   low 2
 else
  low 1
  high 2
endif
The best you can do is determine that if the voltage on input 1 is higher than a certain value that the logic states of ouptuts 1 and 2 are swapped over.

If however the (indentical) code was written like this:-
Code:
Symbol Trip_point = 1234
Symbol Temperature_Sensor = 1
Symbol Heater = 2
Symbol Cooler = 1
Symbol Temperature = w0

ReadADC Temperture_Sensor,Temperature
If Temperature > Trip_Point then
   High Cooler
   Low Heater
  Else
   Low Cooler
   High Heater
Endif
You can easily see what the code is doing even without any comments.
Any application attempting to make sense of code will have the same issues.
 

Pauldesign

Senior Member
I intend to use it to explain the operation of my code in a logical way during our end of year thesis presentation, so i'm avoiding from doing a manual flow diagram as it's too tedious to represent/illustrate a complex project.
 

Dippy

Moderator
Perhaps he has written a big dollop of code but wants a pretty flowchart for some documentation...?

If so then dig out your pen, ruler and paper Paul :)

Maybe there is some CAD type apps around for pretty flowcharts??

Edit: Ah, crossed post. My CBall is damned good huh?
 

techElder

Well-known member
I've used this program for the PC that does a fair job of creating flow charts. I used it recently to flow chart Hippy's 08M RTC routine. Flow charting in arrears does help with the understanding of a program, but it takes some time to create.

Diagram Designer by MeeSoft version 1.23.1

(Downloading at cnet.com)
 

hippy

Technical Support
Staff member
There are some products ( including free and shareware ) which can convert source code to flowcharts but I have never used them nor know how good they would be. It would likely entail having to provide some definition or template for the PICAXE Basic Language format so the tool knows what it is working with.

Most PC languages are block-structured and might not support GOTO so that could be an issue. Anything which can create flowcharts from assembly language might have an advantage over others.

A Google search on "automated flowcharting" and similar would be a good place to start. Will be interesting to see how you get on.
 

Pauldesign

Senior Member
Thanks for all the responses; i thought there was a feature in the programming editor to automate the process because at this point in time even a flowchart software as Texas suggested (not to talk of Dippy's old timer, old school 1930 military way :eek:; Kudos Dippy, that's a good method for obese people as they can use it to burn some fats ;) and that explains why most ancient people were slimmer before PC were invented:rolleyes:) is not an option to me as i started doing so with the flow chart feature in Microsoft office 2010 but have to quit.

I think, i'll better leave it off than to do it and do it sloppily and worse if the logic is wrong! as i'm not just doing 1 but 7 and in a rush.

Well, if flowcharts can be converted to basic codes if using the flowchart programming method, why not add a feature in picaxe programming editor to reverse the process. :D

Nevertheless, if i have time after my thesis, i'll investigate Hippy's latest suggestion and feedback.

Enjoy your weekend guys. I'm signing off.
 

Dippy

Moderator
"why not add a feature in picaxe programming editor to reverse the process"
- mmm.... 300 hours of coding time for one person who wants it?
Yup, that makes sense :rolleyes:

Alternatively, if you want to produce a really fancy thesis then some effort is required - by you.

Doing a basic flowchart with pen(cil) and paper is way faster than on a PC.
Try it.
Doing it neatly is another question of course... haha.
Anyway, if you haven't got time (aska CBA) to do a flowchart even with all the PC help then that would be a pity.
 

hippy

Technical Support
Staff member
Well, if flowcharts can be converted to basic codes if using the flowchart programming method, why not add a feature in picaxe programming editor to reverse the process. :D
It is possible, but the first pass result is a set of blocks, one per line of code, and a 'rats nest' of linking paths. It then needs similar auto-placement of blocks and auto-routing of paths as for doing PCB design. That's a reasonably complicated job and not only does it have to be right ( where auto-PCB design may perhaps stop ) but has to be humanly understandable ad capable of being followed linearly more than a PCB does.

On top of that you only get lines of code in a visual format which don't necessarily give any greater understanding. It needs editing if you want a functional rather than implementation description. It's debatable whether an automatically generated flowchart which needs editing is quicker to produce than manually creating flowcharts.

Most project designs would have high-level flowcharts ( and similar ) as part of the original design from which code is then derived so it's not usually necessary to have to work backwards.

My personal view is that such a tool doesn't really deliver, doesn't add much, is therefore not overly useful, has little market appeal, and falls under the category of a lot of work for little gain.

Don't get me wrong - I can understand where you are coming from. My very first job was taking yards of spaghetti assembly code and producing flowcharts of the program operation. It's also often the first thing one has to do when confronted with code you don't know to get a higher understanding. Having to do that soon reveals what the limitations of simplistic line of code to flowchart block translations would be.
 

BeanieBots

Moderator
I intend to use it to explain the operation of my code in a logical way during our end of year thesis presentation, so i'm avoiding from doing a manual flow diagram as it's too tedious to represent/illustrate a complex project.
Hmm.. absolutely the wrong way round.
A "complex" project should have STARTED with a flow diagram to demonstrate and explain (to the programmer, even if that's you) how the overall system works. How else can you code it?

A SIMPLE project often skips that process but even then it's a good idea as part of the documentation.

For my own projects I use pen, paper and sometimes a plastic stencil.
For formal projects I use microsoft's Visio but it takes much longer than pen & paper.

Well, if flowcharts can be converted to basic codes if using the flowchart programming method, why not add a feature in picaxe programming editor to reverse the process.
See the example I gave earlier.
How would a code-to-flow programme know what w0 for example represented.
Try it yourself.
What would the diagram look like for this code?

if b0 > b1 then goto label1
How would such a flow diagram convey any more inforamtion than the code?
 
Last edited:

papaof2

Senior Member
There were a couple of useful tools from Powerline software in the days of mostly DOS development -

Tree Diagrammer - which could generate a flow chart from C, BASIC, etc, etc, code to printer, screen, or file.

Source Print, which could print C, BASIC, etc, etc, code with keywords highlighted and proper indenting. You could also add keywords, so a new language or a new version of an existing language could be handled.

I expect these are no longer available (except used) but I still have both installed on an older PC (and I also probably have a 5.25" floppy drive somewhere ;-)

If there's a business need for a flowchart, PM me about setting up this old software to handle PICAXE BASIC. 8 to 10 hours of my time may be more than you want to invest.

John
 

Pauldesign

Senior Member
Thanks for all the replies:

Pen and paper is not an option because it's part of our curriculum that any drawings or illustrations must be computer done and not to talk of a thesis in this matter. Using a pen and paper is a shame and a guaranteed zero.
That is an option for a sketch work and not for evaluations purposes.

I understand that a flow chart (boring and time consuming) or state machine is needed first for complex projects but sometimes is easier especially with picaxe programming to code straight up and ii's also facilitates modifications and restructuring esp if new thoughts pops along. In science and engineering it's sometimes easier to think outside the box or solve a problem by working backwards and in my case that was the way to go Beaniebots.:)


I'm not trying to be rude but how will comments for a 20kbyte source code looks like on a power point presentation esp if you've to explain how a program in a functional block works.:rolleyes:

Nevertheless i was just curious if there exit such a feature similar to hardware design languages; where you can switch between different formats.

I'll drop the idea since it's somehow trivial. I just wanted to add it to spice things up and it wasn't a requirement to my thesis.

Thanks once more.:p
 

hippy

Technical Support
Staff member
Using a pen and paper is a shame and a guaranteed zero.
That's definitely a shame but I guess they get to set the rules.

These days it is easier to share documents electronically and being editable by computer is handy.

I've always taken the 'book publishing approach'; the author creates ( with whatever tools they want to use, including pen and paper ), the publisher / editor gets some poor sap to convert all that into the form they want. Of course, that poor sap is sometimes yourself so it's easier to start with the intention of what's ultimately required.

I'm not trying to be rude but how will comments for a 20kbyte source code looks like on a power point presentation esp if you've to explain how a program in a functional block works.:rolleyes:
I think it depends on what you need to explain. It's rare anyone is particularly interested in a line by line source code explanation but wants to see the overview, understand the big picture, then perhaps those overview blocks broken down into some more detail. The occasional snippets of code may be included but only where it helps demonstrate a particular trick described.

For example you could describe PICAXE programming as a list or sequence of flowchart blocks -

1) Open Programming Editor or AXEpad
2) Type source code
3) Click on Syntax Check
4) Any Errors : No - Continue, Yes - Edit code, back to (3)
5) Click on Program
6) Did it download okay : Yes, Continue, No - Fix problem, back to (5)
7) Test downloaded program
8) Does it work as expected : Yes : Continue, No - Edit Code, back to (3)
9) Go "YeeHaa!", take an early lunch

You can break any one of those down into much greater detail, but not all of it has to be broken down further. It really depends on what the audience is most interested in.

It may be worthwhile talking to your tutor or having a look at some thesises (thesi?) published on the internet.
 

BeanieBots

Moderator
I'm not trying to be rude but how will comments for a 20kbyte source code looks like on a power point presentation esp if you've to explain how a program in a functional block works.
I think you missed my point.
How will any automated method of creating a flow diagram generate anything that makes any sense without knowing variable and label names?

Have another look at the two examples I posted then (without ANY prior knowledge) produce the two simple flow diagrams (by hand) and see what you end up with.

also, which PICAXE are you downloading 20k of code into?
 

Pauldesign

Senior Member
How will any automated method of creating a flow diagram generate anything that makes any sense without knowing variable and label names?
I've not got time to experiment at the moment but it seems as if you're directly implying that if a program is writing using the flowchart method and then converted to PICaxe basic codes, it won't make any sense (can't be use practically to accomplish any task and not to talk of complex ones) and needs to be review after conversion (i.e add or define label names, variables etc)

If that is the case, then whats is the realistic use of the flowchart method (is it just to be used to learn the concept of logical flow in a program).

Sorry for being vague as to the 20Kbyte of codes, i was referring to the approximate combine code size in all my 7 PICaxes in the project as i was planning to do a flow diagram for the logic in each picaxe.
 

hippy

Technical Support
Staff member
I don't think anyone is saying programs generated from flowcharts are of no use or fully working programs cannot be generated from flowcharts ( Logicator can do just that ), but going the other way is not always as easy.

If one has a flowchart block -

CalculateInterest
{
Interest = Loan * InterestRate + ServiceCharge
}

That can be converted to PICAXE Basic, and in a form which can be converted back. If the compiler converts the flowchart or you code it yourself and produce -

Sub1:
w0 = w1 * w2 + w3
Return

Then, while you can convert that back to a flowchart -

Sub1
{
w0 = w1 * w2 + w3
}

It doesn't give the information which there originally was.
 
Last edited:

BeanieBots

Moderator
Hippy's description is exactly the point I was trying to make.
All the information which makes the flow diagram make any sense gets lost rendering it almost useless. It remains functionally correct but not of any use as a tool to describe what is going on without heavy editiing which is likley to be as much work (if not harder) than doing it manually.

This is true for ANY attempt at going from low level back to high level be it basic to flow or another common request here to go from PIC contents (tokenised basic) back to BASIC (which can't be done anyway).
 
Top