CoDeSys on CCP XS for Bromma Conquip - Research
CoDeSys on CCP XS for Bromma Conquip - Research
CoDeSys on CCP XS for Bromma Conquip - Research
- No tags were found...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Student<br />
Joel Ek<br />
Supervisor at CC-Systems<br />
Fredrik Löwenhielm<br />
Dok Nr<br />
1.0<br />
Date<br />
2006-08-08<br />
Rev<br />
PA1<br />
Säk klass<br />
F<br />
Filname<br />
Thesis.doc<br />
CODESYS ON <strong>CCP</strong> <strong>XS</strong> FOR BROMMA CONQUIP<br />
- BROMMA_ANDinit: this functi<strong>on</strong> is called up<strong>on</strong> initiati<strong>on</strong> and is used if any variables<br />
need to be initialized.<br />
- BROMMA_AND: this functi<strong>on</strong> is then called c<strong>on</strong>sciously during executi<strong>on</strong>. Here the<br />
processing takes place; reading inputs, make calculati<strong>on</strong>s and write to the outgoing ports<br />
of the comp<strong>on</strong>ent.<br />
These two functi<strong>on</strong>s need to be implemented and placed in the IO-driver file IODrvFuncti<strong>on</strong>s.c.<br />
This C-file will of course include the header file with the declarati<strong>on</strong>s of the functi<strong>on</strong>s and the<br />
structs.<br />
If we now look at an example of how the code <strong>for</strong> a comp<strong>on</strong>ent was programmed in C++.<br />
// CLASS:<br />
// CompAnd<br />
//<br />
// DESCRIPTION:<br />
// Implements the behavior of the logical AND functi<strong>on</strong>.<br />
// The comp<strong>on</strong>ent inherits from class Comp<strong>on</strong>ent and<br />
// overrides the methods 'calculate' and 'setArgs'.<br />
//<br />
class CompAnd : public Comp<strong>on</strong>ent<br />
{<br />
public:<br />
CompAnd(); // C<strong>on</strong>structor<br />
~CompAnd(); // Destructor<br />
void calculate();<br />
l<strong>on</strong>g setArgs(BlockParameter * parameters);<br />
#ifdef CODEGENERATION<br />
char * generateDesripti<strong>on</strong>String();<br />
#endif<br />
protected:<br />
private:<br />
l<strong>on</strong>g cInM;<br />
Comp<strong>on</strong>entPort * sigInInM[20];<br />
Comp<strong>on</strong>entPort * sigOutOutM;<br />
};<br />
#endif //COMPAND_H<br />
// NAME:<br />
// calculate<br />
//<br />
// DESCRIPTION:<br />
// Calculates the output signals depending <strong>on</strong><br />
// the input signals and internal state.<br />
//<br />
void CompAnd::calculate()<br />
{<br />
l<strong>on</strong>g i;<br />
// Calculate the output signal<br />
<strong>for</strong>(i = 0; i < cInM; i++)<br />
{<br />
if(getValue(sigInInM[i]) == 0)<br />
{<br />
setValue(sigOutOutM, 0);<br />
return;<br />
}<br />
}<br />
// Set the output signal<br />
setValue(sigOutOutM, 1);<br />
}<br />
Figure 19: Definiti<strong>on</strong> of the AND comp<strong>on</strong>ent and the code <strong>for</strong> the member variable calculate.<br />
As we saw in figure 6, compAnd inherits from the super class comp<strong>on</strong>ent. Many of the functi<strong>on</strong>s<br />
in the super class comp<strong>on</strong>ent and the specific comp<strong>on</strong>ents are not necessary to implement in the<br />
IO-driver since <str<strong>on</strong>g>CoDeSys</str<strong>on</strong>g> automatically handles it. It could <strong>for</strong> example be the member functi<strong>on</strong><br />
setArgs in compAnd which set up the input ports and output ports of the comp<strong>on</strong>ent.<br />
Instead it’s particularly <strong>on</strong>e functi<strong>on</strong> that is interesting: the calculate functi<strong>on</strong>. It is found in every<br />
comp<strong>on</strong>ent and is called by Comp<strong>on</strong>entBoard (fig. 8), this functi<strong>on</strong> calculates the output signal<br />
depending <strong>on</strong> the input signals <strong>for</strong> every comp<strong>on</strong>ent.<br />
This is the part we are interested in and that we want to port into ANSI C code and put in the IOdriver.<br />
32 (55)