0% found this document useful (0 votes)
7 views7 pages

Matlab - Simulink - Keil ARM

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Matlab - Simulink - Keil ARM

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

-

-
-
- -
- -

-
o
o (trong Real-Time Workshop \
Custom Code)
o
1
- :
o
o z O
(trong Real-Time Workshop \ Custom Code)
o -
(trong Simulink \ User-Defined Function)

3.
- - - -

o -Time Workshop Embedded Coder


o
- - -
.
o - : Fixed-step
o -> Solver : Discrete
o Solver options -> Fixed-step size: T

2
4.
-
o <model>.c
o <mode_data>.c
o ert_main.c <model>.c. S

o *.h

3
/*
* File: pid.c
* ....
*/
#include "pid.h"
#include "pid_private.h"
/* Exported block signals */
real_T In2; /* '<Root>/In2' */
real_T Out1; /* '<Root>/Saturation' */
real_T Out2; /* '<Root>/Pulse Generator' */
/* Block states (auto storage) */
D_Work_pid pid_DWork;
/* Real-time model */
RT_MODEL_pid pid_M_;
RT_MODEL_pid *pid_M = &pid_M_;

/* Model step function */


void pid_step(void)
{
real_T rtb_Add;
real_T rtb_Sum;
real_T rtb_FilterCoefficient;
...
/* Sum: '<Root>/Add' incorporates:
* Inport: '<Root>/In2'
*/
rtb_Add -= In2;
...
/* Saturate: '<Root>/Saturation' */
Out1 = rt_SATURATE(rtb_Sum, pid_P.Saturation_LowerSat,
pid_P.Saturation_UpperSat);
...
}

/* Model initialize function */


void pid_initialize(void)
{
...
/* exported global signals */
Out1 = 0.0;
Out2 = 0.0;
...
/* external inputs */
In2 = 0.0;
...
}

/* Model terminate function */


void pid_terminate(void)
{
/* (no terminate code required) */
}

4
/*
* File: pid_data.c
* . . .
*/

#include "pid.h"
#include "pid_private.h"

/* Block parameters (auto storage) */


Parameters_pid pid_P = {
1000.0, /* Expression: 1000
* Referenced by:
'<Root>/Setpoint (deg)'
*/
800.0, /* Computed Parameter:
Setpointdeg_Period
* Referenced by:
'<Root>/Setpoint (deg)'
*/
400.0, /* Computed Parameter:
Setpointdeg_Duty
* Referenced by:
'<Root>/Setpoint (deg)'
*/
0.0, /* Expression: 0
* Referenced by:
'<Root>/Setpoint (deg)'
*/
0.05, /* Expression: P
* Referenced by:
'<S1>/Proportional Gain'
*/
0.005, /* Computed Parameter:
Integrator_gainval
* Referenced by:
'<S1>/Integrator'
*/
0.0, /* Expression:
InitialConditionForIntegrator
* Referenced by:
'<S1>/Integrator'
*/
0.0, /* Expression: D
* Referenced by:
'<S1>/Derivative Gain'
*/
0.005, /* Computed Parameter:
Filter_gainval
* Referenced by:
'<S1>/Filter'
*/
. . .
};

5
/*
* File: ert_main.c
* . . .
*/
#include <stdio.h>
#include "pid.h" /* Model's header file */
#include "rtwtypes.h" /* MathWorks types */
static boolean_T OverrunFlag = 0;
. . .
void rt_OneStep(void)
{
...
/* Step the model */
pid_step();

/* Get model outputs here */

/* Indicate task complete */


OverrunFlag--;
}

int_T main(int_T argc, const char_T *argv[])


{
/* Initialize model */
pid_initialize();

/* Attach rt_OneStep to a timer or interrupt service routine with


* period 0.005 seconds (the model's base sample time) here. The
* call syntax for rt_OneStep is
*
* rt_OneStep();
*/
...

/* Terminate model */
pid_terminate();
return 0;
}

6
5. C
-
o \ User Defined Functions)
o \
User Defined Functions)
- Ch
o z O
-Time Workshop \ Custom Code)
o - \ User-Defined
Function)

6. T fil

You might also like