1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

daisy chain two 74hc165 to read paralell data ,serialy.

Discussion in 'AVR' started by tony64, Mar 14, 2017.

  1. tony64

    tony64 New Member

    Joined:
    Mar 4, 2017
    Messages:
    14
    Likes:
    0
    My problem is how to read these bits which comes to 16 bits(2 bytes)?then send these bytes serially out to parallel out puts.To explain more suppose we have 16 push button that is input to two shift register and on the out put we will get them serially,but to keep the push buttons pressed alive and active ,we have to some how keep them on (say if they are led) ,what I have done is sending back the bytes we get serialy through SIPO(595)and a driver (ULN) to the paralell inputs.
    I have made some codes but do not work.
     
  2. SPDCHK

    SPDCHK Member

    Joined:
    May 26, 2006
    Messages:
    446
    Likes:
    17
    Location:
    South Africa
    • Like Like x 2
  3. tony64

    tony64 New Member

    Joined:
    Mar 4, 2017
    Messages:
    14
    Likes:
    0
    I am using atmega32 and C in codevision.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. wkrug

    wkrug Active Member

    Joined:
    May 30, 2010
    Messages:
    280
    Likes:
    29
    Location:
    Germany

    I think that could not work.
    When hold down the level of the switch input with the ULN Chip, the controller always will read a low level in spite of the switch isn't pressed.
    I would seperate the input circuit from the output circuit.
    One shift register bank will read the switches ( input ), another Bank will handle the Outputs.
    The Controller read the switches and handle the outputs depending of the readed switch positions.

    Another possible way is to switch the output off for a short time, then read the input shift register and set the output again.
    But that make a short interruption of output supply.

    Could You post a schematic please?
     
    Last edited: Mar 16, 2017
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,250
    Likes:
    911
    Location:
    Rochdale UK
    Why do you use a ULN on switched inputs??? The signal will not be more than a couple of mA's..

    Do the switches switch anything else?
     
  7. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,250
    Likes:
    911
    Location:
    Rochdale UK
    This is unclear.... Do you mean outputs...

    Scenario

    16 switched bits ->two chained 165 -> AVR.... PROCESS ... AVR -> two chained 595 -> 16 LED's
     
  8. tony64

    tony64 New Member

    Joined:
    Mar 4, 2017
    Messages:
    14
    Likes:
    0
    Scenario

    16 switched bits ->two chained 165 -> AVR.... PROCESS ... AVR -> two chained 595 -> 16 LED's[/QUOTE]
    Yes this is in fact the scenario :When we press the key in the inputs(by connecting them to grnd.)the led in the input dose not stay on,once you release the push button ,it goes off ,So what we like to do is to keep them on and wait for the next instruction.we are using uln because this is the hardware we have on hand and can not chage it. we have to write the program for this hardware and these uln should switch other things.
    I have included an schematic (rough).for you.I have also some code written and it works up to a stage which reads the inputs ,but to send the read switches back to input to keep the leds on is not working.
     

    Attached Files:

  9. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,250
    Likes:
    911
    Location:
    Rochdale UK
    Normally you read the switches and if there is a button press you can the latch the LED in software... The button needs to go through each state....

    Off-> On...or On -> Off...

    Only when it goes off to on set/reset a latch.. This means the switch ahas to be released and re=pressed for the LED to be changed.. I normally save the switch state and add in the new state to see if the correct transition has occurred.. Take a switch...
    ON or OFF.. = 1 or 0
    move the switch to the second bit in a byte( shift left ) and add the new switch.

    we get

    0:0 was off... still off
    0:1 was off... now on
    1:1 was on... still on
    1:0 was on now off.

    so if we take the last two bits 01 is the only combo we need..
    Code (c):

    state<<=1;  // Shift the old switch pos
    state += sw  & 0x3;  // add the new switch pos and clear all but the last two digits
    if(state==1)  LED = ~LED; // only if the state was 1, toggle the LED..
     
     
    • Like Like x 1
  10. tony64

    tony64 New Member

    Joined:
    Mar 4, 2017
    Messages:
    14
    Likes:
    0
    I am thinking about what you said..
    but the problem is we have two bytes,not one byte.
    and the other point is this software instruction should go thorough 595 ,should it not?
    Let me send you a part of my code :(sorry don,t know how to put it in code box).
    Code (c):

     void HC165_readSerialData(uint8_t serial_data[])
    {
      uint8_t buttons[2] = {0, 0};
        uint8_t i,j;
        uint8_t _byte;
     
        /* Pulse LD low and then high to load parallel data */
        PORTC.3=0;//LD_LOW;
        delay_ms(1);
        PORTC.3=1;//LD_HIGH;

        /* For each '165... */
        for (i = 0; i <= 2; i++)
         {
            _byte = 0;
            /* ...read the serial out data */
            for (j =0; j <= 7; j++) {
                _byte <<= 1;    //shifts a reasonably expensive,so we only do one shift per loop
                if (PIND.5 & (1<<QH_PIN))
                   {
                       _byte |=1;  //then we conditionally set the lsb
                     
                   }
                PORTD.7=0;//CLKINH_LOW;
                delay_ms(1);
                PORTD.7=1;//CLKINH_HIGH;
                 if(PIND.5==0)
                          {
                           LCDprint("0");
                          delay_ms(10);
                       
                          }
                      else if(PIND.5==1)
                          {
                                                                                                                                                                                                                         
                          LCDprint("1");
                          delay_ms(10);
                         
                          }
            }
            serial_data[I] = _byte;
           
           }

        /* Disable clocking now */
        CLKINH_HIGH;    //got me beat why you need to inhibit the clock - I'd just tie it low and save a port pin
    }


       uint8_t buttons[2] = {0, 0};
       
       int i=0;unsigned char out;unsigned char data; // uint8_t register_value;
    void main(void)
       {
        DDRA=0xff;
        DDRB=0xff;
        DDRC=0b00001100;
        DDRD=0b11011111;
        // PORTB.4=0; //buzer
        // delay_ms(200);
         PORTB.4=1;
         PORTA.7=1;
         PORTA.1=0;
         PORTC.2=0;
         SET_HC165_DDR;
        SET_QH_PULLUP;
           
         LCDinit();
         delay_ms(10);
           
             LCDcmd(0x01);
               
        while(1)
        {    
         
            HC165_readSerialData(buttons);
            delay_ms(1000);
           
             LCDcmd(0x01);  
             delay_ms(1000);
         }
         }
     
    [/I]
     
    Last edited by a moderator: Mar 19, 2017
  11. tony64

    tony64 New Member

    Joined:
    Mar 4, 2017
    Messages:
    14
    Likes:
    0
    unfortunately I could not succeed in transferring back the data I get serially.
     

Share This Page