Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

strange problem pic16f877a

Status
Not open for further replies.

5282604

Full Member level 4
Joined
Dec 19, 2009
Messages
194
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
egypt
Activity points
2,407
i use xt 4mhz crystal and i try long time and no solution.
the problem is. i make simple loop. on and off an led with 500ms delay . it work in simulation .
but in my circuit it's take about 10sec to flashing led. :?:
 

mailus

Full Member level 4
Joined
Mar 6, 2012
Messages
234
Helped
7
Reputation
16
Reaction score
7
Trophy points
1,308
Location
-
Activity points
2,706
Post your code.
what compiler you are using?
And also specify your microcontroller?
 

5282604

Full Member level 4
Joined
Dec 19, 2009
Messages
194
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
egypt
Activity points
2,407
mikroc pro 4.6
chip pic16f877a
crystal 4mhz xt


void main() {
TRISD=0x00; // TRISD OUTPUT

while(1){
portd=1;
delay_ms(500);
portd=0;
delay_ms(500); }
}


work in simulation . but in my real circuit delay is 10 sec no .5sec
 

pjmelect

Advanced Member level 2
Joined
May 13, 2012
Messages
526
Helped
120
Reputation
240
Reaction score
120
Trophy points
1,323
Activity points
4,347
I don't know C very well but your code looks OK, my thoughts on this is what about the configuration word? You should ensure that the watchdog timer is off and you could also try HS mode instead of XT mode in the crystal configuration bits.
 

mailus

Full Member level 4
Joined
Mar 6, 2012
Messages
234
Helped
7
Reputation
16
Reaction score
7
Trophy points
1,308
Location
-
Activity points
2,706
You must turn off analog module and comparator.by adding this code we can turn off these module.
Adcon1=0x07;
Cmcon=0x07;

- - - Updated - - -

void main() {
Adcon1=0x07;
Cmcon=0x07;
TRISD=0x00; // TRISD OUTPUT
while(1){
portd=1;
delay_ms(500);
portd=0;
delay_ms(500); }
}
 

5282604

Full Member level 4
Joined
Dec 19, 2009
Messages
194
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
egypt
Activity points
2,407
You must turn off analog module and comparator.by adding this code we can turn off these module.
Adcon1=0x07;
Cmcon=0x07;

- - - Updated - - -

void main() {
Adcon1=0x07;
Cmcon=0x07;
TRISD=0x00; // TRISD OUTPUT
while(1){
portd=1;
delay_ms(500);
portd=0;
delay_ms(500); }
}
i try this code and the problem is still.

- - - Updated - - -

I don't know C very well but your code looks OK, my thoughts on this is what about the configuration word? You should ensure that the watchdog timer is off and you could also try HS mode instead of XT mode in the crystal configuration bits.
yes i do this
 

kripacharya

Banned
Joined
Dec 28, 2012
Messages
1,209
Helped
182
Reputation
360
Reaction score
175
Trophy points
1,343
Location
New Delhi
Activity points
0
i use xt 4mhz crystal and i try long time and no solution.
the problem is. i make simple loop. on and off an led with 500ms delay . it work in simulation .
but in my circuit it's take about 10sec to flashing led. :?:
most likely problem is that you think you are using 4mhz, but actually clock is not 4mhz. PIC has many clocking modes, and you have to do all the settings to make sure it is using external crystal and not (for example) internal RC mode
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,366
Helped
4,727
Reputation
9,469
Reaction score
4,495
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
122,588
The "delay_ms()" function is a software generated delay and as such it needs to know how many instructions to loop through to generate the required time. Check you have a line in your code, somewhere near the top or a configuration setting somewhere to tell it that the clock is 4MHz. If it assumes a different clock frequency is being used the delay will be wrong.

Brian.
 

jjeevan007

Full Member level 5
Joined
Apr 13, 2012
Messages
311
Helped
44
Reputation
88
Reaction score
43
Trophy points
1,308
Location
bangalore
Activity points
2,781
post the full code

tell us which is the compiler you are using

and also post the your circuit
 

mailus

Full Member level 4
Joined
Mar 6, 2012
Messages
234
Helped
7
Reputation
16
Reaction score
7
Trophy points
1,308
Location
-
Activity points
2,706
check crystal in board.
 

5282604

Full Member level 4
Joined
Dec 19, 2009
Messages
194
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
egypt
Activity points
2,407
#7
i set clock in mikroc at 4mhz.

#8
yes delay_ms is software generated delay.

#9
post code in post 5# , i use simple circuit pic + reser resistor + crystal and 2 cap i try 22p and 15p and no capictor and problem still

#10
i try 3crystal and problem is still.

-------------------------------------------

- - - Updated - - -

1.png
2.png
 

kripacharya

Banned
Joined
Dec 28, 2012
Messages
1,209
Helped
182
Reputation
360
Reaction score
175
Trophy points
1,343
Location
New Delhi
Activity points
0
post your actual circuit

most likely problem is that you think you are using 4mhz, but actually clock is not 4mhz. PIC has many clocking modes, and you have to do all the settings to make sure it is using external crystal and not (for example) internal RC mode
 

5282604

Full Member level 4
Joined
Dec 19, 2009
Messages
194
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
egypt
Activity points
2,407


i use this circuit but without diode and i use 4mhz crystal.


when i remove 4mhz crystal from my circuit the pic16f877a is work but slow" see post 1# " . it's means pic16f877a clocked by internal osc.
 

wp100

Advanced Member level 5
Joined
May 15, 2009
Messages
3,056
Helped
883
Reputation
1,781
Reaction score
736
Trophy points
113
Location
Prime Meridian
Activity points
0
Hi,

The 16F877A does not have any internal oscillators, only external ones.

If the led is flashing very slowly with the crystal removed, its just by chance / random oscillations.

How have you built your circuit, on a pcb, hand wired or on a breadboard ?

How far from the chip is the crystal ? - it should be as close a possible.

Have you got boths sets of power rails connected ? pins 11 and 12, and 31 and 32.

Have you got a 100nf cap across pins 11 and 12 ?


What are you using for a power supply ?


A picture would help ..
 

jjeevan007

Full Member level 5
Joined
Apr 13, 2012
Messages
311
Helped
44
Reputation
88
Reaction score
43
Trophy points
1,308
Location
bangalore
Activity points
2,781
how many pic microcontroller you are using................

change the pic microcontroller and see, i mean the microcontroller which u are using may be got damaged.................

otherwise first check whether your pic miicrocontroller working fine or not..........
 

pjmelect

Advanced Member level 2
Joined
May 13, 2012
Messages
526
Helped
120
Reputation
240
Reaction score
120
Trophy points
1,323
Activity points
4,347
If the crystal is removed and the circuit still works albeit very slowly, it means that the configuration bits for the oscillator are set for RC mode not XT or HS mode.
 

kripacharya

Banned
Joined
Dec 28, 2012
Messages
1,209
Helped
182
Reputation
360
Reaction score
175
Trophy points
1,343
Location
New Delhi
Activity points
0
Hi,

The 16F877A does not have any internal oscillators, only external ones.

If the led is flashing very slowly with the crystal removed, its just by chance / random oscillations.
good catch wp100. though i noted that '877A does have an internal RC osc for the watchdog, and there's some mention of an internal RC osc for the ADC ?
with crystal removed, there should ideally be no random oscillations - why would there be ?

so here is a theory --
the watchdog is not disabled, but there is also no Fosc with crystal removed. hence the WD keeps activating the mcu and makes it step through the code very slowly ?

maybe OP should check if his crystal is operating at 4Mhz or not, and all settings for this are properly set. if only he has an oscilloscope ??
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,366
Helped
4,727
Reputation
9,469
Reaction score
4,495
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
122,588
The watchdog causes a reset so it can't step through the code. If the power pins are not all connected and the decoupling capacitors are missing it is possible the crystal oscillator is not running in fundamental mode or is randomly pulsing.
The WDT and ADC internal RC clocks can't be used to drive the PCLATH/PCL so it isn't possible they are the problem.
We need a FULL schematic to give a better diagnosis, the one provided doesn't even show the errant LED!

Brian.
 

kripacharya

Banned
Joined
Dec 28, 2012
Messages
1,209
Helped
182
Reputation
360
Reaction score
175
Trophy points
1,343
Location
New Delhi
Activity points
0
We need a FULL schematic to give a better diagnosis, the one provided doesn't even show the errant LED!

Brian.
well said !! without better inputs, it is useless trying to help
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top