mugheesnawaz
Member level 1
- Joined
- May 1, 2013
- Messages
- 39
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Activity points
- 1,605
i am using pic 16f877a with 8MHZ crystal and microC for pic for coding for buck and boost modules operation and i am using relays with the outputs of buck and boost so that only one output is received from buck and boost at a time(either buck will be on or boost will be on).
i am using port A for analog inputs,portB for LCD,Port E for buck boost enabling i.e i will set on pin ON and one pin OFF and will connect pins of this ports to relays of buck and boost.PORT C is used for PWM of buck and boost.now i am enabling buck and constantly decreasing 12V until it gets to 6V and then stop.i want to display simultaneously display this output of buck on LCD which i am facing problem in.
without LCD, i am getting correct results but when i interface LCD the operation stops i think due to delays of LCD_out command.kindly skip other parts of circuit as they will confuse you.
attached is image of cct diagram.
i am using port A for analog inputs,portB for LCD,Port E for buck boost enabling i.e i will set on pin ON and one pin OFF and will connect pins of this ports to relays of buck and boost.PORT C is used for PWM of buck and boost.now i am enabling buck and constantly decreasing 12V until it gets to 6V and then stop.i want to display simultaneously display this output of buck on LCD which i am facing problem in.
without LCD, i am getting correct results but when i interface LCD the operation stops i think due to delays of LCD_out command.kindly skip other parts of circuit as they will confuse you.
attached is image of cct diagram.
Code:
unsigned int ADCRead(unsigned char channel)
{
unsigned char l_byte, h_byte;
unsigned int ADR;
ADCON0 = 0x81 | (channel << 3); //Change channel
delay_us(50); //Acquisition Delay 50us
GO_DONE_bit = 1; //Set GO_DONE bit to start conversion
while (GO_DONE_bit == 1); //Wait for bit to be cleared
//If bit is cleared, this means conversion is over
l_byte = ADRESL;
h_byte = ADRESH;
ADR = (h_byte<<8)|l_byte;
ADON_bit =0; //switch off adc
return ADR;
}
// LCD Module connections
sbit LCD_RS at RB1_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D4 at RB4_bit;
// End LCD module connections
// LCD Pin direction
sbit LCD_RS_Direction at TRISB1_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB7_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB2_bit;
// End of LCD Pin direction
void main(void)
{
unsigned int Ch0, Ch1;
float Form1,Form2;
unsigned short duty1=255;
float tempo=15.6;
char str_temp[60];
CMCON = 7; //Disable ADC
PORTA=0;
TRISA=0xff;
PORTB = 0;
TRISB = 0;
PORTC=0;
TRISC = 0;
PORTD = 0;
TRISD = 0;
PORTE = 0;
TRISE = 0;
ADCON0 = 0x81;
ADCON1 = 0x80;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR); // Clear DisplayDelay_ms(30);
Lcd_Out(1, 1, "MPPT Controller");
delay_us(1000);
PWM1_Init(25000); // Initialize PWM1 for 25Khz
PWM1_Start(); // start PWM1
PWM1_Set_Duty(duty1); // Set current duty for PWM1
PORTE.F0=0;
PORTE.F1=1;
while(1)
{
duty1=255;
PWM1_Set_Duty(duty1);
Ch0 = ADCRead(0); //Gets reading from channel 0
delay_us(100); // 0.1ms delay for ADC stabilization
Ch1 = ADCRead(1); //Gets reading from channel 1
delay_us(100); // 0.1ms delay for ADC stabilization
Form1= (10*(5*Ch0)/1023);
PORTD = Form1;
Form2= ((Ch1-123)/12);
delay_us(100); // 0.1ms delay for ADC stabilization
while((Form1>9.80))
{
Ch0 = ADCRead(0); //Gets reading from channel 0
delay_us(100); // 0.1ms delay for ADC stabilization
Ch1 = ADCRead(1); //Gets reading from channel 1
delay_us(100); // 0.1ms delay for ADC stabilization
Form1= (10*(5*Ch0)/1023);
delay_us(100);
FloatToStr(Form1, str_temp);
PORTD = Form1;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, "Battery Voltage=");
// Ltrim(str_temp);
Lcd_Out(2, 1, str_temp);
//delay_ms(1000);
duty1-=2.55; //255/100=2.55 for each instance 1% decreased
PWM1_Set_Duty(duty1);
}
}
}
Last edited: