Daily Archives: October 17, 2015

Arrival of the DE0-Nano

Published by:

My DE0-Nano finally arrived from Terasic,

this cute little development board cost me about $60 (or $100 without student discount), I had to wrangle a bit with FedEx to get it (You wait in all day for them, but the second you step out they arrive) but it’s finally here

I’m not the biggest fan of unboxing videos (mainly because I get jealous of what people unwrap) but I decided to throw one up to show everyone what you get and compare it to my old DE1 which I got about 5 or 6 years ago.

This board is not recommended for those unfamiliar with Altera technology or even FPGA/CPLD technology in general, it doesn’t come with a huge array of flashy lights or switched, if you want that then go for the DE0 (non-nano flavour) or if you want the full experience, look at the DE2 kit’s, they have plenty to play with. This one is designed for those who want to specifically attach their own circuits.

The De0-Nano consists:

  • Altera Cyclone IV FPGA which contains about 22,320 Logic Elements, 4 PLL’s, among other things.
  • 32MB SDRAM
  • 2Kb I2C EEPROM
  • 8 LED’s (Green), 2 pushbuttons, and 4 switch dipswitch.
  • ADI ADXL345 13-Bit 3-axis high resolution accelerometer
  • NS ADC128S022 12-Bit x 8-Channel ADC up to 200ksps

All in all, some nice toys to play with in a small package.

I’ll be definitely playing with this board and doing some more videos and blogs about it.

More info about the DE0-Nano can be found here on Terasic’s DE0-Nano page

PSU Project #7 – LCD’s

Published by:

September 19th 2015
In this quick video we discuss the use of LCD’s on the Arduino board.
The LCD’s we use are the standard 16×2 Hitachi based alphanumeric display and a 84×48 Nokia 3310 display.

PSU Project #7 – LCD’s

Hitachi based LCD:
Hitachi LCD to Arduino
This is the wiring diagram of the setup used in the demonstration of the Hitachi based LCD.
This Hitachi based display is a very commonly used display type, there is a library in the Arduino IDE by standard under the name of LiquidCrystal and there is example code that is used. Should I find myself restricted on space inside the Arduino then I may consider using this display as the character set is hardcoded into the Hitachi controller on the module thus saving us space in the code.
Nokia 3310 display:
Nokia 3310 LCD to Arduino
This is the wiring diagram of the setup used in the demonstration of the Nokia 3310 display.

The Nokia 3310 display uses a Philips PCD8544 driver chip but since it was mostly used in the Nokia 3310 cell-phone it is more commonly known by that name.

Example code for this display can be found here at the Arduino playground site. (opens in new window)
This is the code that I used in the demonstration. I did however make changes to the code:
The lines that read:
#define PIN_SDIN  4
#define PIN_SCLK  3

Were changed to:

#define PIN_SDIN  11
#define PIN_SCLK  13
This allowed it to work it my wiring shown above.
Note: I have since moved it back to pins 4 and 3, it seems to be fine now. I decided to do this to ensure that 11 and 13 were available for SPI communications on normal (non-mega) Arduino’s, this is important as I’m going to base most of it around the Arduino Nano.

PSU Project #6 – Operational Amplifiers

Published by:

September 30th 2015
In this video I will briefly be discussing the Operational Amplifier and it’s functions.
I will be covering the basic configurations that may be used in out power supply design.
This is by no means an exhaustive lesson on OPAMP’s, that would take many hours of video footage and knowledge that I do not possess at this point in time, but it should be sufficient enough to allow a beginner to start using them in circuits.

PSU Project #6 – Operational Amplifiers

Open loop:
  Vout = ((IN+)-(IN-))*Aol
  Aol is the gain of the OPAMP
Negative feedback:
  Vout = -(Rf/Ri)*Vin
Positive feedback
Vout = (1+(Rf/Ri))*Vin
Multi-Channel / Summing Amplifier
Vout = (-(Rf/Ri1)*Vin1) + (-(Rf/Ri2)*Vin2)
          further stages can be added if needed, just add them at the end of the formula.
Unity Gain / Buffer
Vout = Vin
Differential Amplifier
Vout = (Vin2-Vin1)*(Ra/Rb)

PSU Project #5 – Arduino SPI

Published by:

September 19th 2015
In this video I get the hardware SPI up and running on the Arduino and write code for the MCP3304 and MCP4822
The example Arduino code further down the page will read channel 0 of the ADC and output it to both channels of the DAC.
I recorded this with a Sony DCR-SR300 camcorder I borrowed from the college, turns out that it’s not a HD recorder. I didn’t realize this until I was nearly done editing. I will make sure I get a HD camera for next time.

Arduino code (can be downloaded here):
#include "SPI.h"

#define DAC_CS 9 // DAC chip-select
#define ADC_CS 10 // ADC chip-select

void setup() {
 //set pin modes 
 pinMode(DAC_CS, OUTPUT); 
 pinMode(ADC_CS, OUTPUT); 
 // disable all devices to start with 
 digitalWrite(ADC_CS, HIGH); 
 digitalWrite(DAC_CS, HIGH); 
 SPI.begin();
 Serial.begin(115200); 
 Serial.println("Ready.");
}

void set_dac(byte chan, unsigned int value,byte ga, byte shdn)
{
 byte b,c,conf;
 // ga : 0=2x (0-4096v), 1=1x (0-2.048v)
 // shdn : 0 = shutdown DAC channel, 1 = output available
 // [ A'/B , x , GA', SHDN', D11, D10, D9, D8 ]
 conf=(chan&0x01)<<7; // mask out channel number and shift it to bit 7
 conf=conf|(ga&0x01)<<5; // mask out gain select and shift it to bit 5 and or it to conf
 conf=conf|(shdn&0x01)<<4; // mask out shutdown select and shift it to bit 4 and or it to conf
 conf=conf|(value>>8); // or in the top nibble of value left in conf
 b = value; // bottom byte of value
 SPI.beginTransaction(SPISettings(15000000, MSBFIRST, SPI_MODE0));
 digitalWrite (DAC_CS, LOW); // enable DAC
 SPI.transfer(conf); // send configuration and top nibble of value
 SPI.transfer(b); // send bottom byte
 digitalWrite (DAC_CS, HIGH); // disable DAC
 SPI.endTransaction();

}

unsigned int get_adc(byte chan)
{
 unsigned int a,b,c,conf;
 conf=conf=((chan&0b00000111)<<1)|0b00110000; // create configuration byte
 SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
 digitalWrite (ADC_CS, LOW); // enable ADC
 SPI.transfer(conf); // send configuration byte
 b = SPI.transfer(0x00); // receive sign bit & top 4 bits 
 c = SPI.transfer(0x00); // receive lower 8 bits
 digitalWrite (ADC_CS, HIGH); // disable ADC
 SPI.endTransaction();
 b = b&0b00011111; // filter out unwanted stuff from high byte
 a = (b*0x100)+c; // convert 2 8-bit numbers into a single 16-bit number
 return(a);
}

unsigned int get_adc_avg(byte chan)
{
 long tempx = 0;
 byte ax = 0;
 for (ax=0;ax<10;ax++)
 {
 tempx+=get_adc(chan);
 }
 tempx/=10;
 return (tempx);
}

void loop() 
{
 unsigned int xx;
 set_dac(0, (get_adc_avg(0)/2),0, 1);
 set_dac(1, (get_adc_avg(0)/2),0, 1);
}

PSU Project #3 – MCP4822

Published by:

(Transplanted from old website)

August 31st 2015:

In this episode we investigate the MCP4822 12-Bit DAC.
This is another digital building block for the PSU design, this component will allow us to set the voltage level and the current limit for the circuit digitally.
Below is the schematic used in this episode. It builds upon the one from episode #1
In the episode, I explain how the internals of the DAC work and introduce the concept of an R-2R ladder.

PSU Project #3 – MCP4822

Sketch used in the episode (can be downloaded here):

/*
 Test sketch for the MCP3304 and MCP4822
 Both are bit-banged to get them working.
 In this demo:
 DAC channel A will count up from 0v to 4.096V
 DAC Channel B will mirror what is being read on ADC Channel 0
 Arduino   MCP3304   MCP4822
 */
 #define ADC_CS 10    // ADC chip-select
 #define DAC_CS 9    // DAC chip-select
 #define ADC_MOSI 11   // ADC_MOSI
 #define ADC_MISO 12    // ADC_MISO
 #define SPI_CLK 13  // Clock
 #define MCP4822_DAC_A_BUFFERED_GAIN_1X_NON_SHDN      0x70  // DAC A, Buffered, Gain 1x, Output power control
 #define MCP4822_DAC_A_BUFFERED_GAIN_2X_NON_SHDN      0x50  // DAC A, Buffered, Gain 2x, Output power control
 #define MCP4822_DAC_A_NON_BUFFERED_GAIN_1X_NON_SHDN  0x30  // DAC A, Non buffered, Gain 1x, Output power control
 #define MCP4822_DAC_A_NON_BUFFERED_GAIN_2X_NON_SHDN  0x10  // DAC A, Non buffered, Gain 2x, Output power control
 #define MCP4822_DAC_B_BUFFERED_GAIN_1X_NON_SHDN      0xF0  // DAC B, Buffered, Gain 1x, Output power control
 #define MCP4822_DAC_B_BUFFERED_GAIN_2X_NON_SHDN      0xD0  // DAC B, Buffered, Gain 2x, Output power control
 #define MCP4822_DAC_B_NON_BUFFERED_GAIN_1X_NON_SHDN  0xB0  // DAC B, Non buffered, Gain 1x, Output power control
 #define MCP4822_DAC_B_NON_BUFFERED_GAIN_2X_NON_SHDN  0x90  // DAC B, Non buffered, Gain 2x, Output power control
int test2=0;
 long test3=0;
void pulse_MCP_clock(void)
 {
 digitalWrite(SPI_CLK, LOW); delayMicroseconds(50);
 digitalWrite(SPI_CLK, HIGH); delayMicroseconds(50);
 }
long read_MCP(int channel)
 {
 long value=0;
 signed int x=0;
 digitalWrite(ADC_CS, LOW);
 digitalWrite(DAC_CS, HIGH);
 delayMicroseconds(50);
 digitalWrite(ADC_CS, LOW);
 delayMicroseconds(50);
 digitalWrite(ADC_MOSI, HIGH); //start pulse
 pulse_MCP_clock();
 digitalWrite(ADC_MOSI, HIGH); //single mode
 pulse_MCP_clock();
 for(x=2; x>=0; --x)
 {
 if(bitRead(channel,x))
 {
 digitalWrite(ADC_MOSI, HIGH);
 }
 else
 {
 digitalWrite(ADC_MOSI, LOW);
 }
 pulse_MCP_clock();
 }
 digitalWrite(ADC_MOSI, LOW);//put low throughout
 for(x=1;x<=3;++x)
 {
 //blank, Null, and sign bit (always 0 in single mode)
 pulse_MCP_clock();
 }
 //now get twelve bits
 for(x=11; x>=0; --x)
 {
 pulse_MCP_clock();
 if (digitalRead(ADC_MISO))
 {
 bitSet(value,x);
 }
 else
 {
 bitClear(value,x);
 }
 }
 digitalWrite(ADC_CS, HIGH);
 digitalWrite(DAC_CS, HIGH);
 return value;
 }
void init_ADC(void)
 {
 digitalWrite(SPI_CLK,HIGH); //clock
 digitalWrite(ADC_MISO, LOW); //output -- supposed to be float but not sure how to do this on Arduino
 digitalWrite(ADC_MOSI, HIGH); //input
 digitalWrite(ADC_CS, HIGH);
 delayMicroseconds(50);
 digitalWrite(ADC_CS, LOW);
 delayMicroseconds(50);
 digitalWrite(ADC_CS, HIGH);
 digitalWrite(DAC_CS, HIGH);
 }
int get_adc_avg(int channel)
 {
 long tempx = 0;
 byte ax = 0;
 for (ax=0;ax<10;ax++)
 {
 tempx+=read_MCP(channel);
 }
 tempx/=10;
 return (tempx);
 }
void mcp4822_init() {
 digitalWrite(DAC_CS,HIGH);
 digitalWrite(SPI_CLK, LOW);
 digitalWrite(ADC_CS,HIGH);
 digitalWrite(ADC_MOSI, LOW);
 }
void mcp4822_write(byte control,int data) {
 byte i;
 int tempx=0x00;
 tempx = data|(control<<8);
 digitalWrite(ADC_CS,HIGH);
 delayMicroseconds(10);
 digitalWrite(SPI_CLK,LOW);
 delayMicroseconds(10);
 digitalWrite(DAC_CS,LOW);
 delayMicroseconds(10);
 digitalWrite(ADC_MOSI,LOW);
 for(i=16;i>0;--i)
 {
 digitalWrite(SPI_CLK,LOW);
 digitalWrite(ADC_MOSI,bitRead(tempx,i-1));
 digitalWrite(SPI_CLK,HIGH);
 }
 digitalWrite(DAC_CS,HIGH);
 delayMicroseconds(10);
 }
void setup() {
 //set pin modes
 pinMode(ADC_CS, OUTPUT);
 pinMode(DAC_CS, OUTPUT);
 pinMode(ADC_MOSI, OUTPUT);
 pinMode(ADC_MISO, INPUT);
 pinMode(SPI_CLK, OUTPUT);
 init_ADC();
 mcp4822_init();
 digitalWrite(ADC_CS, HIGH);
 digitalWrite(DAC_CS, HIGH);
 Serial.begin(115200);
 Serial.print("Hello2"); // Just to show the serial is working
 }
void loop() {
 int tempx2 = 0;
 if (test3++>0xFFF) test3=0;
 tempx2 = read_MCP(0);
 mcp4822_write(MCP4822_DAC_A_NON_BUFFERED_GAIN_2X_NON_SHDN, test3);
 mcp4822_write(MCP4822_DAC_B_NON_BUFFERED_GAIN_2X_NON_SHDN, tempx2);
 delay(10);
 }

PSU Project #1 – MCP3304

Published by:

(Transplanted from old website)
August 9th 2015:
This is the first episode of the series, since it’s an odd numbered episode we will be discussing digital things.
The MCP3304 is a 13-Bit ADC. The 13th bit is the sign bit for when in differential mode, but since we are using single ended we will be getting our results in 12-Bit format.
This episode is about 11 minutes long, I would eventually like to make longer episodes but I’m still finding my feet with it all. If I keep the episodes short it will allow me to get more of them out regularly as it won’t take as long for me to edit and annotate them, but we will see what happens as we progress.
This is the wiring of the MCP3304 and it’s reference and the connections to the Arduino as refered to in the video. I show a schematic with the MCP4822 DAC in the video, but this is the same schematic without the DAC.

PSU Project #1 – MCP3304

For those who are playing along at home, here is the Arduino code for testing the MCP3304:
 code can be found here
#define ADC_CS 10    // chip-select
#define ADC_MOSI 11   // ADC_MOSI 
#define ADC_MISO 12    // ADC_MISO 
#define SPI_CLK 13  // Clock
 
void pulse_MCP_clock(void)
{
  digitalWrite(SPI_CLK, LOW); delayMicroseconds(50);
  digitalWrite(SPI_CLK, HIGH); delayMicroseconds(50);
}
 
long read_MCP(int channel)
{
  long value=0;
  signed int x=0;
  digitalWrite(ADC_CS, HIGH);
  delayMicroseconds(50);
  digitalWrite(ADC_CS, LOW);
  delayMicroseconds(50);
  digitalWrite(ADC_MOSI, HIGH); //start pulse
  pulse_MCP_clock();
  digitalWrite(ADC_MOSI, HIGH); //single mode
  pulse_MCP_clock();
  for(x=2; x>=0; --x)
  {
    if(bitRead(channel,x))
    {
      digitalWrite(ADC_MOSI, HIGH);
    }
    else
    {
      digitalWrite(ADC_MOSI, LOW);
    }
    pulse_MCP_clock();
  }
  digitalWrite(ADC_MOSI, LOW);//put low throughout
  for(x=1;x<=3;++x)
  {
    //blank, Null, and sign bit (always 0 in single mode)
    pulse_MCP_clock();
  }
  //now get twelve bits
  for(x=11; x>=0; --x)
  {
      pulse_MCP_clock();
      if (digitalRead(ADC_MISO))
      {
         bitSet(value,x);
      }
      else
      {
         bitClear(value,x);
      }
  }
  digitalWrite(ADC_CS, HIGH);
  delayMicroseconds(10);
  return value;
 }
 
 void init_ADC(void)
 {
  digitalWrite(SPI_CLK,HIGH); //clock
  digitalWrite(ADC_MISO, LOW); //output -- supposed to be float but not sure how to do this on Arduino
  digitalWrite(ADC_MOSI, HIGH); //input
  digitalWrite(ADC_CS, HIGH);
  delayMicroseconds(50);
  digitalWrite(ADC_CS, LOW);
  delayMicroseconds(50);
 }
 
int get_adc_avg(int channel)
{
  long tempx = 0;
  byte ax = 0;
  for (ax=0;ax<10;ax++)
  {
    tempx+=read_MCP(channel);
  }
  tempx/=10;
  return (tempx);
}
 
void setup() {
   //set pin modes 
  pinMode(ADC_CS, OUTPUT); 
  pinMode(ADC_MOSI, OUTPUT); 
  pinMode(ADC_MISO, INPUT); 
  pinMode(SPI_CLK, OUTPUT); 
  
  init_ADC();
  // disable device to start with 
  digitalWrite(ADC_CS, HIGH); 
  Serial.begin(115200); 
  Serial.print("Hello2");
}
 
void loop() {
  // put your main code here, to run repeatedly:
  int tempx = 0;
  tempx = get_adc_avg(0);
  Serial.print("In = ");
  Serial.println(tempx,HEX);
  delay(50);
}

PSU Project #0 – Intro

Published by:

(Transplanted from old website)
August 9th 2015:

Yesterday I launched my new series on YouTube for my PSU Project with episode #0.

It was an introduction to the new series in which I explained the way in which I will be approaching the design for the PSU. The will be parts for the Digital side and parts for the Analogue side with the eventual combining of both parts to create the final design. And if there is enough interest at the end of it, I may further extend into option expansions and computer control.
I may eventually expand to a 3rd section which deals with a Java interface that will run on PC, Mac, Linux machines.
It is aimed to have all odd numbered episode for digital, and even for analogue until we get to the stage we combine. This may change as we go along, but time will tell 🙂

If your interested in following along, I will be using these main parts (at least to begin with):
Digital section:
  • An Arduino or Clone
  • MCP3304 – 13-Bit ADC
  • MCP4822 – 12-Bit DAC
  • MCP1541 – 4.096V reference for ADC (MAX6029 4.096V version or similar can be used in it’s place)
  • Hitachi Compatible display
Analogue section:
  • 2N3055
  • LM324 Quad-OPAMPs
  • LM358 Dual-OPAMPs

Welcome to 39K

Published by:

Welcome to 39K, here you will find many things related to electronics, as well as some other things that are not.

On this site I will be hosting the pages for the power supply project that I am currently showing on my YouTube channel.

This site is currently being built up so more will be following shortly, thanks for stopping by.