Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mbed.h"
- #include "main.h"
- #include "x_nucleo_plc01a1_class.h"
- int main(){
- setup(spi, X_NUCLEO_PLC01A1_PIN_SPI_BITS, 0, 1E6); //set the SPI function mode: 16-bit / mode 0 / 486Hz ???
- //I can't find what mode 0 does, or why we're at 486 Hz....
- tickevent1.attach(*dacticker, 5);
- tickevent2.attach(*ledticker, 0.1); //tickers can run parallel, while the program code moves on.
- tickevent3.attach(*relayticker, 3);
- }
- void dacticker(){
- out.write(temp);
- temp += 0.03;
- if(temp > 0.3f){ //apparantly the 'f' part is important. Voltage only goes 0.9V if 0.30 is used instead of 0.3f
- temp = 0.00;
- }
- }
- void ledticker(){
- LD2 = !LD2;
- }
- void relayticker(){
- DigitalInputArrayHandler(plc);
- SsrelayHandler(plc, relay_input); //Don't forget to set the correct mode!
- }
- /**********************************************************
- ****************** PLC BOARD FUNCTIONS ********************
- **********************************************************/
- void DigitalInputArrayHandler(X_NUCLEO_PLC01A1 &plc) // Receive input data from Digital Input Termination Device
- {
- plc.plcInput().DigInpArray_GetInput(inputArray);
- }
- void SsrelayHandler(X_NUCLEO_PLC01A1 &plc, uint8_t VNI_out) //Select output function and set outputs
- {
- outputArray[1] = plc.setOutput(0xFF); //Activate all PLC outputs simultaneously.
- plc.outputParityBits(outputArray); /* Parity bits calculation */
- plc.plcOutput().Ssrelay_SetOutput(outputArray); /* Send output information to solid state relay */
- }
- void setup(SPI &spi, int bits, int mode, int frequency_hz) //0x1E6 = 486 Hz?
- {
- /* Set given configuration. */
- spi.format(bits, mode);
- spi.frequency(frequency_hz);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement