FAQ & Terms of UseFAQ & Terms Of Use   Wiggler RadioMW Radio   Muff Wiggler TwitterTwitter   Support the site @ PatreonPatreon 
 SearchSearch   RegisterSign up   Log inLog in 

74HC165 over Arduino SPI
MUFF WIGGLER Forum Index -> Music Tech DIY  
Author 74HC165 over Arduino SPI
I need to read 80 digital inputs connected to push button switches with an arduino uno.
At first I thought about a 8x10 matrix (with diodes across each switch) using multiplexing, a 74HC595 on the columns + 2x digital output and a 74HC165 inputs on the rows to avoid using many uC pins.
Then I thought, why not using 10x 74HC165, and no multiplexing? It would take less time I think (you just transfer 10 bytes instead of testing 10 columns and transfer 1 byte for each of them, so 16 bytes in total).
Other advantages: less pins, pullup resistors instead of diodes.
Disadvantages: many ICs to solder, but that's not a problem since this is a one-time-only PCB.

I'm wondering, can I use Arduino SPI to speed up and to check the inputs during an interrupt?
If yes, do you think I need buffer IC on the SPI lines, since I'm using 10 ICs (assuming the PCB is not more than 16cm*16cm).
diodes (1N4148) are about the same price as a resistor, so that's no argument.
Use hardware spi, that is able to clock at 8Mhz
I have never used the 74HC165 so I'm not sure to have CPOL and CPHA correct, but you have to use them in daisy chain (output of first chip connect to input of second chip etc.) and sample them synchrone (tying all SH wires together)
code in setup:
SPCR = (1<<SPE) // SPI enable
|(1<<MSTR) //master mode
|(0<<CPOL) //setup rising
|(0<<CPHA) //sample falling
|(0<<SPR1); //fosc max
SPSR = (1<<SPI2X); //double frequency

and to transfer:
PORTB &= ~(1<<PB2); // drive CS low
SPDR = your_byte; // send which dac channel
while ( !(SPSR & (1<<SPIF))) {}; // ready?
PORTB |= (1<<PB2); // drive SS high again
yes, you can use 10 ICs and just clock the data in, its just more parts. if the board is large and the parts spread out, there could be some speed limitations due to capacitance of the traces, but it should be fine. a buffer IC could help here, but you probably wont need it. its just the clock and select lines that run the full length, the data line gets passed from IC to IC, so its already buffered. and you can poll the ICs in an interrupt, it will take around 200 clock cycles to complete, or 12us.
Have you considered using a GPIO SPI device ?.

Eg. the MCP23S17 gives you 16 I/O lines (halves your i/o device count), has internal pull-ups, can generate a pin change interrupt (saves polling the devices). You can link up to 8 of them. Easy enough to code for.
@gbiz thanks for posting that, ordered immediately some of those on a breakout board.

They even have interrupts:
There are two interrupt pins, INTA and INTB, that can be associated with their respective ports, or can be logically OR’ed together so that both pins will activate if either port causes an interrupt.
The interrupt output can be configured to activate under two conditions (mutually exclusive):
1. When any input state differs from its corresponding Input Port register state. This is used to indicate to the system master that an input state has changed.
2. When an input state differs from a preconfigured register value (DEFVAL register).
The Interrupt Capture register captures port values at the time of the interrupt, thereby saving the condition that caused the interrupt.
(source: datasheet)
I would go with the diode matrix configuration, and then use one 16 channel multiplexer connected to the 10 row lines, and one 8 bit shift register (parallel in, serial out) to read the 8 columns together. It requires only 2 ICs, 5 pins for the mux (enable pin, 4 control pins, you can tie the common one to either GND or VCC), and 3 pins for the shift register (data out, clock, latch for storing the data in the register before reading it).
A matrix w/diodes is the best (cheapest) solution, but
If this is a monosynth keyboard have you considered using a resistor ladder on an ADC? ...or multiple ADC channels?

Another (best) solution that will give 16 inputs MUX is the 4067 analog switch...more, 5 of them, all sharing the same 4 bit scan bus but each 4067 with it's own common input. That's 9 GPIO for your 80 switches.
The beauty of this setup is if the switches were pressure sensitive types, photocells, or double strike types (velocity), those 5 inputs could be to ADC's smile
MUFF WIGGLER Forum Index -> Music Tech DIY  
Page 1 of 1
Powered by phpBB © phpBB Group