PDA

View Full Version : 4Mhz Circuit with a 20Mhz PIC



koossa
- 16th October 2007, 18:20
Good day Picers!

I have layout an easy LED blink circtuit at 4Mhz.
I only have 20Mhz PICs, 1 x PIC16F877-20l/P and 2 x PIC16F877-20/P

When I program the PIC16F877-20l/P @ 4Mhz it works fine, but when I program the PIC16F877-20/P it does not work and it's exactly the same circuit.

Is there any setting to get this Pics working @ 4Mhz?


Thank you!
Koossa

Kamikaze47
- 16th October 2007, 19:08
I assume you have the following line at the top of your PBP program:

DEFINE OSC 4

Thats the only setting I can think of that you would need to worry about.

What does happen? Does everything happen at the wrong speed, or does the PIC refuse to do anything at all?

koossa
- 16th October 2007, 19:25
Here is my code, and nothing at all happen
With the PIC16F877-20l/P it is working, but when I switch it with the PIC16F877-20/P it does not work.


<code>
&nbsp;&nbsp;Include "Modedefs.bas"

&nbsp;&nbsp;DEFINE OSC 4 ' Set the Xtal frequency to 4mHz

&nbsp;&nbsp;LEDPin VaR PORTC.2
&nbsp;&nbsp;i var byte

Main:
&nbsp;&nbsp;for i = 1 to 10
&nbsp;&nbsp;&nbsp;&nbsp;High LEDPin
&nbsp;&nbsp;&nbsp;&nbsp;Pause 400
&nbsp;&nbsp;&nbsp;&nbsp;Low LEDPin
&nbsp;&nbsp;&nbsp;&nbsp;Pause 400
&nbsp;&nbsp;next i
end
</code>

Jumper
- 17th October 2007, 00:49
Hi,

At 20 MHz I guess you use "HS" for 20 MHz but for 4 MHz "XT" would be a better choice.

What do you clock it with? do you have a 4MHz x-tal or osc?

/me

koossa
- 17th October 2007, 06:05
Jumper

Thank you very much for your feedback.
I do have my Oscillator setting on "XT" and I'm using a 4Mhz X-tal.

Koossa

paul borgmeier
- 17th October 2007, 15:57
... a long shot but try blinking RB0 instead of RC2 (and report back).

koossa
- 17th October 2007, 16:31
I have moved my LED to RB0 and change my code, but not one of them are working now.
Am I missing something?


<code>
&nbsp;&nbsp;Include "Modedefs.bas"

&nbsp;&nbsp;DEFINE OSC 4 ' Set the Xtal frequency to 4mHz

&nbsp;&nbsp;LEDPin VaR PORTB.0
&nbsp;&nbsp;i var byte
Main:
&nbsp;for i = 1 to 10
&nbsp;&nbsp;High LEDPin
&nbsp;&nbsp;Pause 400
&nbsp;&nbsp;Low LEDPin
&nbsp;&nbsp;Pause 400
&nbsp;next i
end
</code>

mackrackit
- 17th October 2007, 16:42
Have you tried Oscillator setting on "HS"?

koossa
- 17th October 2007, 16:52
No
I will try

koossa
- 17th October 2007, 17:19
I have set it to HS, but still nothing.

Bruce
- 17th October 2007, 19:53
Attach the compiled .HEX file that you are programming into the PIC here. If there's a
problem with your config settings, that makes it easy for someone to spot.

koossa
- 17th October 2007, 20:03
Bruce

Attached the zipped hex file.

Thank you very much for your time!

Bruce
- 17th October 2007, 21:04
Hi Koossa,

The good news is - config settings look fine. XT osc, WDT on, PWRT on, brownout on,
LVP off, protection off. Looking good here if you're using a 4MHz external crystal.

The bad news is - this code isn't anywhere near what you show above just trying to
toggle an LED.

It sets up the USART for 19,200bps at 4MHz, shoots out a single letter f, then sits & spins
waiting for serial data input, in a loop watching the RCIF flag bit.

Are you 100% sure you're actually programming the file you expect into your 877?

The .HEX file you have attached is for sure not the one you show above trying to toggle
an LED....;o}

Archangel
- 17th October 2007, 23:37
Hello Koossa,
try adding this to your code:

CCP1CON = 0 ' DISABLE CAPTURE COMPARE MODULE
TRISC = %00000000 ' SET ALL PORT C TO OUTPUTS


JS

Charles_Leo
- 18th October 2007, 23:55
I think this code was compiled using the MicroCode Studio Plus ICD Compile. It won't run in the PIC unless there is an ICD connection to the PC.

If you intended to run the code without the ICD, find the "normal" compile/program buttons in MicroCode Studio Plus. Don't use ICD Compile or ICD Compile And Program unless you have the ICD connection hooked up.

koossa
- 19th October 2007, 17:35
I think this code was compiled using the MicroCode Studio Plus ICD Compile


Thank you Charles_Leo, you are correct, it's been a while since I last use this software so I was a bit rusty.

Joe S., I have added your code and everything is working now


CCP1CON = 0 ' DISABLE CAPTURE COMPARE MODULE
TRISC = %00000000 ' SET ALL PORT C TO OUTPUTS


Thank you very much!!!