Library to use my Photo MOS Relays Circuit having 16 or less channels.

Fork of PMRC4ch by Akifumi Takahashi

Revision:
15:56703876e914
Child:
17:08a68860396b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PMRC16ch.h	Tue Jun 26 12:19:09 2018 +0000
@@ -0,0 +1,123 @@
+#ifndef PMRC_16CHANNEL_H
+#define PMRC_16CHANNEL_H
+/**
+ *  PMRC16ch.h
+ *  ----------------------------------------
+ *  -  A Program with which to control
+ *  Photo MOS Relay Circuit
+ *  for 16 channels Electric Stimulation.
+ *  which ES circuit made by Ph.D. Kajimoto.
+ *  Photo Couplers are controlled by Shift-
+ *  Resisters. So this lib serves sift-
+ *  resister's utility.
+ *  ----------------------------------------
+ *  32 Photo MOS Relay IN
+ *  16 channel OUT
+ *   +--i      o----+----i      o--+
+ *   |  [PMR01-1]   |    [PMR01-2] |
+ *   |         (ch1(B)out)         |
+ *   |                             |
+ *   +--i      o----+----i      o--+
+ *   |  [PMR02-1]   |    [PMR02-2] |
+ *   |         (ch2(R)out)         |
+ *   |                             |
+ *   .              .              .
+ *   .              .              .
+ *   .              .              .
+ *  Vpp                           GND
+ *  ----------------------------------------
+ *  Shit-Resister
+ *  nOE is connected to GND
+ *  in
+ *  ->[PMR01-1]->[PMR01-2]->[PMR02-1]->[PMR02-2]
+ *  ->[PMR03-1]->[PMR03-2]->[PMR04-1]->[PMR04-2]
+ *  ->[PMR05-1]->[PMR05-2]->[PMR06-1]->[PMR06-2]
+ *  ->[PMR07-1]->[PMR07-2]->[PMR08-1]->[PMR08-2]
+ *  ->[PMR09-1]->[PMR09-2]->[PMR10-1]->[PMR10-2]
+ *  ->[PMR11-1]->[PMR11-2]->[PMR12-1]->[PMR12-2]
+ *  ->[PMR13-1]->[PMR13-2]->[PMR14-1]->[PMR14-2]
+ *  ->[PMR15-1]->[PMR15-2]->[PMR16-1]->[PMR16-2]
+ *  ->out
+ *  ----------------------------------------
+ *  Log
+ *  ver.1   2016/dec/11-
+ *  ch.16 VER.
+ *  ver.16.1   2018/jun/01-
+ */
+#include "mbed.h"
+class PMRC16ch
+{
+public:
+    //
+    //  Constructor
+    //
+    PMRC16ch();
+    PMRC16ch(
+        uint8_t arg_num_ch,
+        PinName arg_SCK,
+        PinName arg_CLR,
+        PinName arg_RCK,
+        PinName arg_SER,
+        PinName arg_OUT
+        );
+
+    //  Const.
+    enum State {ALLOFF = 0, CH1 = 1, CH2, CH3, CH4, CH5, CH6, CH7, CH8, 
+                CH9, CH10, CH11, CH12, CH13, CH14, CH15, CH16, NaN = 9999};
+    enum Polarity {Anodic = 0, Cathodic = 1};
+    //
+    //  Function to set channel
+    //
+    char allOff();
+    char setCh(State ch, Polarity cp = Cathodic);
+    char setCh(char ch, Polarity cp = Cathodic);
+    void allHiZ();
+    void setBits(uint32_t bits, int num_of_bits, Polarity cp = Cathodic);
+    //
+    //  Function to get prameter
+    //
+    char getState();//inline definition
+    bool getPol();  //inline definition
+
+private:
+    //
+    //  Sig var to controll PRM circuit
+    //
+    uint8_t m_num_ch;   //  The number of channels to use 
+    DigitalOut m_SCK;   //  Shift-resister's clock
+    DigitalOut m_CLR;   //  To use when you want to clear shift-resister
+    DigitalOut m_RCK;   //  FF's clock
+    DigitalOut m_SER;   //  Serial input to shift data in a shift-resister
+    DigitalIn  m_OUT;   //  Output data overflowed from shift-resister
+    //  Initialization
+    void init();
+    //
+    //  Function to set channel
+    //
+    //  shift the bits arbitary times
+    void shiftby(int times);
+    //  this is the function with which to rapidly set it all-off
+    void sweep();
+    //  set the simulation bits of 01
+    void setStimbits();
+    //update the clock of shift-resister
+    void update();
+    //  output the data by uploading them to FF Resitors
+    void upload();
+    //
+    // Var for store state
+    //
+    State m_PMRC_state;
+    Polarity m_PMRC_POL;
+};
+inline char PMRC16ch::getState()
+{
+    return static_cast<char>(m_PMRC_state);
+}
+inline bool PMRC16ch::getPol()
+{
+    //return false if cathodic
+    //return true  if anodic
+    return static_cast<bool>(m_PMRC_POL);
+}
+#endif
\ No newline at end of file