daniel23
Published © LGPL

Automatic degausser arduino controlled

The degausser applies a decreasing alternating magnetic field. The decreasing field is produced by TRIAC phase control driven by an arduino

AdvancedFull instructions provided491
Automatic degausser arduino controlled

Things used in this project

Hardware components

Arduino Pro Mini 328 - 5V/16MHz
SparkFun Arduino Pro Mini 328 - 5V/16MHz
×1
Triac 60V 25A (e.g. Q6025R5)
×1
Opto Triac MOC3021
×1
Optocoupler, 1 Channel
Optocoupler, 1 Channel
×1

Story

Read more

Schematics

Degausser diagram

Pdf file

Code

AC Phase control for demagnetization

Arduino
Software for Arduino Pro Mini or Nano (or any other ATmega328P based Arduino)
/*         ******************************************
//         *  AC Phase control for demagnetization  *
//         *    Daniel Engel         16/10/2022     *
//         ******************************************
//
//  V_0.3:  Translated into English and added more detailed comments
//
//  Inspired by: "AC Control V1.1" (author unknown)
// ==========================================================================
*/

// Timing Sequence
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
// * timer is set up but disabled
// * zero crossing detected on pin 2
// * timer starts counting from zero
// * comparator set to a "delay to on" value
// * counter reaches comparator value
// * comparator ISR turns on TRIAC gate
// * counter set to overflow - pulse width
// * counter reaches overflow
// * overflow ISR turns off TRIAC gate
// * TRIAC stops conducting at next zero cross
// * "delay to on" is increased, waiting for the next loop at zero crossing

// Timer runs at 16MHz.
// Using a divide by 256 on the counter each count is 16 microseconds.
// 1/2 wave of a 60Hz AC signal is about 520 counts (8,333 microseconds).
// 1/2 wave of a 50Hz AC signal is about 625 counts (10.0 microseconds).
// note that "delay to on" + triac gate pulse width shall not exceed the half wave duration

// NB: Timer0 (8 bits) is used by delay() millis() micros() and the PWM on pins 5 and 6.

// #include <avr/io.h>
#include <avr/interrupt.h>

#define DETECT 2            // zero cross detect
#define GATE 9              // TRIAC gate
#define PULSE 8             // trigger pulse width (counts)
#define StartBtn 7          // Start Button
#define LedRun 4            // Red LED => RUN

// -----------------------------------------------------------------------
int i = 587;          // Value where the triac is no longer fired. Determined experimentally
int SetPower = 200;   // smaller number => More power !!! SetPower=>TBD !!!
// (minimum current ~400;  maximum current ~200;) Determined experimentally
// -----------------------------------------------------------------------

void setup() {
  pinMode(DETECT, INPUT_PULLUP);    // zero cross detect
  pinMode(GATE, OUTPUT);            // TRIAC gate control
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(LedRun, OUTPUT);
  digitalWrite(LedRun, LOW);
  pinMode(StartBtn, INPUT_PULLUP);

  // set up Timer1    (see ATMEGA328 data sheet p.134 for more details)
  OCR1A = SetPower;     //initialize the comparator
  TIMSK1 = 0x03;        //enable comparator A and overflow interrupts
  TCCR1A = 0x00;        //timer control registers set for
  TCCR1B = 0x00;        //normal operation, timer disabled

  // set up zero crossing interrupt (IRQ0 is on pin 2)
  // Call zeroCrossingInterrupt on rising signal
  attachInterrupt(0, zeroCrossingInterrupt, RISING);

  BlinkFast();
}

//=======================================================================
void loop() {
  i++;
  if (i > 587)    // end of degauss cycle -

  {
    noInterrupts();
    digitalWrite(GATE, LOW);
    digitalWrite(LedRun, LOW);
    i = SetPower;    // timer value is set waiting for next cycle
    delay(2500);     // delay between cycles to allow the heat to be spread
    //                  if several cycles are chained one after the other
    while (digitalRead (StartBtn) == HIGH) {}     // button is released
    while (digitalRead (StartBtn) == LOW) {}      // button is pressed
    //   the degaussing cycle starts after the button is released

    interrupts();
    digitalWrite(LedRun, HIGH);
  }
  OCR1A = i;      // set the compare register
  delay(5);       // wait for a quarter of an alternation (for 50Hz)
  //          (could be set to 10 if more time is needed for degaussing)
}

//=======================================================================
void BlinkFast() {
  for (byte i = 6; i != 0; i--)
  {
    digitalWrite(LedRun, HIGH);  delay(100);
    digitalWrite(LedRun, LOW);  delay(100);
  }
}

//=======================================================================
//Interrupt Service Routines

void zeroCrossingInterrupt() {  //zero cross detect
  TCCR1B = 0x04;                //start timer with divide by 256 input
  TCNT1 = 0;                    //reset timer - count from zero
}

ISR(TIMER1_COMPA_vect) {        //comparator match
  digitalWrite(GATE, HIGH);     //set TRIAC gate to high
  TCNT1 = 65536 - PULSE;        //trigger pulse width
}

ISR(TIMER1_OVF_vect) {          //timer1 overflow
  digitalWrite(GATE, LOW);      //turn off TRIAC gate
  TCCR1B = 0x00;                //disable timer stopd unintended triggers
}

Credits

daniel23

daniel23

8 projects • 10 followers

Comments