PIC 16F877A Rebooting and garbled LCD display!!

General discussion on mikroC.
Post Reply
Author
Message
siddharthsh
Posts: 11
Joined: 20 Jan 2008 16:56

PIC 16F877A Rebooting and garbled LCD display!!

#1 Post by siddharthsh » 05 Sep 2008 17:57

Hi All,

I am trying to develop a digital speedometer and tachometer for my motorcycle using the programs given on this website (using CCP and TMR0 interrupt routines): http://www.mikroe.com/forum/viewtopic.p ... tachometer.

Currently I am using the following hardware:
PIC16F877A
11.0592 MHz
16x4 LCD

THE PROBLEM:
The RPM and Speed readouts work fine, but:
1) The moment I press the horn the LCD starts to display all kinds of random garbled characters. The only option is to restart the system, which is quite dangerous and cumbersome while riding
2) Sometimes the PIC also reboots (As I am able to see the program startup routine on the LCD) accompanied by the garbled images on the LCD
3) If the unit is kept on just connected to a power source, for sometime it works fine. But after say a minute or so, the LCD only displays the dynamic data (the value of Speed and RPM) on the screen (that which is updated regularly every second) and the static data on the screen (eg: km/h and RPM characters that are output only in the beginning of execution) vanishes. So what I get is only the numeric values for Speed, RPM but the "Km/h" and "RPM" do not appear.

ADDITIONAL INFORMATION:
FUSES:
1) LVP = OFF
2) BODEN = OFF
3) PWRTE = OFF
4) WDT = OFF
5) HS_OSC = TRUE

WIRING:
1) I am using shielded wires from the sensors
2) The length of the LCD cables from the PIC (PCB) to the LCD is about 10cm (approx. 4 inches). Is it too long, for it to cause interference?
3) I have included 2 capacitors 10uF and 100pF at the 5V power supply (power supply is common for the PIC and the LCD) . Are the capacitor values sufficient?


I have tried to include most of the information for troubleshooting. Does anyone have any idea about what could be happening here and how I could reduce/eliminate this issue?

Looking forward to your suggestions and inputs.

Regards,
Siddharth

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#2 Post by Dany » 05 Sep 2008 20:21

Hi,
10uF and 100pF at the 5V power supply
- The 100pF should be 100nF (probably it is already), and should be placed as close as possible to the PIC Vdd/Vss connections.

-What about MCLR? What is the circuit there?
The moment I press the horn the LCD starts to display all kinds of random garbled characters. The only option is to restart the system, which is quite dangerous and cumbersome while riding
- I assume you derive the 5V for the PIC and the LCD from your motorcycle accu voltage. This is a very varying and very "dirty" source, causing the PIC to go wacky. What electronic components do you use to derive your 5V?
I would surely suggest to use a bigger elco than 10uF, especially if your LCD has backlight.

- Try to program the unconnected pins of your PIC as input and ground them.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

siddharthsh
Posts: 11
Joined: 20 Jan 2008 16:56

#3 Post by siddharthsh » 06 Sep 2008 06:11

Hi Dany,
Thanks for your response.

1) Actually, I am using a 100pF but will go for a 100nF now that you have mentioned it

2) MCLR is connected to +5VDC via a 10k resistor

3) I am getting the +5VDC through a LM7085 voltage regulator that is directly connected to the 12 Volt motorcycle battery

4) You mentioned that I should convert all the unused pins to input and ground them. What is the advantage of doing this?

Regards,
Siddharth

siddharthsh
Posts: 11
Joined: 20 Jan 2008 16:56

Another issue......

#4 Post by siddharthsh » 06 Sep 2008 07:47

Hi All,
I am trying to incorporate a Watchdog timer in my PIC using MikroC and am using a CLRWDT command to clear the WDT. However upon compiling the program I get the following error:
Undeclared Identifier [CLRWDT] in expression

Can anyone tell me how to use and clear the Watchdog timer?

Regards,
Siddharth

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#5 Post by Dany » 06 Sep 2008 10:04

siddharthsh wrote:1) Actually, I am using a 100pF but will go for a 100nF now that you have mentioned it
Yes, that is really necessary. Also the place of that capacitor plays an important role: as short as possible connected between the supply pins of the PIC.
siddharthsh wrote:2) MCLR is connected to +5VDC via a 10k resistor
This is in principle Ok, but better is also to add a cap of 100 nF to ground.
siddharthsh wrote:3) I am getting the +5VDC through a LM7085 voltage regulator that is directly connected to the 12 Volt motorcycle battery
Is probably an LM7805 in stead of 7085.
This is Ok, but: are there 100 nF capacitors accorss input and output of the 7805 (as short as possible to the 7805)?
In your case (very dirty "Vbatt") I would suggest to add between the 8705 and the motorcycle battery an DRC network: a diode (e.g.1n4148) with the anode connected to the battery, in series with that a resistor of e.g. 10R, connected to the input of the 7805, plus an elco of 1000uF (min 25V) between the input of the 7805 and its ground.
siddharthsh wrote:4) You mentioned that I should convert all the unused pins to input and ground them. What is the advantage of doing this?
It prevents them picking up electromagnetic pulses from the environment (which will be there in your case).
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

siddharthsh
Posts: 11
Joined: 20 Jan 2008 16:56

#6 Post by siddharthsh » 06 Sep 2008 16:29

Hi Dany,

Thanks for your suggestions. I tried out your method and here are the results:

1) Made a Diode + Resistor + Capacitor circuit, but as soon as I press the horn the PIC reboots. I also tried a 2200uF and a 1000uF capacitor but none seemed to work.

2) I Made the PIC and LCD run from a separate 9Volt pocket torch light battery with the circuit power and ground both separated from the bike power and ground. Now when I pressed the horn...nothing happened, the PIC did not reboot and continued to work normally. I must have pressed the horn at least 30 times but the PIC never rebooted.

3) With the PIC connected to an external battery as in #2 I also connected the GND of the PIC circuit to GND of the bike (the 12V of bike was not connected to the PIC circuit). Now when I press the horn the PIC reboots again. Upon noticing this I checked with a multimeter and found that the grounding of the bike is floating when I press the horn .i.e. when I press the horn there is a voltage difference between the negative terminal of the bike battery and the body of the bike..even though in the electrical circuit diagram of the bike it shows that the battery negative and the body of the bike are connected.

It seems to me that the ground going below zero (when I press the high current consuming horn) is causing issues in the PIC. This could be something like a floating ground issue?

Do you know what could be happening here, and what can be done to resolve this issue?

Regards,
Siddharth

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#7 Post by Dany » 06 Sep 2008 18:38

siddharthsh wrote:1) Made a Diode + Resistor + Capacitor circuit, but as soon as I press the horn the PIC reboots. I also tried a 2200uF and a 1000uF capacitor but none seemed to work.
The horn is a very EM agressive thing. Perhaps an elco (e.g. 1000 uF) and a few 100nF's accross the horn will help.
siddharthsh wrote:2) I Made the PIC and LCD run from a separate 9Volt pocket torch light battery with the circuit power and ground both separated from the bike power and ground. Now when I pressed the horn...nothing happened, the PIC did not reboot and continued to work normally. I must have pressed the horn at least 30 times but the PIC never rebooted.
This does mean that the distrurbance comes via the power supply or the ground.
siddharthsh wrote:3) With the PIC connected to an external battery as in #2 I also connected the GND of the PIC circuit to GND of the bike (the 12V of bike was not connected to the PIC circuit). Now when I press the horn the PIC reboots again. Upon noticing this I checked with a multimeter and found that the grounding of the bike is floating when I press the horn .i.e. when I press the horn there is a voltage difference between the negative terminal of the bike battery and the body of the bike..even though in the electrical circuit diagram of the bike it shows that the battery negative and the body of the bike are connected.
It seems to me that the ground going below zero (when I press the high current consuming horn) is causing issues in the PIC. This could be something like a floating ground issue?
As you say, the horn draws a lot of current. Even the smallest resistance (is not really "floating") between the chassis and the minus of the battery will cause the chassis to go negative with respect to the battery minus. Perhaps you could check this connection and make it as short and as thick as possible? Also it should become better if the battery minus was connected to the same place on the chassis where the horn is mounted. This makes the ground resistance lower and the negative voltage less.
siddharthsh wrote:Do you know what could be happening here, and what can be done to resolve this issue?
Try to avoid any connection of your PIC circuit (also those of the sensors including their shielding) to the chassis of the bike, always use the minus of the battery. Perhaps you can try test 3 with the PIC ground connected to the minus of the battery in stead of to the chassis first.

But, in the end, all proposals will help (more or less), try to implement them as good as possible...
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

siddharthsh
Posts: 11
Joined: 20 Jan 2008 16:56

#8 Post by siddharthsh » 07 Sep 2008 16:20

Hi Dany,
Thanks a lot again for your inputs on the rebooting issue, your suggestions have really helped a lot. The difference in circuit behavior is very clearly evident. The rebooting is down by almost half, and sometimes not evident at all.
Regards,
Siddharth

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

Re: Another issue......

#9 Post by xor » 07 Sep 2008 16:53

siddharthsh wrote:Hi All,
I am trying to incorporate a Watchdog timer in my PIC using MikroC and am using a CLRWDT command to clear the WDT. However upon compiling the program I get the following error:
Undeclared Identifier [CLRWDT] in expression

Can anyone tell me how to use and clear the Watchdog timer?
Do it in ASM:

Code: Select all

    asm{
        clrwdt;
       }
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

siddharthsh
Posts: 11
Joined: 20 Jan 2008 16:56

#10 Post by siddharthsh » 08 Sep 2008 14:15

Thanks Xor, that got it working!!

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#11 Post by Dany » 08 Sep 2008 15:43

siddharthsh wrote:The difference in circuit behavior is very clearly evident. The rebooting is down by almost half, and sometimes not evident at all.
Hi, I am glad it is so much better now, but I assume it is not good enough yet. :oops:

Next step is to put the PIC and as much as possible of its circuitry (so e.g. its power regulator) inside a metal box, which is connected to the ground of the PIC (and not to anything else, also not the chassis of the bike).
If you can also put the display in the same box (of course with a hole to make it visible), but try first with the LCD outside the box. If you can not place the display inside the box, then you can experiment with shielded wires to the display, but this can cause another problem: the shielded wires cause extra capacity to ground, which may be too high for the LCD speed.

The metal box should have as less as possible holes in it with wires through them (and also as less as possible without wires through them :shock: ).

This was really all I could think of.
If this is no sufficient to suppress the "horn" disturbance, then nothing will (or it might be of course that a real EMC expert has some more ideas..., perhaps you can ask them for more help :oops: ).
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#12 Post by Dany » 08 Sep 2008 15:52

3) If the unit is kept on just connected to a power source, for sometime it works fine. But after say a minute or so, the LCD only displays the dynamic data (the value of Speed and RPM) on the screen (that which is updated regularly every second) and the static data on the screen (eg: km/h and RPM characters that are output only in the beginning of execution) vanishes. So what I get is only the numeric values for Speed, RPM but the "Km/h" and "RPM" do not appear.
You can prevent this by writing to the LCD also the "static" information every time you send the "dynamic" information.
But: if the processor of the LCD itself goes beserk (it can go as beserk as your PIC) you can not do anything about it, only hope that it has a watchdog on board...

Perhaps it is not wrong to place an extra cap of 100 nF between Vcc and Gnd on the LCD board.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

siddharthsh
Posts: 11
Joined: 20 Jan 2008 16:56

#13 Post by siddharthsh » 11 Sep 2008 14:07

Hi Dany,
Thanks for the suggestions. I've removed the static data from the LCD now. Though the performance is much better, sometimes the transition is visible. I also noticed another thing: I tried the same program on another PIC (from a different supplier) on a slightly different board and the thing never reboots. Could there be a difference in the quality of PIC from one supplier to the other? What do you think?
Regards,
Siddharth

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#14 Post by Dany » 14 Sep 2008 08:57

siddharthsh wrote:Hi Dany,
Thanks for the suggestions. I've removed the static data from the LCD now. Though the performance is much better, sometimes the transition is visible. I also noticed another thing: I tried the same program on another PIC (from a different supplier) on a slightly different board and the thing never reboots. Could there be a difference in the quality of PIC from one supplier to the other? What do you think?
Two things are different: the board (only slightly) and the PIC. To be sure that there is a difference between the PIC's (which could be possible i think) you should try them on the same board of course. :D Perhaps the layout of the "bad" board is such that it is bery sensitive to EM disturbances.

But: it seems your problem is solved sucessfully?
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroC General”