Control CD4021 and 74HC595 over the same SPI bus

30/10/2011

Working on a project I needed extra digital in’s and extra digital out’s for my Arduino Uno (lots of LEDs, lots of buttons). I’ll use a CD4021 to extend the digital in’s and a 74HC595 to gain extra digital out’s. I decided it would be best to both access the data of the CD4021 and send data to the 74HC595 over the hardware SPI bus on the Arduino (see previous post). Turns out te be not that hard (fortunately ;) ). Here’s the eagle schematic for 1 4021 and 1 595. Of course you can cascade more IC’s if you need more in’s or out’s. Only difference is that you’ll have to interpret and send more bytes (1 byte per IC).

Here’s my Arduino code so far:

#include <SPI.h>

#define PIN_SCK          13             // SPI clock
#define PIN_MISO         12             // SPI data input
#define PIN_MOSI         11             // SPI data output
#define PIN_SS1          10             // SPI hardware default SS pin, 4021
#define PIN_595_1        9              // SPI 74HC595

// result byte for 4021
byte buttons8;

// global vars for button timeout and debounce
long button1timeout = 0;
long button2timeout = 0;
long debounce = 200;

void setup() {
  Serial.begin(9600);
  SPI.begin();

  // set all IC select pins HIGH
  digitalWrite(PIN_SS1,HIGH);
  pinMode(PIN_595_1, OUTPUT);
  digitalWrite(PIN_595_1,HIGH);
}

void loop() {

  // SS1 = HIGH -> 4021 is gathering data from parallel inputs

  // select 595
  digitalWrite(PIN_595_1,LOW);

  // send BIN number to 595 to light 1 LED (not necessarily the 1 example LED on the schematic)
  SPI.transfer(B00000100);

  // deselect 595
  digitalWrite(PIN_595_1,HIGH);

  // select 4021
  digitalWrite(PIN_SS1,LOW);
  // read CD4021 IC
  buttons8 = SPI.transfer(0x00);

  // button functions and debounces
  // needs refactoring for smaller footprint
  if((B10000000 & buttons8) && (millis() - button1timeout > debounce)) {
    Serial.println("but1");
    button1timeout = millis();
  }
  if((B01000000 & buttons8) && (millis() - button2timeout > debounce)) {
    Serial.println("but2");
    button2timeout = millis();
  }

  // deselect 4021
  digitalWrite(PIN_SS1,HIGH);
}

 

 

 

No Comments

Arduino, CD4021 and SPI

29/10/2011

The “ShiftIn” tutorial on the Arduino site (Parallel to Serial Shifting-In with a CD4021BE) is very clear on why and how to setup and test your Arduino in combination with a CD4021 IC. I needed extra digital inputs and decided to communicate via SPI with the CD4021 chip. Figured it out, it was actually pretty simple thanks to the easy SPI implementation in the Arduino software since version 0020 or so (?)

Setup as described in the Arduino tutorial. Reconnect the clock, the MOSI and the slaveselect as the #defines in the following code. And you’re all set.

#include

#define PIN_SCK          13             // SPI clock
#define PIN_MISO         12             // SPI data input
#define PIN_MOSI         11             // SPI data output
#define PIN_SS1          10             // SPI hardware default SS pin

void setup() {
  Serial.begin(9600);
  SPI.begin();
}

void loop() {
  digitalWrite(PIN_SS1,HIGH);

  // while gathering info from parallel inputs
  // do some other processing
  // for now I'll use
  delayMicroseconds(200);

  // select PIN_SS1 CD4021 IC
  digitalWrite(PIN_SS1,LOW);
  // read byte from CD4021 IC
  Serial.println(SPI.transfer(0x00),BIN);
}

tip: buy some resistor arrays instead of all individual resistors

No Comments

LCD optimizations and additions

25/10/2011

One of my first posts contains a LCD prototype. Today I needed LCD functionality and made some optimizations and additions to the LCD prototype.

Speed up

In the LCD3Wire library, I removed two delays:

131c131
<   //delay(1);
---
>   delay(1);
155c155
<   //delayMicroseconds(1);
---
>   delayMicroseconds(10);

This gives a good speed increase when using the LCD3Wire library. Furthermore, reading this post (http://solar-blogg.blogspot.com/2009/02/displaying-custom-5×8-characters-on.html) I copied the code to the Arduino and displayed my own custom character (using the LCD3Wire library)

lcd.commandWrite(0x40);
lcd.print(0b00000);
lcd.print(0b00100);
lcd.print(0b00010);
lcd.print(0b11111);
lcd.print(0b00010);
lcd.print(0b00100);
lcd.print(0b00000);
lcd.print(0b00000);
lcd.cursorTo(1,0);
lcd.print(0x00);

And another great LCD speedup trick by designer2k2 on the Arduino forums is to avoid using lcd.cursorTo. Instead use his direct positioning code

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1240088162

lcd.commandWrite(0x80);                //Line=1, Cursor 0
lcd.commandWrite(0xC0+val);            //Line=2, Cursor val
lcd.commandWrite(0x94+7);              //Line=3, Cursor 7
lcd.commandWrite(0xD4);                //Line=4, Cursor 0
No Comments

Impressed by Thor!

15/10/2011

Wow! I decided to give Reason 6 a good try. First of all I wanted to recreate the sound of my last analog prototype (see and listen to the previous post). Oh, here’s a picture of that prototype btw:

In Thor I recreated the sound of a single analog oscillator like so:

A single Analog Osc generating a sawtooth waveform, no filters, enveloppe only sustain. Sounds… the same! Listen for yourself:

ReasonanalogFLAC by sinneb

This recording was made via the buildin soundcard of my MacBook. Sound quality will improve when better audio interface hardware equipment is being used. The soundcloud conversion didn’t work out, not in PCM nor FLAC…

My soundcloud comment:

Tough upload, still sounds horrible. It’s not that important, just wanted to let you hear the hard-to-hear difference between my own VCO prototype and a construction in Propellerhead Reason’s Thor synthesizer.

No Comments

New synth in the works

19/07/2011

and here’s an audiofile with a sneak preview of one of the VCO’s.

vco1_test1

This sawtooth is generated through an orange drop capacitor (sounded better then its wima counterpart) in a 100% analog sound path. Reset pulses are generated by an Arduino and the rise of the sawtooth waveform is controlled by a MCP4921 DAC. Each frequencies requires an exact voltage to level out the sawtooth. I haven’t calibrated these voltages yet so the sawtooth isn’t very precise yet. I like the raw sound though!

1 Comment

beta juno106 filter replacement!

9/05/2011

Juno-106 filter replacement (beta, sounds very ok!) by sinneb


The filterpart, 4 pole low pass with resonance. Download LTSpice schematic file:

juno106BetaFilterReplacement_FilterPart (pdf version)

 

 

The exponential current source. Leave 10 ohm resistor out when connecting to filterpart. Download LTSpice schematic file:

juno106BetaFilterReplacement_ExpoPart (pdf version)

The VCA of this beta filter was built like the schematic supplied by Mooger5 (check older posts). The redesigned VCA based on a LM13700 should work also (check older posts).

No Comments

“tuned” the LPF

25/04/2011

Yesterday I tuned the LPF using my trusty old board o’ potentiometers…

Best sounding values came out like this:

which I, after some thinking, recognized as the original values like in the JUNO6! Very nice! Just had to replace the 100pF capacitor with a 240pF capacitor like in the original. Only thing missing is the “mystery resistor” on the + input of the OTA to ground. For now I just left this res out.

A fitting frequency range for the filter should be achieved by a good control current. According to the IR3109 specifications, transconductance should range from 1µƱ – 10mƱ. The expo converter from the previous post delivers a current ranging from 70nA to 1.65mA which translate to a transconductance of 1.34µƱ to 31mƱ. Ok for now.

I made a mockup of the JUNO6 board and the IR3109 ic:

No Comments

working combination!

23/04/2011

Got a working combination of the expo converter and the 1 pole low pass filter. Sounds nice, although the expo needs some tuning.

listen:

Juno106 1pole replacement filter, for now only cutoff by sinneb

No Comments

redesigned the expo converter, again

19/04/2011

The output current of the expo converter is now (100nA < Iabc < 2mA) which means a more logarithmic response of the VCF, more like the IR3109.

btw this is a one pole LP filter, not a two pole

VCF sound like this now:
Juno2poleFilter-v2 by sinneb

and here’s the real 2 pole LP filter:

Juno2poleFilter-v3-real2pole by sinneb

No Comments

2-pole LM13700 lowpass filter working?

18/04/2011

I’m not sure. Did a lot of prototyping and these are the results.

Since I couldn’t figure out a proper way to calculate the cutoff frequency when using different current and resistor combination, I decided to use the default lowpass filter circuit from the LM13700 datasheet.

Hooked my expo converter up to pin 1 (100nA < Iabc < 1.1mA) and started testing. The Vout of this pole is the Vin of the second pole. Unfortunately I only had 1 LM13700 working left, since I blew up all my other’s ;). I experimented a lot with different capacitor and resistor combination and the only ok sounding combination is a 1nF capacitor with 10K big and 220Ohm small resistors. Check the following sound files for the results:

Juno2polefilter by sinneb

Oh, just for fun: a pic of the breadboard in action

left bottom: BA6110 based VCA. Right top: dual 2N3906 based expo converter. Right bottom: Only remaining LM13700 configured as a 2-pole lowpass filter.

No Comments