PWM & Osc Frequency issues with 16F737

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

PWM & Osc Frequency issues with 16F737

Post by medelec35 »

I am probably missing something basic.

My problem is I have set PWM at a frequency of 5KHz on a 16f737 with a clock (using internal clock ) frequency of 4MHz. This gives a period time of 200 microseconds. Flowcode simulator is displaying correct frequency and PWM.

When chip is programmed (config 1 = 0x3F98, config 2 = 0x3FBD) and power applied, I only get a period of 40 milliseconds = 24Hz. The duty cycle is correct.

Looking at the data sheet, OSCCON (8Fh) bits 6-4 should be set 110 for 4MHz, but looking at special function registers in a different simulator only bit 4 is set.

Is Flowcode supposed to auto set clock for 4MHz and then internal clock is enabled by config settings?

If I have set config settings wrong, what should they be set at?

Any ideas on how I can run PWM at correct frequency in hardware please?

Also is there a simple way of displaying SFR’s and values in Flowcode simulator?
Last edited by medelec35 on Thu Feb 05, 2009 5:50 pm, edited 1 time in total.
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PWM & Osc Frequency issues with 16F737

Post by Benj »

Hello

Sounds like the internal oscillator is running at a much slower speed then expected.

The speed control in Flowcode configures the timings for delays etc but will not change anything in the chip configuration etc.

At the very start of your program add a C code icon containing the following.

osccon = 0x70;

This will start the internal oscillator running at 4MHz to match your defined speed in Flowcode.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PWM & Osc Frequency issues with 16F737

Post by medelec35 »

Thank you for your fast responce.

Your solution did work.

one minor correction

osccon = 0x70; = 8MHz osc.

and

osccon = 0x60; = 4MHz osc.

Is there a answer to 'Also is there a simple way of displaying SFR’s and values in flowcode simulator?' please.

Would it be a good idea for a future flowcode update to have a dropdown box to select type of osc, and if internal, then flowcode can automaticly set int osc at selected chip clock speed?
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PWM & Osc Frequency issues with 16F737

Post by Benj »

Hello

Ah yes sorry about that, the 4MHz option is much more likly to work :)

As for the SFRs - Standard Function Registers (took me a while there) Flowcode V3 cannot do anything as it basically knows nothing about the C code or chip type, The BoostC compiler handles all of this. We have something up our sleeve for V4.

For now if you want to view register contents I would write a simple program to output the values onto LEDs or into a PC via RS232 or USB.

Good idea with the internal oscillator speed selection, maybe we could work this in somehow.

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: PWM & Osc Frequency issues with 16F737

Post by Steve »

medelec35 wrote:Would it be a good idea for a future flowcode update to have a dropdown box to select type of osc, and if internal, then flowcode can automaticly set int osc at selected chip clock speed?
This is a good idea. However, it's not as simple as it seems because Flowcode does not understand the configuration data for each chip (and this would be difficult to do because the chips have many different ways of representing the oscillator types in their config bits).

Also, the current "clock speed" setting in Flowcode only tells Flowcode the intended speed of the hardware. If it was also used to set the speed of the hardware, but then only in certain situations (i.e. when the user has correctly entered the appropriate config data to set the chip into INTRC mode), then this would cause more confusion than it does presently.

An alternative would be to provide a simple component that provides an easy way of setting the internal oscillator frequency, and inserts the appropriate C code at the beginning of the program. But I cannot promise this quickly, because we have so much work to do at the moment...

Post Reply