0

I implemented an integrator (grounded capacitor driven by piece-wise constant current source) using Stateflow and the 'after' condition. See code.

With the given setting the capacitor should change its voltage every 1 sec, but does so about every 1.3 secs - Why?

Testbench

Statechart

Scope

bardo
  • 390
  • 1
  • 9
  • Add a picture of your model and chart. For security reason many people are (or should be) reluctant to download and run code from a 'random' individual. – Phil Goddard Sep 15 '17 at 17:50
  • Is the chart discrete? If so, what is the sample rate? If not, what are the time steps taken by the overall model? – Phil Goddard Sep 15 '17 at 23:01
  • Good question. I had the solver set to Update method: Inherited. Turns out that 'after' requires Continuous, to which 'hasChanged' is not compatible. So the solution could be to split the chart in two with different Update methods for the event detections and do the actual summing in a third block - Thanks! – bardo Sep 16 '17 at 05:52

1 Answers1

0

See my submission to File Exchange for an implementation in Stateflow.

Still looking for an S-function implementation.

bardo
  • 390
  • 1
  • 9