How to get a single or double out of a simulink block created with a tlc-file

2 vues (au cours des 30 derniers jours)
Sietse
Sietse le 15 Juin 2015
Dear list,
I created a target for the stm32f4 microcontroller. I have a question about one of the simulink blocks. The block code (and complete target) can be found at http://fwn06.housing.rug.nl/stm32f4_target/stm32f4/blocks/AandD/tlc_c/stmadc1.tlc. The model (adc_float) that I test it with is only this block connected to a scope block, using external mode.
stmadc1 is a simple block that implements getting a value from a ADC. I want the block to return a signal of type SS_SINGLE, as I specify in the .c version. But it seems that values calculated (say 0.0034) are returned as a rounded values (now 0).
The question is, how to get these "float's" visable in the simulation. The tlc-file is not much more than:
%function Outputs(block, system) Output
int adc1_sum;
float adc1_value;
adc1_sum= ((int)Get_ADC_Value(11))*8;
adc1_value = (float) adc1_sum;
printf("fl %f\r\n", adc1_value);
%<LibBlockOutputSignal(0, "", "", 0)> = adc1_value;
%endfunction %%Outputs
Note that I can test the value going to the output signal using the printf; the values a really floats. Looking at the generated code (adc_float.h) I see:
/* Block signals (auto storage) */
typedef struct {
int32_T SFunction1; /* '<Root>/S-Function1' */
} B_adc_float_T;
And the adc_float.c file gives:
adc1_value = (float) adc1_sum;
printf("fl %f\r\n", adc1_value);
adc_float_B.SFunction1 = adc1_value;
So the type of the output signal values is an int32_T. The question is how do I get that to be a real_T. Note that if I use the timestwo example I DO get a real_T. But I don't see the difference with my block.
Thanks in advance, Sietse

Réponses (0)

Catégories

En savoir plus sur Target Language Compiler dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by