Monthly Archives: October 2015

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.