cancel
Showing results for 
Search instead for 
Did you mean: 

Simulink Blockset for STM32

skrisada
Associate II
Posted on August 02, 2009 at 07:17

Simulink Blockset for STM32

11 REPLIES 11
16-32micros
Associate III
Posted on May 17, 2011 at 13:17

Dear skrisada & all Rapid STM32 team,

The Idea is excellent and the development/project is appealing on how easy we play with STM32 without C coding. This is suitable for all students and universities, I highly encourage you to continue having more and more examples around STM32 micros, Unfortunately I do not have Matlab, Mathworks software ,I will try to get an evaluation version so I can provide you useful feedbacks.

Really it is well done, and Invite all forum users to have a look :

http://www.rapidstm32.com/Home

Cheers,

STOne-32.

skrisada
Associate II
Posted on May 17, 2011 at 13:17

Dear all,

We 've just finished a beta Simulink blockset for STM32.

It 's called Rapid STM32 blockset.

When used with Matlab/Simulink/Real-Time Workshop Embedded Coder, the blockset can generate C code from Simulink model automatically.

The idea is to make implementing complex algorithm as simple as possible using high level graphical programming language like Matlab.

At the moment we 've only implemented the Digital IO, USART (TX), PWM, ADC1. More features will be added later.

We 'd really appreciate your feedback and 'd like invite you to take a look at

http://www.rapidstm32.com

.

There are 2 examples on the site.

1. Toggling pin C2 and C3 at specified frequencies.

2. Acquiring data from analog channel AN0 and send the data + time stamp to Simulink via USART for real-time plotting in Simulink scope or doing any DSP algorithms.

Thank you

Rapid STM32 team

skrisada
Associate II
Posted on May 17, 2011 at 13:17

Dear STOne-32

Thank you for your comment. This is very encouraging.

We will definitely continue to add more features and examples.

Hope you can get Matlab/Simulink evaluation OK.

You will need Real-Time Workshop and Real-Time Workshop Embedded Coder evalution too. (Please don't forget to mention to Mathworks sales' rep.)

Have you watched the videos? Are they helpful or difficult to follows.

Rapid STM32 team

16-32micros
Associate III
Posted on May 17, 2011 at 13:17

Hi Rapid Team,

The videos are excellent too, The ''overview_rvmdk.mp4'' is impressive, how simulation on Matlab/Simulink , RVMDK Logic Analyser and Real Hardware are behaving exactly the same and all on this in single mouse clicks, without any C Coding. Really it is excellent 🙂

Cheers,

STOne-32.

16-32micros
Associate III
Posted on May 17, 2011 at 13:17

Dear skrisada & all Rapid STM32 team,

I Started testing the Models on simulink and The results are very good, I like very much 🙂 Here is a screen-shot of my testing, However I'm not able to use the DAQ demo , I get always errors.

I have some remarks/future suggestions:

1) Add ADC Block (Input signal and output Digital)

2) add DAC Block ( Input Digital Stream and Analog output with Buffer On or Off)

=> My idea is to Use a a FIR ''low pass Filter'' to the a Noisy Sine signal from the ADC, apply to it the FIR from the Fixed-point Library and then Output it to the DAC of the STM32 and see the new filtered signal in a scope.

Is it possible to help me to have such model ?

Thank you a lot for your excellent Job.

Cheers,

STOne-32.

skrisada
Associate II
Posted on May 17, 2011 at 13:17

Dear STOne-32

We 're glad you like it. Did you manage to build the model, compile the code, download and run the digital IO on a real STM32?

Could you tell us what kind of errors you get when testing the DAQ demo?

>I have some remarks/future suggestions:

>

>1) Add ADC Block (Input signal and output Digital)

>2) add DAC Block ( Input Digital Stream and Analog output with Buffer On or Off)

The ADC Block has already been implemented.

It is under Simulink Library Browser/ Rapid STM32 Blockset / On-chip peripheral / ADC configuration.

It is also used in the DAQ demo.

You can select to output raw data (12-bits ADC as uint16 right-aligned), converted data in volts either using single (IEEE 32-bits float) or double (IEEE 64-bits double) format.

Moreover, under the ADC configuration block setting, you also have an option to select oversampling so that the ADC resolution is increased to either 13,14,15 or 16 bits (based on oversampling-decimation technique).

These options are available when you double click the ADC configuration block. But you have to change setting popup from ''Default'' to ''Custom'' to be able to change these features.

The ADC configuration dialog is shown in the picture.

The DAC block has not been implemented yet. But it is already on the list.

We will try to implement the DAC block as soon as possible.

At the moment we are working on SD card block to allow simple data logging to SDC.

>=> My idea is to Use a a FIR ''low pass Filter'' to the a Noisy Sine signal >from the ADC, apply to it the FIR from the Fixed-point Library and then >Output it to the DAC of the STM32 and see the new filtered signal in a >scope.

>Is it possible to help me to have such model ?

Absolutely. That is the beauty of using Matlab Simulink. You can insert a filter block

(any kind of DSP algorithms not only low-pass but also high-pass, adaptive, Kalman etc.).

Under it you can select FIR/IIR of any specified order or design specs. Matlab also show you the frequency response, delay time etc.

Take a look for a sample at

http://www.mathworks.com/access/helpdesk/help/toolbox/dspblks/ug/f8-178htmlf8-190263

.

This is an example of desinging a fixed point filter.

Since we have not implemented the DAC block yet, you will not be able to use the STM32 DAC. (You can integrate hand-written code for DAC, however.)

It is also possible to insert the lowpass filter block in the DAQ demo model to see how acquired data from real ADC is filtered.

Anyway I have attached a simple Simulink model file with .mdl to simulate your concept in Simulink.

We use the following blocks

1. Sin Wave and Band-limited white noise from Library Browser/Simulink/Sources

2. Quantizer from Library Browser/Simulink/Discontinuities (set quantization level to 3.3/2^12 to model 12-bits ADC with 3.3V max)

3. Sum from Library Browser/Simulink/Math operations

4. Low pass filter from Library Browser/ Signal Processing Blockset / Filtering / Filter Design Toolbox

5. Scope from Library Browser/Simulink/Sinks

6. Filter Realization Wizard block from the Filtering / Filter Designs library.

Tips

1. In Simulink press CTRL+J so that the model show different colors for different sample time.

2. In Simulink right click the mouse button select Format/Port Data Types so that the signal data type is displayed in the model.

You will be able to simulate the model.

Conceptually, to transfer from simulated model to the STM32 we only need to replace the Quantizer block and other block with STM32 blocks.

We can leave the algorithm block unchanged. Simulink will generate the C code for signal processing algorithm automatically for us.

Enjoy.

Rapid STM32 Team

[ This message was edited by: skrisada on 29-07-2009 09:31 ]

skrisada
Associate II
Posted on May 17, 2011 at 13:17

Hi STOne-32

The good news. We are implementing a DAC block according to your suggestion. Hopefully, by next week we will be able to release it and you can try it.

We have also just released an application note with lots of graphical instructions (minimum Maths :D ) about how to use Simulink to design and evaluate a Kalman filter for a tilt sensor system. The doc is expected to help acquaint STM32 users with Simulink. See

http://www.rapidstm32.com/application-notes

In part 2 (still in writing), we will demonstrate how to transfer from the design and simulation phase to creating a stand-alone embedded tilt sensor system.

Best regards

Rapid STM32 Team

[ This message was edited by: skrisada on 30-07-2009 17:26 ]

16-32micros
Associate III
Posted on May 17, 2011 at 13:17

Hi Rapid STM32 Team ,

This is a Great achievement ! Thank you a lot for all your recommendations, I will start learning and reading the App notes soon 🙂

Regarding the ADC, I would like to have also a simulated Input stage that I can feed with an input inside Simulink.

And here is attached the Error that I get once I make a build of the DAQ Demo, Do you know what may be the root cause ?

Thank you for your help.

Cheers,

STOne32.

skrisada
Associate II
Posted on May 17, 2011 at 13:17

Hi STOne-32

For the daq_demo could you please try replacing the rapidstm32_entry_hook.p in c:\rapidstm32\rapidstm32 directory with the one attached with this message.

If this still doesn't work please let us know. No fear, we will fix it eventually. Also please let us know if it works so that we can rest and release this patch. :D

For the input to the ADC, it is possible but not recommended.

See details from

http://www.mathworks.com/access/helpdesk/help/toolbox/ecoder/det/f41558.html

.

Basically, the Mathworks Inc. recommends ''Multiple-Model Approach'' meaning...

''Have two separate models; one purely for simulation and another purely for code generation to prevent confusion'' together with other advantages mentioned in the help.

So, in practice, you design, simulate, and test your algorithm in one Simulink model until you are fully satisfied. Then you copy only the algorithm block into another model with Rapid STM32 blockset for code generation for STM32.

Please try the tutorial in the app note. It is very introductory and it should help you get started easier. (I hope. 8-)) If you find errors or room for improvement please let us know.

thank you

Rapid STM32 Team