Translate

Tuesday, 25 August 2015

Request from Raminda Subhashana - Arduino astronomical clock controller with over-ride! De-luxe!

Well, I've not always got time for this sort of thing, but one of my readers, Raminda has sent a request in...

Hi, Nice project Just checked it is working, perfect appreciate that. One thing I need to add Button to off light manually in Auto mode, but it should switch on automatically next day. please help me to add it. Thanks. on Pond Pump Controller Update!

Thanks Raminda, a great idea. Sometimes it's difficult to fathom things out, especially when you are trying to learn, and don't have anyone to ask.

OK, so it looks like Raminda is using my Pond pump controller to switch on and off some lights during the night. Great idea.

So, we'll need to add a push button in to switch our over-ride on. A1 isn't doing anything, so we'll hook up a momentary push button (S1) to pin A1 and GND. That's all the hardware we'll need to modify (Note I've made some amendments to the diagram from previous)



Then , we need to think about the code. We'll need to define a flag to control the status of our over-ride. We'll set it to false to start with,

// Over-Ride feature flag for Raminda Subhashana
boolean OverRideFlag = false;

OK. Now we need to tell the arduino what we need pin A1 to be doing... Add this line to the setup..




    pinMode(A1,INPUT);// Over ride push button connected to A1 (and GND)
    digitalWrite(A1,HIGH);


This tells the arduino that A1 is an input, and we want to pull it high when the button is open circuit.

Now in the Loop we need to check the status of the button.

       buttonstate = digitalRead(A1);// check to see if our override button is pressed, if it is, set the flag
       if (buttonstate == LOW ) {
         OverRideFlag=true;
       }        

Here we set the temporary variable buttonstate (also used elsewhere) to the value of A1, if it's low, we set our OverRideFlag to be true.

Finally we need to check the status of the flag, when we come to set the status of the relay, so we need to modify two lines of code...

      if (TimeMins >= Sunrise && TimeMins <=Sunset+60 && tempC>=2 && OverRideFlag==false) { //If it's after sunrise and before sunset + 1 hour, and it's not frozen, and our override isn't set, switch our relay on

I think the comment there is self-explanitory!

We also need to reset the flag once the sun comes up again:
    // Reset Override flag if the sun is up!
    if (TimeMins == Sunrise) {
      OverRideFlag = false;
    }

There's no need to specifically set the relay off, as this is taken care of in the else statement.

So, there you go Raminda, but I have a concern. What if we change our mind? What happens if we want to un-overide it?!?!

ahh... OK , we can change the code slightly to flip the status of the flag everytime the button is pressed.. ON-OFF-ON-OFF  etc . This might suffer with switch bounce, in which case we'll need a slight delay, but it worked ok with me (because of the delay in the loop).

       buttonstate = digitalRead(A1);// check to see if our override button is pressed, if it is, change the status of the flag
       if (buttonstate == LOW ) {
         OverRideFlag = ~OverRideFlag;
       }       
The ~ sign means NOT and is a boolean operator. So our flag is now NOT what it was before, so flips from true to false, or false to true!
The whole code should now look like this:
// Dawn & Dusk controller with frost protection. A special revision for Raminda Subhashana to control some lights.
// 5th December 2014. Modified 17th April 2015. Modified 25 August 2015
// (C) A.G.Doswell 2014 & 2015
// License: The MIT License (See full license at the bottom of this file)
//
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
//
// Designed to control a relay connected to pin A3. Pin goes low during daylight hours and high during night. Relay uses active low, so is
// "On" during the day. This is connected to the fountain pump in my garden.
//
// Time is set using a rotary encoder with integral push button. The Encoder is connected to interrupt pins D2 & D3 (and GND), 
// and the push button to pin analogue 0 (and GND)
// The RTC is connections are: Analogue pin 4 to SDA. Connect analogue pin 5 to SCL.
// A 2 x 16 LCD display is connected as follows (NOTE. This is NOT conventional, as interrupt pins are required for the encoder)
//  Arduino LCD  
//  D4      DB7
//  D5      DB6
//  D6      DB5
//  D7      DB4
//  D12     RS
//  D13     E
// 
// In this revision, there is a Dallas 18B20 Temperature sensor connected to pin 8, enabling frost protection. This is pulled up to +5volts via a 4.7K resistor.
//
// Use: Pressing and holding the button will enter the clock set mode (on release of the button). Clock is set using the rotary encoder. 
// The clock must be set to UTC.
// Pressing and releasing the button quickly will display the current sun rise and sun set times. Pressing the button again will enter the mode select menu. 
// Modes are AUTO: On when the sun rises, off when it sets.
//           AUTO EXTEND : same as above but goes off 1 hour after sunet (nice for summer evenings!) 
//           ON: Permanently ON
//           OFF: Permanently OFF (Who'd have guessed it?)
//
// Change the LATTITUDE and LONGITUDE constant to your location.
// Use the address finder from http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html to find the address of your temperature sensor and enter it where required in DeviceAddress.
// 28th Dec 2014 - Slowed the rate at which the temperature is requested down to once per minute. It has improved the clock display, and solved an issue whereby the temp sensor wasn't always ready to send data, and hung up.
// 10th Jan 2015 - Altered the method of updating the temp to something simpler and more sensible!
// 17th April 2015 - Stored Mode settings in EEPROM
//
// Be sure to visit my website at http://andydoz.blogspot.com

#include <Wire.h>
#include "RTClib.h" // from https://github.com/adafruit/RTClib
#include <LiquidCrystal.h>
#include <Encoder.h> // from http://www.pjrc.com/teensy/td_libs_Encoder.html
#include <TimeLord.h> // from http://swfltek.com/arduino/timelord.html. When adding it to your IDE, rename the file, removing the "-depreciated" 
#include <OneWire.h> // from http://playground.arduino.cc/Learning/OneWire
#include <DallasTemperature.h> // from http://www.hacktronics.com/code/DallasTemperature.zip. When adding this to your IDE, ensure the .h and .cpp files are in the top directory of the library.
#include <EEPROM.h> 

#define ONE_WIRE_BUS 8 // Data wire from temp sensor is plugged into pin 8 on the Arduino
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices
DeviceAddress outsideThermometer = { 0x28, 0x1A, 0x1A, 0x3E, 0x06, 0x00, 0x00,0xC7 }; // use the address finder from http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html to find the address of your device.
RTC_DS1307 RTC; // Tells the RTC library that we're using a DS1307 RTC
Encoder knob(2, 3); //encoder connected to pins 2 and 3 (and ground)
LiquidCrystal lcd(12, 13, 7, 6, 5, 4); // I used an odd pin combination because I need pin 2 and 3 for the interrupts.
//the variables provide the holding values for the set clock routine
int setyeartemp; 
int setmonthtemp;
int setdaytemp;
int sethourstemp;
int setminstemp;
int setsecs = 0;
int maxday; // maximum number of days in the given month
int TimeMins = 0; // number of seconds since midnight
int TimerMode = 2; //mode 0=Off 1=On 2=Auto
int TimeOut = 10;
int TimeOutCounter;

// These variables are for the push button routine
int buttonstate = 0; //flag to see if the button has been pressed, used internal on the subroutine only
int pushlengthset = 3000; // value for a long push in mS
int pushlength = pushlengthset; // set default pushlength
int pushstart = 0;// sets default push value for the button going low
int pushstop = 0;// sets the default value for when the button goes back high

int knobval; // value for the rotation of the knob
boolean buttonflag = false; // default value for the button flag
float tempC; // Temperature

// Over-Ride feature flag for Raminda Subhashana
boolean OverRideFlag = false;


const int TIMEZONE = 0; //UTC
const float LATITUDE = 20.00, LONGITUDE = -2.00;  // set YOUR position here 
int Sunrise, Sunset; //sunrise and sunset expressed as minute of day (0-1439)
TimeLord myLord; // TimeLord Object, Global variable
byte sunTime[]  = {0, 0, 0, 1, 1, 13}; // 17 Oct 2013
int SunriseHour, SunriseMin, SunsetHour, SunsetMin; //Variables used to make a decent display of our sunset and sunrise time.
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.

void setup () {
    //Serial.begin(57600); //start debug serial interface
    Wire.begin(); //start I2C interface
    RTC.begin(); //start RTC interface
    lcd.begin(16,2); //Start LCD (defined as 16 x 2 characters)
    lcd.clear(); 
    pinMode(A0,INPUT);//push button on encoder connected to A0 (and GND)
    digitalWrite(A0,HIGH); //Pull A0 high
    pinMode(A1,INPUT);// Over ride push button connected to A1 (and GND)
    digitalWrite(A1,HIGH);
    pinMode(A3,OUTPUT); //Relay connected to A3
    digitalWrite (A3, HIGH); //sets relay off (default condition)
    sensors.begin();
    sensors.setResolution(outsideThermometer, 12); // set the resolution to 12 bits (why not?!)
    
    //Checks to see if the RTC is runnning, and if not, sets the time to the time this sketch was compiled, also sets default mode to 2 and writes to EEPROM
    DateTime now = RTC.now();
    lcd.clear();
    lcd.print("Waiting for RTC");
    delay (60000);// wait a minute for the RTC to sort itself out.
    if (! RTC.isrunning()) {
    RTC.adjust(DateTime(__DATE__, __TIME__));
    EEPROM.update (0,0); // set the auto mode as 0 (off) for default
    }
  
 
   lcd.print("Raminda Subhashana");
   lcd.setCursor(0, 1);
   lcd.print("Light Controller");
   delay (2000);
   lcd.clear();
   lcd.print("Version 1.32");
   lcd.setCursor(0, 1);
   lcd.print("(C) A.G.Doswell ");
   delay (5000);
   lcd.clear();
    //Timelord initialisation
    myLord.TimeZone(TIMEZONE * 60);
    myLord.Position(LATITUDE, LONGITUDE);
    CalcSun ();
    TimerMode = EEPROM.read (0); // Read TimerMode from EEPROM
    delay (1000);
}
           
void printTemperature(DeviceAddress deviceAddress)
{
  lcd.setCursor (9,1);
  tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    lcd.print("Err");
  } else {
    
    lcd.print(tempC);
    lcd.print((char)0xDF);
    lcd.print("C ");
   
  }
}


void loop () {
    

  
    DateTime now = RTC.now(); //get time from RTC
    //Display current time
    lcd.setCursor (0,0);
    lcd.print(now.day(), DEC);
    lcd.print('/');
    lcd.print(now.month());
    lcd.print('/');
    lcd.print(now.year(), DEC);
    lcd.print(" ");
    lcd.setCursor (0,1);
    lcd.print(now.hour(), DEC);
    lcd.print(':');
    if (now.minute() <10) 
      {
        lcd.print("0");
      }
    lcd.print(now.minute(), DEC);
    lcd.print(':');
    if (now.second() <10) 
      {
        lcd.print("0");
      }
    lcd.print(now.second());
    lcd.print(" ");
    
    //current time in minutes since midnight (used to check against sunrise/sunset easily)
    TimeMins = (now.hour() * 60) + now.minute();
   
    
    //Get and display temp every minute
    if (now.second() == 7) {
      sensors.requestTemperatures(); // Request temperature
      delay (249);
      printTemperature(outsideThermometer); // display on lcd.
     
    }
    
    // Calculate sun times once a day at a minute past midnight
    if (TimeMins == 1) {
      lcd.clear();
      CalcSun ();
    }
    
    // Reset Override flag if the sun is up!
    if (TimeMins == Sunrise) {
      OverRideFlag = false;
    }
         
    
    if (TimerMode ==2) {
      if (TimeMins >= Sunrise && TimeMins <=Sunset-1 && tempC>=2 && OverRideFlag==false) { //If it's after sunrise and before sunset, and it's not frozen, and our override isn't set, switch our relay on
          digitalWrite (A3, LOW);
          lcd.setCursor (13,0);
          lcd.print ("On ");
        }
        else {  //otherwise switch it off
          digitalWrite (A3, HIGH);
          lcd.setCursor (13,0);
          lcd.print ("Off");
        }
      }
       if (TimerMode ==3) {
      if (TimeMins >= Sunrise && TimeMins <=Sunset+60 && tempC>=2 && OverRideFlag==false) { //If it's after sunrise and before sunset + 1 hour, and it's not frozen, and our override isn't set, switch our relay on
          digitalWrite (A3, LOW);
          lcd.setCursor (13,0);
          lcd.print ("On ");
        }
        else {  //otherwise switch it off
          digitalWrite (A3, HIGH);
          lcd.setCursor (13,0);
          lcd.print ("Off");
        }
      }
       if (TimerMode ==0) { // Off
         digitalWrite (A3, HIGH);
         lcd.setCursor (13,0);
         lcd.print ("Off");
       }
     
       if (TimerMode ==1 && tempC>=2) { // TimerMode is On, but it's not frozen
         digitalWrite (A3, LOW);
         lcd.setCursor (13,0);
         lcd.print ("On ");
       }
       
       buttonstate = digitalRead(A1);// check to see if our override button is pressed, if it is, change the status of the flag
       if (buttonstate == LOW ) {
         OverRideFlag = ~OverRideFlag;
       }        

    
    pushlength = pushlengthset;
    pushlength = getpushlength ();
    delay (10);
    
    if (pushlength <pushlengthset) {
      lcd.clear ();
      ShortPush ();   
      lcd.clear ();
    }
    
       
       //This runs the setclock routine if the knob is pushed for a long time
       if (pushlength >pushlengthset) {
         lcd.clear();
         DateTime now = RTC.now();
         setyeartemp=now.year(),DEC;
         setmonthtemp=now.month(),DEC;
         setdaytemp=now.day(),DEC;
         sethourstemp=now.hour(),DEC;
         setminstemp=now.minute(),DEC;
         setclock();
         pushlength = pushlengthset;
       };
}

//sets the clock
void setclock (){
   setyear ();
   lcd.clear ();
   setmonth ();
   lcd.clear ();
   setday ();
   lcd.clear ();
   sethours ();
   lcd.clear ();
   setmins ();
   lcd.clear();
   RTC.adjust(DateTime(setyeartemp,setmonthtemp,setdaytemp,sethourstemp,setminstemp,setsecs)); //set the DS1307 RTC
   CalcSun (); //refresh the sunrise and sunset times
   delay (1000);
   
}

// subroutine to return the length of the button push.
int getpushlength () {
  buttonstate = digitalRead(A0);  
       if(buttonstate == LOW && buttonflag==false) {     
              pushstart = millis();
              buttonflag = true;
          };
          
       if (buttonstate == HIGH && buttonflag==true) {
         pushstop = millis ();
         pushlength = pushstop - pushstart;
         buttonflag = false;
       };
       return pushlength;
}
// The following subroutines set the individual clock parameters
int setyear () {
   lcd.setCursor (0,0);
    lcd.print ("Set Year");
    pushlength = pushlengthset;
    pushlength = getpushlength ();
    if (pushlength != pushlengthset) {
      return setyeartemp;
    }

    lcd.setCursor (0,1);
    knob.write(0);
    delay (50);
    knobval=knob.read();
    if (knobval < -1) { //bit of software de-bounce
      knobval = -1;
    }
    if (knobval > 1) {
      knobval = 1;
    }
    setyeartemp=setyeartemp + knobval;
    if (setyeartemp < 2014) { //Year can't be older than currently, it's not a time machine.
      setyeartemp = 2014;
    }
    lcd.print (setyeartemp);
    lcd.print("  "); 
    setyear();
}
  
int setmonth () {

   lcd.setCursor (0,0);
    lcd.print ("Set Month");
    pushlength = pushlengthset;
    pushlength = getpushlength ();
    if (pushlength != pushlengthset) {
      return setmonthtemp;
    }

    lcd.setCursor (0,1);
    knob.write(0);
    delay (50);
    knobval=knob.read();
    if (knobval < -1) {
      knobval = -1;
    }
    if (knobval > 1) {
      knobval = 1;
    }
    setmonthtemp=setmonthtemp + knobval;
    if (setmonthtemp < 1) {// month must be between 1 and 12
      setmonthtemp = 1;
    }
    if (setmonthtemp > 12) {
      setmonthtemp=12;
    }
    lcd.print (setmonthtemp);
    lcd.print("  "); 
    setmonth();
}

int setday () {
  if (setmonthtemp == 4 || setmonthtemp == 5 || setmonthtemp == 9 || setmonthtemp == 11) { //30 days hath September, April June and November
    maxday = 30;
  }
  else {
  maxday = 31; //... all the others have 31
  }
  if (setmonthtemp ==2 && setyeartemp % 4 ==0) { //... Except February alone, and that has 28 days clear, and 29 in a leap year.
    maxday = 29;
  }
  if (setmonthtemp ==2 && setyeartemp % 4 !=0) {
    maxday = 28;
  }
  
   lcd.setCursor (0,0);
    lcd.print ("Set Day");
    pushlength = pushlengthset;
    pushlength = getpushlength ();
    if (pushlength != pushlengthset) {
      return setdaytemp;
    }

    lcd.setCursor (0,1);
    knob.write(0);
    delay (50);
    knobval=knob.read();
    if (knobval < -1) {
      knobval = -1;
    }
    if (knobval > 1) {
      knobval = 1;
    }
    setdaytemp=setdaytemp+ knobval;
    if (setdaytemp < 1) {
      setdaytemp = 1;
    }
    if (setdaytemp > maxday) {
      setdaytemp = maxday;
    }
    lcd.print (setdaytemp);
    lcd.print("  "); 
    setday();
}

int sethours () {
    lcd.setCursor (0,0);
    lcd.print ("Set Hours");
    pushlength = pushlengthset;
    pushlength = getpushlength ();
    if (pushlength != pushlengthset) {
      return sethourstemp;
    }

    lcd.setCursor (0,1);
    knob.write(0);
    delay (50);
    knobval=knob.read();
    if (knobval < -1) {
      knobval = -1;
    }
    if (knobval > 1) {
      knobval = 1;
    }
    sethourstemp=sethourstemp + knobval;
    if (sethourstemp < 1) {
      sethourstemp = 1;
    }
    if (sethourstemp > 23) {
      sethourstemp=23;
    }
    lcd.print (sethourstemp);
    lcd.print("  "); 
    sethours();
}

int setmins () {

   lcd.setCursor (0,0);
    lcd.print ("Set Mins");
    pushlength = pushlengthset;
    pushlength = getpushlength ();
    if (pushlength != pushlengthset) {
      return setminstemp;
    }

    lcd.setCursor (0,1);
    knob.write(0);
    delay (50);
    knobval=knob.read();
    if (knobval < -1) {
      knobval = -1;
    }
    if (knobval > 1) {
      knobval = 1;
    }
    setminstemp=setminstemp + knobval;
    if (setminstemp < 0) {
      setminstemp = 0;
    }
    if (setminstemp > 59) {
      setminstemp=59;
    }
    lcd.print (setminstemp);
    lcd.print("  "); 
    setmins();
}

int setmode () { //Sets the mode of the timer. Auto, On or Off

    lcd.setCursor (0,0);
    lcd.print ("Set Mode");
    pushlength = pushlengthset;
    pushlength = getpushlength ();
    if (pushlength != pushlengthset) {
      EEPROM.update (0,TimerMode); //write the mode setting to EEPROM
      return TimerMode;
    }

    lcd.setCursor (0,1);
    knob.write(0);
    delay (50);
    knobval=knob.read();
    if (knobval < -1) {
      knobval = -1;
    }
    if (knobval > 1) {
      knobval = 1;
    }
    TimerMode=TimerMode + knobval;
    if (TimerMode < 0) {
      TimerMode = 0;
    }
    if (TimerMode > 3) {
      TimerMode=3;
    }
    if (TimerMode == 0) {
    lcd.print("Off        ");
    lcd.print("  "); 
    }
    if (TimerMode == 1) {
    lcd.print("On         ");
    lcd.print(" "); 
    }
    if (TimerMode == 2) {
    lcd.print("Auto       ");
    lcd.print("  "); 
    }
    if (TimerMode == 3) {
    lcd.print("Auto Extend");
    lcd.print("  "); 
    }
    setmode ();
}

int CalcSun () { //Calculates the Sunrise and Sunset times
    DateTime now = RTC.now();
    sunTime[3] = now.day(); // Give Timelord the current date
    sunTime[4] = now.month();
    sunTime[5] = now.year();
    myLord.SunRise(sunTime); // Computes Sun Rise.
    Sunrise = sunTime[2] * 60 + sunTime[1]; // Sunrise returned in minutes past midnight
    SunriseHour = sunTime[2];
    SunriseMin = sunTime [1];
    sunTime[3] = now.day(); // Uses the Time library to give Timelord the current date
    sunTime[4] = now.month();
    sunTime[5] = now.year();
    myLord.SunSet(sunTime); // Computes Sun Set.
    Sunset = sunTime[2] * 60 + sunTime[1]; // Sunset returned in minutes past midnight
    SunsetHour = sunTime[2];
    SunsetMin = sunTime [1];
}

void ShortPush () {
  //This displays the calculated sunrise and sunset times when the knob is pushed for a short time.
for (long Counter = 0; Counter < 604 ; Counter ++) { //returns to the main loop if it's been run 604 times 
                                                     //(don't ask me why I've set 604,it seemed like a good number)
  lcd.setCursor (0,0);
  lcd.print ("Sunrise ");
  lcd.print (SunriseHour);
  lcd.print (":");
  if (SunriseMin <10) 
     {
     lcd.print("0");
     }
  lcd.print (SunriseMin);
  lcd.setCursor (0,1);
  lcd.print ("Sunset ");
  lcd.print (SunsetHour);
  lcd.print (":"); 
    if (SunsetMin <10) 
     {
     lcd.print("0");
     }
  lcd.print (SunsetMin);        

    
  //If the knob is pushed again, enter the mode set menu
  pushlength = pushlengthset;
  pushlength = getpushlength ();
  if (pushlength != pushlengthset) {
    lcd.clear ();
    TimerMode = setmode ();

  }
  
}

}
/*
 * Copyright (c) 2015 Andrew Doswell
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */


Hope this helps! Have fun and check back soon!

PS. Some users are having trouble with contact bounce... Add C1/C2, R5 & R6...


Sunday, 23 August 2015

Soundlab CPA 100 Mobile power amp, and surprising output matching.

Now, I needed a mobile amp, 100 watt-ish for a project. Didn't I have something in the loft? Yep, a cheap-and-cheerful Soundlab CPA 100. 75 watts allegedly. That'll do. It had a label on it. "Been reverse poled" ... ugh. Let's have a look.

I wasn't holding out much hope really, the fuse was intact. but I was expecting a rake of burnt out resistors, maybe some PCB tracks blown open...

I was, however presently surprised, just a handful of caps had popped their bases, as a result of being effectively connected backwards!   

















Anyway, a few cursory checks, and on with the power. Great. It works. Left it running for a few mins, driving a few watts into a dummy load, when I started thinking... why two transformers?


Now normally an automotive power amp needs a few more volts to drive a larger amount of power into a 4 ohm load... Ohms law applies here again, but we're dealing with a sine wave (for RMS watts)

For example, a "proper" class A only amp will swing 6 volts into our 4 ohm load ( a little less in reality, due to the losses in the transistor), so ohms law :

Power = ((Epeak/1.414) x 2) / R where E-peak is the maximum voltage of the sine wave (it will be less than the supply in reality due to transistor losses)
= (6/1.414) x 2 / 4
=4.2 watts

A push pull amp , will swing our full 12 volts into our load, giving ~18 watts. 

There are other amp topologies, such as Class H "Rail switchers" which will give more, but the limit is usually around 50 watts.

Now normally, our big automotive power amp has a step-up switched mode supply, which generates a nice +/- supply of , say 40 volts, so it can swing 80 volts into our load... mucho power ! As long as the supply is up to it! You don't get something for nothing, so the current consumed at 12 volts from the battery would rise proportionally. If the amp with +/- 40 volt supply actually exists, it will generate about 200 watts in a 4 ohm load, and will need 200 watts (plus a bit for losses in the power supply) from our 12 volt source (That's 16 2/3 amps) In Bridge-tied load, we're looking at more like 750 watts.

So, back to our little Soundlab. Are the transformers a power supply? Nope. So how does it generate more power than it's push pull design allows for?

Those transformers are output transformers. They lower the impedance the output stage sees from the speaker. So , to swing enough current from a 12 volt supply into our load, the load needs to be small.

Let's work it out...

Power = (Epeak/1.414)x2  / Resistance , so 
Resistance = (Epeak/1.414) x 2/Power
= (12/1.414)x2/75 
= 0.226 Ohms.

So our two output transformers change our 4 ohm load to a 0.226 ohm load, which allows more current to be drawn from the output stage, and more voltage to swing into the load.

There's some quite heavy negative feedback from the speaker side to tame an otherwise cheap amplifier into giving reasonable performance, and it doesn't make 75 watts RMS, but more like 75 watts when bridged, so will probably give me sufficient power for my needs. The plus side to having a transformer coupled output is if the output transistors should fail, there will never be DC on the speaker!

Radford STA-15 repairs & renovations. A quick note on biassing.

Telephone rang, a lovely chap called John. 

"I've got a Radford, one of the valves has gone, can you take a look?"

Of course. The trouble is, John lives in Scotland, and posting anything with valves in always worries me, but never fear, UPS did a stunning job and all arrived safely.

It's a rather lovely STA-15, made in 1962.


Ah yes, the disclaimer.....

WARNING. Do NOT try this at home. This amplifier calls for some high HT voltages. The main HT rail is some 390 VDC. It will floor you or kill you if you come into contact with it. It will not warn you, blow a fuse, nor pull your safety trip. It may not give you a second chance. RESPECT IT'S AUTHORITY

There are exposed 240VAC mains connections inside the enclosure. 

I will not, under any circumstances, accept any liability if you decide to repair an amplifier for yourself.

Having got that out of the way....

Fairly obvious straight away which valve had failed. Apparently, it had glowed brightly and the fizzed. It's gone down to air. It was one of a pair of Mullard EL34's. Pity, but it's twin read a bit sad on the Avo tester, so was probably due a change anyway. Interestingly enough, the other pair, which read low, but not within the realms of working OK, were Zaerix valves. I never really understand people mixing valves brands between channels, I mean we want the thing to be balanced really. Nothing for it but a new set of valves. A phone call to the lovely people at hotroxuk.com saw a new matched set of four Russian made Tung-Sol on the way. (No connection with Hot Rox, other than a delighted customer)

So, why had the Mullard expired? Switching on with the valves removed, showed the offending valve had a positive voltage on it's grid, with respect to the cathode. Not good. That's equivalent to you holding the throttle flat down of your car for hours... The valve's anode current would have risen, and the anode itself probably glowed bright red trying to dissipate all that heat, followed by the glass envelope failing due to the heat. Sadly, it's an all too common a fault. The capacitor which couples the audio to the grid, after the phase splitter had broken down, and was passing DC. Nothing for it , but a re-cap.

The Radford has a lovely symmetrical design.
In this picture I've nearly finished re-capping the left hand channel...








... and there's both sides done. Caps are Vishay and Rifa, they're reliable and are well thought of in Audiophile circles.








I checked the other valves for faults, and emission, and all was found to be in good order. I also did some checks on the values of resistors, especially anode, cathode and screen. Everything was good, and always better than 5% tolerance. Nice!

Now to check the biassing....

There's a lot of BS out there about biassing, some of it comes from manufacturers and importers, some of it folklore, most of it wrong or downright stupid. We need to bias out output stage to get our anode current to less than the maximum plate dissipation of our valve. So we have an EL34. It's maximum plate dissipation is 20 watts. Anything more and we're in trouble, and run the risk of premature failure, the anode glowing red etc etc. Nasty. Don't do it.

So we need to know two things. The current flowing into the anode, and the voltage between the anode and the cathode (not, as some suggest between the anode and ground). That's all the valve "sees" and is all we need to do our calculations.

To make this easy, please welcome the Doz "Bias-o-rama" ... It's an octal socket and an octal plug. All the pins are connected together, except the anode and cathode, which are connected by 1 ohm resistors. There's some flying leads across these resistors. Now measuring the voltage across the resistors, will give us the current flowing in mA. Great.
So, first off, install the bias-o-rama, and valves into the amp. Plug in speakers.


Right, switch on and wait for the valves to warm. It's worth keeping an eye on things here, just in case the bias is miles out, or there's a fault, and our valve starts to red-plate. If it does, switch it off quickly.

Now that everything's ok, measure the voltage between the anode and cathode. In this case a very civilised 390 V. Now measure the voltage across the anode resistor on the "Bias-o-rama"... That gives us the current in mA flowing though the Anode. As these valves are from a matched set, both currents should be within a couple of mA of each other....








Yep , they're good (Thanks HotRox!)


So we have 390v and about 50 mA flowing. Simple ohm's law tells us power = voltage x current, so
390 x 0.050 = 19.5 watts. Less than our maximum allowable 20 watts. (I will point out, this was taken after I'd adjusted the bias, which on the Radford involves changing resistors in the grid feed circuit, there's no pot or anything helpful like that)

Biassing too cool (not enough current flowing) will show up as cross-over distortion.

Some biassing voodoo calls for measurement of the cathode current. I'm not sure why, as this also includes any current flowing into the screen too. Less accurate, but probably near enough. I suppose the cathode is always at a lower voltage, so it's safer.

OK, so now we're happy with the bias, leave the amp running for 15 mins and check again. Still good? (It should be, although I once had a set of clear top 6550's that drifted badly, they went back!)
Right, now go to a darkened room, and play the amp loud for 15 mins. Look carefully at the large grey anode. If there's any signs of it glowing red, or little spots of glowing, it's still biassed too hot. Go and do it again!

So there it is, on test in the living room, much to the wife's delight. Playing the excellent CD "I will be a pilgrim" by Arch Garrison (http://www.archgarrison.co.uk/) , a blend of acoustic guitar and philcordia , some nice folky bits with a psychadelic air to it.



A post script...


My apologies for the poor focus, the infra red from the tubes stops the auto-focus working on the camera (it works by infra-red!), and this was a long exposure. I hope you can see the blue glow around the holes in the anode. This is caused by electrons hitting the glass and causing it to fluoresce. This is normal. If a tube gets "gassy" a similar blue glow can be seen, but very much more pronounced and time for a new valve! 





Saturday, 15 August 2015

Technics SL-P1200B Compact Disc Player

This belongs to lovely chap in the beautiful country of Wales.

It's a commercial CD player, favored (briefly) by the beeb and independent local radio stations in the late 80's , early 90's. This one dates from 1988.

The -P version was specifically for broadcast use, and instead of the large slider on the right being for pitch control, it's a fader. The pitch control is the small knob on the top right.

Rumour has it the poor things gained a reputation for being a finicky, requiring the CD to be spotless, and was possibly responsible for more "dead-air" back then than anything else. Sad really, because the spec is fantastic, Burr-brown PCM54HP DAC's and Technic's successful "Class AA" bits and bobs.

All this needed was a bit of a service. The laser is fantastic and should give plenty of good service back in the motherland!


Friday, 14 August 2015

Trio (Kenwood) KA-2500 amplifier repair & renovations.

The things that turn up. This arrived from a friend of a friend, for repair.

It looked as if it had been safely stored in a lake for the last 40 years.



It's a fairly straight-forward silicon amp, dating from ~1973. It uses 4 NPN 2SD180 output transistors, capacitively coupled to the speakers.

This unit had obviously seen a couple of repairs in the long-distant past. The first thing I noticed was the mains fuse, which looked like it belonged in a 1960's Morris-Minor rather than the mains input of this amp! 

 8 amps continuous, 15 amp blow.... You can just imagine this being worked a little too hard in the 70's... blasting out some Yes at a party, only to be met with silence ... then someone has a bright idea and pops the bonnet on Dad's Morris!
Rather than the 2 amp requirement!

The mains input filtering cap, C28, was looking in a sorry state, so was snipped out, pending replacement, and mains gently applied via the variac. The power supply was obviously heavily loaded by something, as the voltage across C25 didn't rise as expected, and there was some excessive current draw from the mains. The HT feed wire was disconnected, and the voltage rose to an acceptable level, without the current draw. My immediate thoughts went to the output transistors, our 4 2SD180's , but these tested OK. I started to check the caps in the output stage, and every single one read high ESR, low capacity, leaky or a combination of all three! A blanket re-cap saw no real improvement of current draw when the supply was reconnected. Time to measure some voltages... With the mains set low, to give us an HT of ~5V, bias was obviously miles out, with two of our output transistors (Q2 & Q3) hard to rail. Tracing back showed either Q3 or Q5 were hard on, for no apparent reason... R5 had also risen in value to 1 Megohm or so. Q3 and 5 were removed and tested OK on the transistor tester, and found to read fine for gain and leakage. R5 was replaced. Powering on again showed no improvement. More voltage measurements again hinted that either Q3 or Q5 were the guilty party. Static testing of caps, resistors and transistors proved fruitless. Q3 and Q5 are 2SD317's.... and are so obsolete. Noah himself had discarded his stock (of two, obviously!) Looking at the spec showed an old favorite of mine, the BC547 may well do in that position, although it has a slightly less Vce of 50V as opposed to 70V for the 2SC317. I knew that it would never see more than 50V in this position, so I fitted two, and was rewarded with audio, albeit the output stage was still drawing too much current. Setting up the bias to the output stage (60mA) cooled things somewhat , and I left the amp on test for a while... 


All was well, and the bias stable :) 

All that remained to do was to recap the phono pre-amp board, a quick clean up and send it on it's way. The output capacitors seemed to read OK, and there's very little in the way of DC on the speaker terminals. The main smoothing cap also seems OK... After all that testing I suspect it had reformed itself,  without resorting to the Dreadnaught capacitor reformer.

Freshly re-capped phono-pre. Nice symmetrical design .

 Top down...

 A mixture of construction, some tag-strip , but mostly PCB.









 The finished article...

... and the guilty parties!









Nice selection of in's and out's... Note Tape HD, now that's not High Definition, oh no, that's Tape HeaD! It feeds the phono stage without the RIAA equalisation.







How does it sound? Phono preamp is a bit noisy. Best described as "of it's time" , but a nice piece of earlyish transistor hifi nonetheless.












Thursday, 13 August 2015

Mini 1275GT ... more corrosion




 ... and so it continues....


N/S Floor in 
N/S heel board cut out
Check alignment
New N/S heel board cut to size...
... and welded in place.
There needs to be 50.5 inches between these bolts and the ones on the other side.
N/S heel board / boot floor/ rear pocket closer panel welded in
N/S inner sill seat belt mounting point welded in, and door step to a-post panel lined up
... and welded into place
N/S rear quarter repair cut to size and welded.
Nasty near side floor bodge removed
... rear pocket unpleasantness!
Much more to cut out yet!
O/S Inner wing repaired
O/S heel board / rear seat area repaired
... and rotten heel board cut out
more to come ....
Inner wing repair (another view)
Nasty.. most of the floor comes out with the a-post still attached
... nasty
Lower rear pocket is in a bad way due to being sandwiched between two rotting pieces of floor 
.. so a new section is made up and welded in place

Floor taking shape...
Check fit ... and I'm not happy with it... 

... so I turn my attention to the rear heel board again! 
and the closer panel
Outer sill in place... 
... starting to come together... but why wasn't I happy with the fit?
Because the centre cross member was in a bad way .... so I cut it out
.. welded some tabs to a new one to ensure good alignment, and welded in place.
... then the boot floor gets a repair piece...
... or three
Valence checked for fit
Rotten lower section of the rear panel cut out and replacement welded in

Inner wheel arch repair (this is where it all started!)
.. then I hit filler in the top part of the O/S rear quarter...
... so it gets cut out
... and , after two evening's worth of cutting and fettling...
The new panel is fitted and welded in.
Window rail and quarter stiffener panel fitted.





A coat of primer to protect the new metal.



A coat of priner and stone chip for the floor , and refit the freshly painted rear subframe.



Refit the front subframe (again freshly painted), and back on it's wheels.


... still much work to do to the front panel, and of course paint and reassembly, but that's it for now.