Can I initiate interrupt on a PLC digital input, in the same way we use nucleo board pins?

29 Nov 2016

/media/uploads/khsaleh/img_2639.jpg Successful interrupt on PB_8 ( it failed on PA_3, any thought?) /media/uploads/khsaleh/pb_8.jpg InputArray[1] is the state of the inputs. What is InputArray[0]

Please find here copy of main.cpp

/ ****************

  • @file main.cpp
  • @author AST/CLs
  • @version V1.1.0
  • @date February 23rd, 2016
  • @brief mbed test application for the STMicroelectronics X-NUCLEO-PLC01A1
  • PLC Expansion Board.
  • /

/* Includes --------------*/

/* expansion board specific header files. */

  1. include "x_nucleo_plc01a1_class.h"
  1. include "rtos.h"

/* Definitions -------------*/

/* Uncomment this for OUTPUT_CYCLING ENABLE */ #define OUTPUT_CYCLING

/* Variables -------------*/

/* Array for input data from Digital Input Termination Device */ uint8_t inputArray[2] = {0x00, 0x00}; /* Array for output data to Solid State Relay */ uint8_t outputArray[2] = {0x00, 0x00};

/* Number of channels in ON state */ uint8_t Ch_On = 0x00;

/*==================================================== pulse generator is connected to pin and the thread implements the pulse counter - can the PLC inputs generate similar interrupts?

================================================*/

Timer t1; InterruptIn in(PB_8); (PA_3) not working; int count = 0; float t_period = 0; This is the period between interrupts in microseconds float HZ = 0;

void counter(void ) { count++; t_period = t1.read_us(); Get time since last interrupt HZ = (1/t_period)*1000000; Convert period (in us) to frequency (Hz) t1.reset(); Reset timer and wait for next interrupt }

void print_thread(void const* argument) { while (true){ Thread::wait(10000); printf("pulses = %d\nFreq = %.2f\ninArray[0] %.2x\ninArray[1] %.2x\n "\ ,count,HZ,inputArray[0],inputArray[1]); fflush(stdout); } }

/* Functions -------------*/

/

  • @brief Receive input data from Digital Input Termination Device
  • @param None
  • @retval None
  • / void DigitalInputArrayHandler(X_NUCLEO_PLC01A1 &plc) { plc.plcInput().DigInpArray_GetInput(inputArray); }

/

  • @brief Select output function and set outputs
  • @param None
  • @retval None
  • / void SsrelayHandler(X_NUCLEO_PLC01A1 &plc) { /* Set outputArray as DigInpArray RxBuffer */ outputArray[1] = plc.signalMirror(inputArray[1]);

/* Uncomment the relevant function as required */ outputArray[1] = plc.signalMirror(0xFF); outputArray[1] = plc.outputFreeze(0xFF,5000); outputArray[1] = plc.outputRegroup(0xFF); Ch_On = plc.inputSum(&outputArray[1],0xFF); outputArray[1] = plc.setOutput(0xFF); outputArray[1] = plc.inputsAND(0xFF,0x0F); outputArray[1] = plc.inputsOR(0xF0,0x0F); outputArray[1] = plc.inputsNOT(0x00); outputArray[1] = plc.inputsXOR(0xFF,0x00);

/* Parity bits calculation */ plc.outputParityBits(outputArray);

/* Send output information to solid state relay */ plc.plcOutput().Ssrelay_SetOutput(outputArray); }

void setup(SPI &spi, int bits, int mode = 0, int frequency_hz = 1E6) { /* Set given configuration. */ spi.format(bits, mode); spi.frequency(frequency_hz); }

/* Main --------------*/

int main() { /*- Initialization. -*/

/* Initializing SPI bus. */ SPI spi(X_NUCLEO_PLC01A1_PIN_SPI_MOSI, X_NUCLEO_PLC01A1_PIN_SPI_MISO, X_NUCLEO_PLC01A1_PIN_SPI_SCLK); setup(spi, X_NUCLEO_PLC01A1_PIN_SPI_BITS);

/* Initializing X_NUCLEO_PLC01A1 IO Channels Component. */ X_NUCLEO_PLC01A1 plc(X_NUCLEO_PLC01A1_PIN_SPI_CS1, X_NUCLEO_PLC01A1_PIN_SPI_CS2, X_NUCLEO_PLC01A1_PIN_OUT_EN, spi);

printf("\n\n* RTOS PLC example *\n"); pulse counter in.mode(PullDown); Set the pin to Pull Down mode. in.rise(&counter); Set up the interrupt for rising edge t1.start(); start the timer

Compiler raises "Deprecated" warning, what is the updated declaration? Thread thread(print_thread,NULL, osPriorityNormal, DEFAULT_STACK_SIZE);

while(1) { plc.plcInput().SetReadStatus(1); /* Polling input device to refresh input state */ if(plc.plcInput().GetReadStatus()) {

plc.plcInput().SetReadStatus(0);

  1. ifdef OUTPUT_CYCLING plc.outputCycling();
  2. else DigitalInputArrayHandler(plc); SsrelayHandler(plc);
  3. endif /* OUTPUT_CYCLING */ } wait_ms(10); } }