PDA

View Full Version : Problem with 16F737



rangerdoc
- 29th October 2007, 01:53
I'm having problems with my first PIC project. I'm using a PIC 16F737 to make a 16 channel fireworks sequencer. The breadboard prototype works great. The only issue I have is that "Pause 1" is giving me approx 134mS of delay, not 1 mS. Pause 100 gives me 13.4 seconds, not 100mS & that is maximum. Pause 1000 also gives me 13.4 seconds delay. I'm using the internal oscillator. Could this be the source of my problems?

stevecrunch
- 29th October 2007, 02:04
Hi,

Take a look at the PicBasic Manual. It's well explained and a free download.

If you use a 4 MHz crystal, Pause is in milliseconds so...

Pause 1000 will pause 1 second

You can pause up to 65 535 milliseconds (16 bits)

Your problem could be your clock or you oscillator calibration value. Last address in the program memory.

rangerdoc
- 29th October 2007, 02:30
It may be too well explained, because it's absolutely Greek to me. Most of the manual and all of the datasheet are over my head.
Frankly, I don't even know what you mean by "last address in the program memory".
I've got the datasheet & can't really see anything beyond some vague references here & there to OSCCON & OSCTUNE, but nothing about how to use them. The PBP manual say to "see the speed section", which I can't find.

stevecrunch
- 29th October 2007, 02:45
I'll try to explain more. Anyoone can feel free to add.

Your PIc has 2 types of memory. Program and data memory. Your program is compiled and loaded int o program memory. Your data is stored in data memory which is volatile memory meaning when you power off your PIC, it is erased.

Your memory is divided into addresses. The last address in your program memory has a value put in by Microchip. This value calibrates your PIC as close as possible to the clock specified in the datasheet. If you erase your chip, you lose your calibration value. So the first thing you should do when you put a PIC in your programmer is read it and write this value down on paper in case you overwrite it by accident. This value is unique to each PIC.

What i'm not so sure of is, will this value make your PIC go to 4.00000000 MHz or will it be off a little. Maybe someone else can answer that????? Is this value good enough for serial communication?

rangerdoc
- 29th October 2007, 03:23
I get the feeling we're talking about two different things here:
I'm not looking to trim or calibrate the internal oscillator for communications or anything precise. The PIC 16F737 has several internal oscillator frequencies. Mine appears to be running at the 35kHz instead of 4MHz. I have no idea of how to change it.
Let me clarify the project. I'm building quite a few of these sequencers... Dozens. I want to use the internal oscillator to keep parts & cost to a minimum.
These are really simple. One digital input, 16 outputs... nothing more. no communications. I have my existing firing panels which will trigger the input high via an optocoupler. The outputs with then go high at the intervals defined by the delay variable. That's it.
I really have no need to go any deeper with PicBasic or with PICs than this as these boards are my end goal. Once they are working, I'm done. I just need the outputs to sequence faster than they are now.
Hope this helps.

rangerdoc
- 29th October 2007, 03:42
Got it. Searching the forum did it once I knew what to look for:

http://www.picbasic.co.uk/forum/showthread.php?t=813

I entered the line "OSCCON = $60" & that got the clock running at 4MHz.

Bruce
- 29th October 2007, 03:53
You need to write to the OSCCON register to select 4MHz. The default value of OSCCON at
power-up is all 0's. That sets the internal osc at 31.5kHz by default.

OSCCON = %xxxxxxxx (replace x's with value shown in data sheet for selecting 4MHz)

Edit: Nice work. It's not that hard is it...;o}

Not bad for your first PIC project.

stevecrunch
- 30th October 2007, 01:04
I think Bruce nailed it. Good answer Bruce.

I have 2 questions concerning that. 1st one I already asked.

1. Are the internal oscillators precise enough to do serial communication?

2. Do all chips have OSCCON? I search the 16F676 PDF... nothing

hmm??????????

Bruce
- 30th October 2007, 03:15
1. Are the internal oscillators precise enough to do serial communication?
Yep. Newer parts with 1% internal oscillators are.

As long as the PIC will operate in a moderate environment like indoors. If you plan to use
it outdoors in extreme heat or cold, go with an external crystal. The internal osc will drift
when exposed to extreme temperatures.


2. Do all chips have OSCCON? I search the 16F676 PDF... nothing
No not all of them have an OSCCON register. Most of them with an internal oscillator that
offers various speeds do. So you can select or change internal osc speeds.

The 16F676 doesn't have an OSCCON register. Its internal osc is fixed at 4MHz. It does
however have a factory calibration value tucked away in the last program memory space.
You tell PBP to fetch & load this into the OSCCAL register with the DEFINE OSCCAL_1K 1
option.

stevecrunch
- 7th November 2007, 03:09
Many Thanx to you.