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.

LCD shows funny character when timer is on

Status
Not open for further replies.

Mithun_K_Das

Advanced Member level 3
Advanced Member level 3
Joined
Apr 24, 2010
Messages
899
Helped
24
Reputation
48
Reaction score
26
Trophy points
1,318
Location
Dhaka, Bangladesh, Bangladesh
Visit site
Activity points
8,254
when I don't use timer interrupt for high frequency its ok and displays everything normal on LCD. But if I use timer interrupt with high frequency, the LCD shows funny characters also with noise in display.


Why this is happening and what is the remedy of this problem?

20022014850.jpg
this is normal condition and
20022014849.jpg
this is when timer is on.

TMR0 = 240;
 

it may be due to the in sufficient delay . try to increase the interrupt time. which is your controller ?
 

Prescaler 1:1; TMR0 Preload = 240; Actual Interrupt Time : 15 us
is this your setting ??
the lcd may display correctly but you can't identify them. try some interrupt in ms range
 

I don't understand why this is happening again, this time I'm just using a 100uS interrupt. code:
Code:
/*******************************************************************************
MCU PIC16F73 , XTAL: 10MHz
Program written by Engr. Mithun K. Das
Email: mithun060@gmail.com    Cell: 01722448270
******************************************************************************/
// LCD module connections
sbit LCD_RS at RC7_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISC7_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections


#define     Clock1             RC5_bit
#define     Clock2             RC6_bit

float Battery;
unsigned int long_bat;
unsigned int adc_rd0,fb=5;
unsigned short oscillation,ch_start;
unsigned int os_cnt,feedback,ch_cnt,current;


void Get_Battery(void);
void Display_Battery(void);



void interrupt()
{
    if(oscillation==1)
    {
        os_cnt++;
        while(os_cnt<=3+feedback)
        {
           Clock2 = 0;
           Clock1 = 0;
           break;
        }
        while(os_cnt>=3+feedback && os_cnt<=53-feedback)
        {
           Clock2 = 1;
           Clock1 = 0;
           break;
        }
        while(os_cnt>=53-feedback && os_cnt<=59+feedback)
        {
           Clock2 = 0;
           Clock1 = 0;
           break;
        }
        while(os_cnt>=59+feedback && os_cnt<=106-feedback)
        {
           Clock2 = 0;
           Clock1 = 1;
           break;
        }
        while(os_cnt>=106-feedback)
        {
           Clock2 = 0;
           Clock1 = 0;
           break;
        }
        while(os_cnt==109)
        {
           os_cnt=0;
           break;
        }

    }


    TMR1IF_bit = 0;
    TMR1H = 0xFE;
    TMR1L = 0xEE;
 }

void PORT_Ini(void)
{
   TRISA = 0xFF; // PORTA input
   TRISB = 0b00000001; // PORTB output except RB0 & RB1
   PORTB = 0x00; // all zero
   TRISC = 0b00001000; // PORTC output
   PORTC = 0x00; // all zero
}


void main()
{
   PORT_Ini(void);
   
   Lcd_Init();
   Lcd_Cmd(_LCD_CLEAR);
   Lcd_Cmd(_LCD_CURSOR_OFF);

   
   Buzzer = 1;
   Delay_ms(500);
   Buzzer = 0;
   Delay_ms(500);
   
   ADCON1=0x00;
   
   OPTION_REG = 0x00;
   // Timer settings
   T1CON = 0x01;
   TMR1IF_bit = 0;
   TMR1H = 0xFE;
   TMR1L = 0xEE;
   TMR1IE_bit = 1;
   INTCON = 0xC0;

   while(1)
   {

       Get_Battery(void);
       Display_Battery(void);
      
      oscillation = 1;
      // feedback... 
      if(adc_rd0==51)
      {
         feedback = feedback;
      }
      else
      {
         if(adc_rd0<57 && adc_rd0>45)
         {
             if(adc_rd0>51)
             {
                if(fb<15)
                {
                   fb = fb+1;
                }
                else
                {
                   fb = fb;
                }
             }
             if(adc_rd0<51)
             {
                if(fb>1)
                {
                   fb = fb-1;
                }
                else
                {
                   fb = fb;
                }
             }
          }
          else
          {
             if(adc_rd0>=57)
             {
                if(fb<15)
                {
                   fb = fb+5;
                }
                else
                {
                   fb = fb;
                }
             }
             if(adc_rd0<=45)
             {
                if(fb>1)
                {
                   fb = fb-5;
                }
                else
                {
                   fb = fb;
                }
             }
          }
          feedback = fb;
      }
  
   }  // while
}// void main

void Get_Battery(void)
{
     ADCON0=0b00011001;
     Battery = (float) ADC_Read(3)*0.0915;
     long_bat = (int) ADC_Read(3)*.915;
}
void Display_Battery(void)
{
    char Mess_Battery[]="B:  . V";
    Mess_Battery[2] = (long_bat/100)  + 48;
    Mess_Battery[3] = ((long_bat/10)%10) + 48;
    Mess_Battery[5] = ((long_bat)%10) + 48;
    Lcd_Out(1,10,Mess_Battery);
    Delay_ms(50);
}

LCD still showing funny characters and noise. I found that there is a problem when I'm using the feedback section.... else all showing good.
 

Is this correct?


Code C - [expand]
1
Lcd_Out(1,10,Mess_Battery);


What is Mess_Battery array or variable?

 

Just a character. to show a message

Code:
 char Mess_Battery[]="B:  . V";
    Mess_Battery[2] = (long_bat/100)  + 48;
    Mess_Battery[3] = ((long_bat/10)%10) + 48;
    Mess_Battery[5] = ((long_bat)%10) + 48;
    Lcd_Out(1,10,Mess_Battery);
    Delay_ms(50);
 

Where the Mess_Battery is lorded in the above code
 

if you want to display "Mess_Battery" use this method


Code C - [expand]
1
2
3
char txt3[] = "Mess_Battery";
 
 Lcd_Out(1,1,txt3);

 

you are making mistake to read the code. I'm using Mess_battery instead of tex3[]; I hope you are able to understand now.

seee carefully:


Code C - [expand]
1
char Mess_Battery[]="B:  . V";

 

I faced a similar problem. Try stopping the timer before writing it to it. After writing to the timer switch it on.

Code:
T1CON.TMR1ON = 0;      //Switch OFF TMR1
TMR1H = 0xFE;
TMR1L = 0xEE;
T1CON.TMR1ON = 1;      //Switch ON TMR1
 

Don't call Display_Battery() continuously instead only call it and update LCD data only if adc value changes.
 

Unfortunately I tried that. Same result bro. It makes all characters like some kind of unknown language/ funny character. Is there any extra protection required at the circuit for LCD? Such as adding a Capacitor near LCD data line?
 

hello,



What is the purpose of the code inside the interrupt .. Step motor control ?
With FOSC=10MHz you have FFFF-FEEE=> 273 cycles *4/10 => 109µS to do this job..
(or 274 ? 0000-FEEE ?)


try to mesure the executing time of inside interrupt... to know, what is the effective load of your MCU
and so, find out remaining time at disposal to do ground Job ( as LCD display).

I think, you don't have enough time in the main to treat LCD, without disturbing each necesseray timing (delay)
to correctly drive it.

Try with a more powerfull PIC .. ie 18F Q10MHz with PLL => 40MHz as FOSC or 16x4=64MHz
or maybe you can organise your program elsewhere , to treat a part of code inside the main instead inside interrupt.
 

Maybe bank switching is causing the problem. Do you get "IRP_bit must be set manually to access xyz" message in mikroC Compiler. If yes then use CopyConst2Ram or change to PIC18F.
 

hello,



What is the purpose of the code inside the interrupt .. Step motor control ?
With FOSC=10MHz you have FFFF-FEEE=> 273 cycles *4/10 => 109µS to do this job..
(or 274 ? 0000-FEEE ?)


try to mesure the executing time of inside interrupt... to know, what is the effective load of your MCU
and so, find out remaining time at disposal to do ground Job ( as LCD display).

I think, you don't have enough time in the main to treat LCD, without disturbing each necesseray timing (delay)
to correctly drive it.

Try with a more powerfull PIC .. ie 18F Q10MHz with PLL => 40MHz as FOSC or 16x4=64MHz
or maybe you can organise your program elsewhere , to treat a part of code inside the main instead inside interrupt.

No, I don't want to use 18F series. As because I found many many circuits using PIC16F72 or 73 with LCD and Timers. But they don't have such a problem I'm having in my case. This is why I want to know what fault I'm making for a long time. I've been working with this problem for very long time. Not by hook or by crook, I've to solve it.

- - - Updated - - -

Maybe bank switching is causing the problem. Do you get "IRP_bit must be set manually to access xyz" message in mikroC Compiler. If yes then use CopyConst2Ram or change to PIC18F.

Nop!, there is no such warning generated. I double checked it.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top