Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PWM and LCD not working simultaneoulsy with PIC 16f877a.please help

Status
Not open for further replies.

mugheesnawaz

Member level 1
Member level 1
Joined
May 1, 2013
Messages
39
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Visit site
Activity points
1,605
i am using pic 16f877a and i want to use pwm to control my output voltage using buck converter and i have sucessfully tested pwm and lcd (separately) and it works fine but when i start pwm(PortC) and lcd on PortD then pwm works sucessfully but lcd doesnt display anything.
kindly help me in mentioning what is worng

Untitled.png

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
        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 RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D4 at RD4_bit;
// End LCD module connections

// LCD Pin direction
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D7_Direction at TRISD7_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD4_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;//CCP1CON = 0x3C;
                PWM1_Init(25000); // Initialize PWM1 for 25Khz
                PWM1_Start(); // start PWM1
                PWM1_Set_Duty(duty1); // Set current duty for PWM1
                 Lcd_Init();                  // Initialize LCD
                 Delay_ms(30);
                 Lcd_Cmd(_LCD_CLEAR);        // Clear DisplayDelay_ms(30);
                 Lcd_Out(1, 1, "MPPT Controller");
                 //FloatToStr(tempo, str_temp);
                 //Lcd_Out(2, 1, str_temp);
 
                }


}
 

The Lcd_xxx API functions are probably using some resource of uC that are being already shared by the PWM module, such as a Timer.
 

Yes i searched about it and RD4 is the one which is being used by pwm and lcd both and i changed the port from D to B for LCD and its working okay except one problem i.e Lcd_out command is very laggy and consumes alot time any solution?
 

You could look for another code that interface with the LCD, preferably some one not precompiled, so that you could check in the code what resources are being used.

In the case of the PWM of 16F877, this module already uses a timer to operate it, and I believe this is the most likely reason for not working, a same resource mutually accessed by both routines, causing conflict .
 
The lagging will be only in Proteus and it is due to oscialloscope. Buy a dual core i7 syatem with 16 GB RAM. It will simulate faster. Just remove the oscilloscope from Proteus and simulate.
 

i am doing in simulation for time being but its laggy and gives wrong values.
sir i removed the oscilloscope but still it is working slowly
 

This is the whole project,if i remove LCD_out commands in the while loop then process is extremely fast which i want it to be with LCD_out commands.
 

Attachments

  • Recent Most.rar
    131.6 KB · Views: 74

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top