Library to use my Photo MOS Relays Circuit having 16 or less channels.
Fork of PMRC4ch by
PMRC16ch.h
00001 /** PMRC16 class header file 00002 * \file PMRC16ch.h 00003 * \author Akifumi Takahashi 00004 * \date 2016/dec/11- 00005 * - ver.1; 8 channel 00006 * \date 2018/jun/01- 00007 * - ver.16.1; 16 channel 00008 * \date 2018/jun/28- 00009 * - ver.16.2; major change 00010 */ 00011 #ifndef PMRC_16CHANNEL_H 00012 #define PMRC_16CHANNEL_H 00013 #include "mbed.h" 00014 /** PMCR16 nyaan 00015 * \par About PMRC16 class 00016 * - A Program with which to control Photo MOS Relay Circuit 00017 * for 16 channels Electric Stimulation. 00018 * - Photo Couplers are controlled by Shift Resisters. So this lib serves 00019 * shift resister's utility. 00020 * 00021 * \par Image of Photo MOS Relay Array 00022 * - 32 Photo MOS Relay IN 00023 * - 16 channel OUT 00024 * 00025 * \verbatim 00026 * +--i o----+----i o--+ 00027 * | [PMR01-1] | [PMR01-2] | 00028 * | (ch1(B)out) | 00029 * | | 00030 * +--i o----+----i o--+ 00031 * | [PMR02-1] | [PMR02-2] | 00032 * | (ch2(R)out) | 00033 * | | 00034 * . . . 00035 * . . . 00036 * . . . 00037 * Vpp GND 00038 * \endverbatim 00039 * 00040 * \par Info. Shit-Resister circuit board 00041 * - nOE is connected to GND 00042 * 00043 * \verbatim 00044 * in 00045 * ->[PMR01-1]->[PMR01-2]->[PMR02-1]->[PMR02-2] 00046 * ->[PMR03-1]->[PMR03-2]->[PMR04-1]->[PMR04-2] 00047 * ->[PMR05-1]->[PMR05-2]->[PMR06-1]->[PMR06-2] 00048 * ->[PMR07-1]->[PMR07-2]->[PMR08-1]->[PMR08-2] 00049 * ->[PMR09-1]->[PMR09-2]->[PMR10-1]->[PMR10-2] 00050 * ->[PMR11-1]->[PMR11-2]->[PMR12-1]->[PMR12-2] 00051 * ->[PMR13-1]->[PMR13-2]->[PMR14-1]->[PMR14-2] 00052 * ->[PMR15-1]->[PMR15-2]->[PMR16-1]->[PMR16-2] 00053 * ->out 00054 * \endverbatim 00055 * 00056 * \version 1 00057 * - 2016/dec/11- 00058 * - program bersion for 8 channel circuit 00059 * \version 16.1 00060 * - 2018/jun/01- 00061 * - 16 channel version 00062 * \version 16.2 00063 * - 2018/jun/28- 00064 * - major change 00065 * \version 16.x 00066 */ 00067 class PMRC16ch 00068 { 00069 public: 00070 // 00071 // Constructors 00072 // 00073 /// Constructor default 00074 PMRC16ch(); 00075 /// Constructor with setting num of channels 00076 PMRC16ch( 00077 uint8_t arg_num_ch ///<[in] number of channels to use 00078 ); 00079 /// Construxtor with full configuration 00080 PMRC16ch( 00081 uint8_t arg_num_ch, ///<[in] number of channels to use 00082 PinName arg_SCK, ///<[in] pin of shift registor clock 00083 PinName arg_CLR, ///<[in] pin to clear the shift registor 00084 PinName arg_RCK, ///<[in] pin of storage registor (buffer) clock 00085 PinName arg_SER, ///<[in] pin to insert data 00086 PinName arg_OUT ///<[in] pin to receive overflowed bit 00087 ); 00088 00089 // Const. 00090 enum State { 00091 ALLGROUND = 0x55555555, 00092 CH1 = /*1V*/0b10000000000000000000000000000000/*16G*/, 00093 CH2 = /*1V*/0b00100000000000000000000000000000/*16G*/, 00094 CH3 = /*1V*/0b00001000000000000000000000000000/*16G*/, 00095 CH4 = /*1V*/0b00000010000000000000000000000000/*16G*/, 00096 CH5 = /*1V*/0b00000000100000000000000000000000/*16G*/, 00097 CH6 = /*1V*/0b00000000001000000000000000000000/*16G*/, 00098 CH7 = /*1V*/0b00000000000010000000000000000000/*16G*/, 00099 CH8 = /*1V*/0b00000000000000100000000000000000/*16G*/, 00100 CH9 = /*1V*/0b00000000000000001000000000000000/*16G*/, 00101 CH10= /*1V*/0b00000000000000000010000000000000/*16G*/, 00102 CH11= /*1V*/0b00000000000000000000100000000000/*16G*/, 00103 CH12= /*1V*/0b00000000000000000000001000000000/*16G*/, 00104 CH13= /*1V*/0b00000000000000000000000010000000/*16G*/, 00105 CH14= /*1V*/0b00000000000000000000000000100000/*16G*/, 00106 CH15= /*1V*/0b00000000000000000000000000001000/*16G*/, 00107 CH16= /*1V*/0b00000000000000000000000000000010/*16G*/, 00108 ALLHiZ = 0x00000000 00109 }; 00110 enum Polarity {Anodic = 0, Cathodic = 1}; 00111 enum StimMode {ONE_VS_THEOTHERS, TWIN_ELECTRODES}; 00112 // 00113 // Function to prepare channels 00114 // 00115 void allGround(); 00116 void allHiZ(); 00117 void setPol(Polarity pol); //inline definition 00118 void setOvsO(char ch); 00119 void setTwin(char stim_ch, char ref_ch); 00120 void setTrio(char stim_ch, char ref_ch1, char ref_ch2); 00121 // 00122 // Function to get prameter 00123 // 00124 uint32_t getState(); //inline definition 00125 bool getPol(); //inline definition 00126 00127 private: 00128 // The number of channels to use 00129 const uint8_t m_num_ch; 00130 // 00131 // Sig var to controll PRM circuit 00132 // 00133 DigitalOut m_SCK; // Shift-resister's clock 00134 DigitalOut m_CLR; // To use when you want to clear shift-resister 00135 DigitalOut m_RCK; // FF's clock 00136 DigitalOut m_SER; // Serial input to shift data in a shift-resister 00137 DigitalIn m_OUT; // Output data overflowed from shift-resister 00138 // 00139 // Var of state 00140 // 00141 // Position of stimulation bits 00142 // 0: no stimbits, 1~m_num_ch: channel of stimulation 00143 uint32_t m_pos_stim; 00144 static const uint32_t m_statearray[]; 00145 uint32_t m_PMRC_state; 00146 Polarity m_PMRC_POL; 00147 StimMode m_PMRC_mode; 00148 // Initialization 00149 void init(); 00150 // 00151 // Function to control buffer of shift-resister 00152 // 00153 // shift the bits arbitary times 00154 void shiftby(int times); 00155 // the function with which to rapidly set it all-ground 00156 void sweep(); 00157 // set the simulation bits of 01 00158 void setStimbits(); 00159 // set all bits arbitarily 00160 void setBits(const uint32_t bits); 00161 // 00162 // Clock Function 00163 // 00164 //update the clock of shift-resister 00165 void update(); 00166 // output the data by uploading them to FF Resitors 00167 void upload(); 00168 }; 00169 inline void PMRC16ch::setPol(Polarity arg_pol) 00170 { 00171 m_PMRC_POL = arg_pol; 00172 } 00173 inline uint32_t PMRC16ch::getState() 00174 { 00175 return m_PMRC_state; 00176 } 00177 inline bool PMRC16ch::getPol() 00178 { 00179 //return false if cathodic 00180 //return true if anodic 00181 return static_cast<bool>(m_PMRC_POL); 00182 } 00183 #endif
Generated on Tue Jul 12 2022 23:51:41 by 1.7.2