Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Jhuman Khan
Published

Autocaut Charging Mini DC IPS Making at Home

In an era where power outages are common, having a backup power solution is crucial. The Autocaut Charging Mini DC IPS is an innovative, low

BeginnerFull instructions provided197
Autocaut Charging Mini DC IPS Making at Home

Things used in this project

Story

Read more

Schematics

schematic_full-autocut-mini-ips_2024-09-25_oSc6o8rQio.png

Code

sketch_sep18a.ino

Arduino
#include <LiquidCrystal.h>

// Initialize the LCD, set the pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);  // RS, E, D4, D5, D6, D7

// Parameters for DSP and Sine Wave Generation
const int sineTableSize = 256;
int sineTable[sineTableSize];  // Sine lookup table
volatile unsigned long phaseAccumulator = 0;  // Phase accumulator for DDS
const unsigned long phaseIncrement = 4294967296 / 50;  // Phase increment for 50Hz sine wave

// Variables for display
float outputFrequency = 50.0;
int batteryVoltage = 12;  // Example voltage for display

void setup() {
  // Setup LCD 1602
  lcd.begin(16, 2);  // Initialize a 16x2 LCD
  lcd.print("Sine Wave IPS");
  delay(2000);
  lcd.clear();
  
  // Setup sine table
  for (int i = 0; i < sineTableSize; i++) {
    sineTable[i] = 127 + 127 * sin(2 * PI * i / sineTableSize);  // Scale for 8-bit PWM
  }

  // Setup Timer1 for Fast PWM at 20kHz for SPWM
  TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11);  // Fast PWM, non-inverting
  TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10);  // No prescaler
  ICR1 = 800;  // 20kHz frequency
  
  // Display initial status
  updateLCD();
}

void loop() {
  // Update the sine wave
  updateSPWM();
  
  // Periodically update LCD with frequency and voltage
  if (millis() % 1000 == 0) {
    updateLCD();
  }
}

void updateSPWM() {
  // DDS: Update phase accumulator
  phaseAccumulator += phaseIncrement;

  // Use the top bits of the phase accumulator for sine table index
  int index = (phaseAccumulator >> 24) & (sineTableSize - 1);
  int sineValue = sineTable[index];  // Get sine wave value
  
  // Output to PWM
  OCR1A = sineValue;  // PWM for half-bridge A
  OCR1B = 255 - sineValue;  // Inverted PWM for half-bridge B
}

void updateLCD() {
  lcd.setCursor(0, 0);  // Set cursor to first row, first column
  lcd.print("Freq: ");
  lcd.print(outputFrequency);
  lcd.print(" Hz");

  lcd.setCursor(0, 1);  // Set cursor to second row
  lcd.print("Batt: ");
  lcd.print(batteryVoltage);
  lcd.print("V");
}

Credits

Jhuman Khan
15 projects • 5 followers
Diploma in Electronics, B.Sc in EEE
Contact
Thanks to Estiak Khan.

Comments

Please log in or sign up to comment.