dIGITAL MUX PROGRAMMING


dear all.

i having totally 18 digital io. 8 pins being used select device id.i have followed 8:1 digital mux circuit reduce no of  pins. using s0,s1,s2 pins selecting analog , digital multiplexer.my question here how can select proper device in program if mypins keep switching.please out here.

http://www.nxp.com/documents/data_sheet/74hc_hct251.pdf

datasheet attached below.

there totally 26 analog 18 digital io required application, 24 analog channel maintained 8:1 multiplexer. working fine. facing problem choosing or set device id here.if code available more full.


below code analog reading values. need idea choose device id between 0~255 based on digital multiplexer.

code: [select]

#include <avr/wdt.h>
int so_enable=7;
int s1_enable=6;
int s2_enable=5;
int enablepin=4;
int sensor_value0=0;
int sensor_value1=0;
int sensor_value2=0;
float  voltage0;
float voltage1;

float current_mux1[9];
float current_mux2[9];
float current_mux3[9];
float arduino_analog_scaling=0.004799608993157;
int row,column;
int digitalhigh=8;
int digitalhigh1=9;
static float  mux1_array[8]={
  0.0};
static float  mux2_array[8]={
  0.0};
  static float  mux3_array[8]={
  0.0};
 
 float current_value1[8]={0.0};
 float current_value2[8]={0.0};
int array[8][4]={
  {    0,0,0,0  }
  ,
  {    0,0,0,1  }
  ,
  {    0,0,1,0  }
  , 
  {    0,0,1,1  }
  ,
  {    0,1,0,0  }
  ,
  {    0,1,0,1  }
  ,
  {    0,1,1,0  }
  ,
  {    0,1,1,1  }
 

};

void setup()
{
  wdt_enable(wdto_8s);
  pinmode(so_enable, output) ;// pin can enable/disable using digital io 7 of arduino
  pinmode(s1_enable, output) ;// pin can enable/disable using digital io 6 of arduino
  pinmode(s2_enable, output) ;// pin can enable/disable using digital io 5 of arduino
  pinmode(enablepin, output) ;// pin can enable/disable using digital io 4 of arduino
  pinmode(a0, input) ;
  pinmode(a5, input) ;
  pinmode(digitalhigh,output);
  pinmode(digitalhigh1,output);
  serial.begin(9600);
/*  serial.print("channel\t");
 serial.print("mux1_v \t"); serial.print("mux1_c \t");
   serial.print("mux2_v \t"); serial.print("mux2_c \t");
   serial.print("mux3_v \t"); serial.println("mux3_c \t");*/
}

void loop()
{
  wdt_reset();
  digitalwrite(digitalhigh,high);
  digitalwrite(digitalhigh1,high);
  for(row=0;row<8;row++)
  {
    int k=(8*array[row][0]+4*array[row][1]+2*array[row][2]+1*array[row][3]);
   
   // serial.print("k:");
    serial.print(k);
    serial.print("\t");
    digitalwrite(enablepin,array[row][0]);
    digitalwrite(so_enable,array[row][1]);
    digitalwrite(s1_enable,array[row][2]);
    digitalwrite(s2_enable,array[row][3]);
   delay(500);
    sensor_value0=analogread(a0);
    sensor_value1=analogread(a3);
    sensor_value2=analogread(a5);
   

    mux1_array[row]=(sensor_value0 * 0.004398826979472141);
   
//   mux1_array[row]=(sensor_value0 * arduino_analog_scaling);
   mux2_array[row]=(sensor_value1 * arduino_analog_scaling);
   mux3_array[row]=(sensor_value2 * arduino_analog_scaling);
    current_mux1[row] = (mux1_array[row]*35.1428571429)-87.6571428571;
    current_mux2[row]=(mux2_array[row]*35.1428571429)-87.6571428571;
    current_mux3[row]=(mux3_array[row]*35.1428571429)-87.6571428571;
   
  serial.print( mux1_array[row]);serial.print("\t");serial.println( current_mux1[row]);//serial.print("\t");
//serial.print( mux2_array[row]);serial.print("\t");serial.print( current_mux2[row]);serial.print("\t");
//serial.print( mux3_array[row]);serial.print("\t");serial.println( current_mux3[row]);
 
 
  }
 serial.println("...................................................................");
/* serial.print("channel\t");
 serial.print("mux1_v \t"); serial.print("mux1_c \t");
   serial.print("mux2_v \t"); serial.print("mux2_c \t");
   serial.print("mux3_v \t"); serial.println("mux3_c \t");*/
 //delay(1000);
}


it's late  :smiley-sleep:

are trying use 251 pass analog voltage?


Arduino Forum > Using Arduino > Programming Questions > dIGITAL MUX PROGRAMMING


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code