Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include "mbed.h"
  2. #include "main.h"
  3. #include "x_nucleo_plc01a1_class.h"
  4.  
  5. int main(){  
  6.     setup(spi, X_NUCLEO_PLC01A1_PIN_SPI_BITS, 0, 1E6);  //set the SPI function mode: 16-bit / mode 0 / 486Hz ???
  7.                                                         //I can't find what mode 0 does, or why we're at 486 Hz....
  8.     tickevent1.attach(*dacticker, 5);                  
  9.     tickevent2.attach(*ledticker, 0.1);                 //tickers can run parallel, while the program code moves on.
  10.     tickevent3.attach(*relayticker, 3);
  11. }
  12.  
  13. void dacticker(){
  14.     out.write(temp);
  15.     temp += 0.03;
  16.     if(temp > 0.3f){    //apparantly the 'f' part is important. Voltage only goes 0.9V if 0.30 is used instead of 0.3f
  17.         temp = 0.00;
  18.     }
  19. }
  20.  
  21. void ledticker(){
  22.     LD2 = !LD2;
  23. }
  24.  
  25. void relayticker(){    
  26.     DigitalInputArrayHandler(plc);
  27.     SsrelayHandler(plc, relay_input); //Don't forget to set the correct mode!            
  28. }
  29.  
  30. /**********************************************************
  31. ****************** PLC BOARD FUNCTIONS ********************
  32. **********************************************************/
  33.  
  34. void DigitalInputArrayHandler(X_NUCLEO_PLC01A1 &plc)        // Receive input data from Digital Input Termination Device
  35. {
  36.   plc.plcInput().DigInpArray_GetInput(inputArray);
  37. }
  38.  
  39. void SsrelayHandler(X_NUCLEO_PLC01A1 &plc, uint8_t VNI_out) //Select output function and set outputs
  40. {
  41.   outputArray[1] = plc.setOutput(0xFF);                     //Activate all PLC outputs simultaneously.
  42.   plc.outputParityBits(outputArray);                        /* Parity bits calculation */
  43.   plc.plcOutput().Ssrelay_SetOutput(outputArray);           /* Send output information to solid state relay */
  44. }
  45.  
  46. void setup(SPI &spi, int bits, int mode, int frequency_hz) //0x1E6 = 486 Hz?
  47. {
  48.     /* Set given configuration. */
  49.     spi.format(bits, mode);
  50.     spi.frequency(frequency_hz);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement