Kbfinal

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

#include <adc.

h>

#include <LiquidCrystal.h>

#include <SoftwareSerial.h> // Include SoftwareSerial library for GSM communication

// Port Configurations (adjust pin connections if needed)

sbit contactor_control at PORTB.B0; // Motor contactor control on RB0

sbit buzzer at PORTB.B1; // Buzzer on RB1 (replace with actual buzzer pin)

// LCD connections on PortB

LiquidCrystal lcd(RS = 2, EN = 3, D4 = 4, D5 = 5, D6 = 6, D7 = 7);

// GSM module communication pins on PortC

const int GSM_TX = 0;

const int GSM_RX = 1;

SoftwareSerial gsmSerial(GSM_TX, GSM_RX);

// Replace with your SIM card phone number and recipient number

const char* GSM_PHONE_NUMBER = "+1234567890";

const char* RECIPIENT_NUMBER = "+9876543210";

// Voltage thresholds (adjust based on system voltage)

const int UNDER_VOLTAGE_LIMIT = 150;

const int OVER_VOLTAGE_LIMIT = 250;

const int VOLTAGE_THRESHOLD_SINGLE_PHASE = 100; // Lower threshold for single-phase detection

const float TRIP_DELAY = 0.1; // Delay in seconds before tripping (adjust based on needs)
// Voltage divider ratio (adjust based on your setup)

const float voltage_divider_ratio = 10.0; // Example: Divider with R1 = 8.8kΩ, R2 = 1kΩ

// Current sensor scaling factor (adjust based on your current sensor)

const float current_sensor_scale = 100.0; // Example: 100 A/V for a sensor with 0-5V output for 0-100A
current

int phase_voltages[3];

float phase_currents[3]; // Array to store phase current readings

// Function to initialize ADC (MikroC 6.3 compatible)

void setup_ADC(void) {

// Set ADC clock source (replace with desired clock source)

ADCON0bits.CSADH = 1; // FOSC/64 clock source (adjust based on your needs)

// Set ADC resolution (8-bit in this case)

ADCON0bits.CHS = 0; // Analog Channel Select bits (00 for 8-bit resolution)

// Configure ADC input channels for voltage measurement (adjust based on your connections)

TRISA = 0b00000111; // Set RA0-RA2 as analog inputs

// Enable ADC module

ADCON0bits.ADON = 1;

}
void read_phase_voltages() {

for (int i = 0; i < 3; i++) {

// Select ADC channel for each phase voltage

ADCON0bits.CHS = i; // Set ADC channel (0, 1, or 2)

__delay_us(10); // Allow for channel selection settling time

ADC_StartConversion(); // Start ADC conversion (MikroC 6.3 function)

while (BusyADC()); // Wait for conversion to complete (MikroC 6.3 function)

phase_voltages[i] = ADC_Read(); // Read ADC result (MikroC 6.3 function)

void read_phase_currents() {

// Implement code to read current sensor outputs using ADC (MikroC 6.3 functions)

// You'll need to adjust this section based on your specific current sensor type and connections

// Assuming current sensors are connected to analog inputs RA3-RA5:

for (int i = 0; i < 3; i++) {

ADCON0bits.CHS = 3 + i; // Set ADC channel for each phase current (RA3-RA5)

__delay_us(10); // Allow for channel selection settling time

ADC_StartConversion(); // Start ADC conversion (MikroC 6.3 function)

while (BusyADC()); // Wait for conversion to complete (MikroC 6.3 function)

int current_adc_value = ADC_Read(); // Read ADC result (MikroC 6.3 function)

// Convert ADC reading to current using sensor scaling factor

You might also like