microcontroller - connect more input to micro from pc817 - TagMerge
2connect more input to micro from pc817connect more input to micro from pc817

connect more input to micro from pc817

Asked 1 years ago
0
2 answers

You can look at it as a 2D matrix n times m, n sets of m optocouplers, in your case n=2 and m=7.

You can read only one set of 7 optocouplers at a time. To read both, you need in principle this sequence:

  1. Set E1 "high" and E2 "low".
  2. Read A0 to A5 and E0 for the first set.
  3. Set E1 "low" and E2 "high".
  4. Read A0 to A5 and E0 for the second set.

Now you have 14 bit values and you can process them.

This is called time division multiplexing, you have 2 time steps and 7 data bits per step.

The circuit works like this:

Only those transistors that have their collectors at "high" can conduct, if they are "on" via their respective LED. I would call them "enabled". If they are "on", the "high" level is readable on A0 to A5 and E0, respectively.

Any transistor with the collector at "low" cannot provide a "high". I would call it "disabled".

To avoid interfering feedback (or reverse) current to the "disabled" transistors, the diodes separate them.

Source: link

0

Arduino Sketch
#include <TimerOne.h>
volatile int i = 0;                               // Variable to use as a counter
volatile boolean zero_cross = 0;   // Boolean to store a "switch" to tell us if we have crossed zero
int AC_pin = 3;                                               // Output to Opto Triac
int dim = 128;                                              // Dimming level (0-128)  0 = on, 128 = 0ff
int freqStep = 77;                                    // This is the delay-per-brightness step in microseconds.
int a = 0;
int pin = 13;
int data = 0;
void setup() 
{
Serial.begin(9600);
pinMode(AC_pin, OUTPUT);                              // Set the Triac pin as output
attachInterrupt(0, zero_cross_detect, RISING);    // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection

Timer1.initialize(freqStep);                                   // Initialize TimerOne library for the freq we need

Timer1.attachInterrupt(dim_check2, freqStep);

}

void zero_cross_detect()

{

zero_cross = true;               // set the boolean to true to tell our dimming function that a zero cross has occured

i = 0;

digitalWrite(AC_pin, LOW);

}

// Turn on the TRIAC at the appropriate time

void dim_check2()

{

if (zero_cross == true) {

if (i >= dim) {

digitalWrite(AC_pin, HIGH);    // turn on light

i = 0;                                                        // reset time step counter

zero_cross = false;                                // reset zero cross detection

}

else {

i++;                                                 // increment time step counter

}

}

}

void loop() {

if (Serial.available()) {
a++;
if (a == 1) data = Serial.read();
if (a == 2) 
 {
pin = Serial.read();
a = 0;
dim = data;
}
}
}

Source: link

Recent Questions on microcontroller

    Programming Languages