DifferentCodeSimAndDownload

From Flowcode Help
Revision as of 11:41, 19 September 2023 by MartinW (talk | contribs) (→‎Setup)
Jump to navigationJump to search

Introduction

In some cases it is necessary to use different code for simulation and for download.

Simulation icons automatically get ignored for compilation but often to drive the simulation macros you need additional code such as calculations and variables.

It can therefore be useful to separate out the simulation side code so that it does not consume resources for the embedded target.


Setup

First, add Events and Built-in Functions to project explorer, so it will look like this:

Sim1.jpg

You can reduce the width by dragging, but you will lose the titles:

Sim2.jpg


This only requires doing once

The extra UI trees can be added by File > Global Settings > UI Trees tab

Make sure the vents and Built-in Functions are moved to the Project Explorer window:

Sim3.jpg


Creating Event Macros

On the project explorer window click on the Events tab.

Click on + of Simulation to expand.

We are intrestesred in Simulation Start and Stop

Decisions

You can now add the Sim decisions anywhere in your program where Sim and download need to do different things.

Sim4.jpg


As the decision is referring to a property the generated C code is fixed and so the decision code gets optimised out when downloading to a microcontroller.


Example File

Here is a Flowcode example file showing the completed functionality.

FC6 Icon.png Sim Demo