How to set timing?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

How to set timing?

Post by JDR04 »

Hi members, wondering if somebody would be able to help me set up the timings in my flowchart.

I have built the circuit on veroboard but fing that the timings are way out. Originally I wanted a maximum of 30 seconds for each setting, delay on, on and time out. I'm thinking its got something to do with the oscillator settings but know how to go about setting it up.

Currently the maximum is about 150 seconds.

I have attached my flowchart that was constructed with the kind help of Martin and others.

Thanks again, John
Attachments
IRTRIGGER.fcf
(16.5 KiB) Downloaded 268 times

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: How to set timing?

Post by medelec35 »

Hi John,
You have got the clock speed within project options set to:
20000000 =20MHz.
The internal osc is set by osccon command and not by the clock settings within project options.
If you don't add an osccon=0xxx; then the internal osc will default to 4MHz on these chips.
So you will need to change your clock speed to 4MHz
The clock settings in project options, only affect the delays that components rely on to work e.g Delays, LCD, I2C RS232 etc.
Since your chip is running at 4Mhz all delays will be wrong since flowcode will be calculating delays using 20000000 instead of the correct 4000000.
Since 20000000/4000000 is 5 then delays well take 5 times longer than expected.

Hence 30 seconds required = 30 * 5 = 150.
Which indeed is what you are seeing.

If you're interested at setting the internal osc to run at a different speed, you can look at the data sheet for 16F690.
Look for the osccon values, then set up as This
The table you're looking for should look like the one above

Hope this helps

Marin
Martin

JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: How to set timing?

Post by JDR04 »

OK, I'm not sure if I understand this right but here goes...............

The table you refer to I think is the one on page 47 of the datasheet. I t seems that with the 16F690 you can set two clock speeds, 8Mhz and 4Mhz.

8Mhz has the number 111 next to it and 4Mhz has 110 next to it which I assume are decimal numbers that need tio be converted to HEX.

Then I need to insert a C CODE box right at the very beginning of the flowchart? ie..... oscon=0 X 70 for 8Mhz.

Would appreciate you guys keeping me right on this......Thanks again ...John
Attachments
16F690 Datasheet.pdf
(4.23 MiB) Downloaded 283 times

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: How to set timing?

Post by medelec35 »

Hi John, I did state at the begining these chips default to 4MHz, if you left out the osccon altogether.
The diagram posted is just a guide, and it will be required if
A) you want a speed any other than the default 4MHz
or
B) you use a different chip that does not have 4MHz as a default

So with your chip the osccon is not require as you was running it at 4MHz.

I guess you will require the osccon setting for 4MHz if you started running he chip at say 8MHz, then decided to change to 4MHz 1/2 way though?
JDR04 wrote:8Mhz has the number 111 next to it and 4Mhz has 110 next to it which I assume are decimal numbers that need tio be converted to HEX.

Then I need to insert a C CODE box right at the very beginning of the flowchart? ie..... oscon=0 X 70 for 8Mhz.
That is correct you can set the internal psc frequency to 8MHz by placing osccon=0x70; at the very start of the flowchart.
In fact you can set the osc to run at any of the speed listed.
So internal osc can run at:
8 MHz
4 MHz (default)
2 MHz
1 MHz
500 kHz
250 kHz
125 kHz
31 kHz (LFINTOSC)

It does not have to be hex, you can use binary for 8MHz:

Code: Select all

osccon=0b1110000;
Or Decimal:

Code: Select all

osccon=122;
I just use hex because the numbers are easier to remember for me!
There is no right or wrong number format, its just down to personal choice.
Don't forget the semicolon that is required on the end of C statements.

Perhaps to see if its clear you can tell me what osscon value is required if I want to run internal osc at 1MHz?
Martin
Martin

JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: How to set timing?

Post by JDR04 »

Would I convert 1000000hz to HEX

osccon=0xF4240;

I measnt to ask you if you thought the program would be stable if run at 8Mhz or would it be best to stick to 4Mhz. Whats your experience with this?

Thanks a lot.......John

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: How to set timing?

Post by medelec35 »

Hi John,
No thats not correct.
osccon like the other registers are only 8 bits wide (0 to FF).
Best way to determine correct value of osccon is look at the link I posted on my first post and if you're up for it then take a look how I determined correct value and give it another try.
Don't forget we are not trying to convert the actual frequency but looking up what the correct osccon value is for the desired frequency.
JDR04 wrote:I measnt to ask you if you thought the program would be stable if run at 8Mhz or would it be best to stick to 4Mhz. Whats your experience with this?
8MHz is fine.
Should run very stable.

These days even 8MHz is not that fast compared with internal osc of 16 & 32MHz you get in the more up-to date like 12F840, 16F1824 + the 18F series.

Martin
Martin

JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: How to set timing?

Post by JDR04 »

Sorry mate, I dont get it.

When looking at the link you provided, the table shows 1011 next to it. So I assume this is the binary value equivalent to 1Mhz?

If I used the binary number instead would it be osccon=0b00001011?

Man I'm lost on this and really appreciate your patience in trying to show me the way. Thanks...John

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: How to set timing?

Post by medelec35 »

No problem it is a tricky one.

If you refer to table you mentioned from 16f690 datasheet on page 48 , you can see for 1MHz its shows as 100 since it also shows bit 6-4 then 1=bit6,0=bit5, last 0=bit4 we are not interested in the bits higher so bit7 can be ignored.
what I do is add an additional 0 for every bit left below bit 4.
so we got a 0 for bit3, a 0 for bit2 a 0 for bit1 and finally a 0 for bit0
place them after the 100 and you have 0b1000000 = 40 Hex (don't forget 0b just means the following numbers will be in a binary format)
therefore for 1MHz

Code: Select all

osccon=0x40;
Do the same thing for 4MHz although just for exercise purposes as it not require for the 16f690
4MHz from table = 110 then bits 3 - 0 require adding on the end I have put in bold
1100000 use windows calculator to convert from bin to hex:
0b1100000= 0x60
Therfore

Code: Select all

osccon = 0x60;
Does that help?
Martin

JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: How to set timing?

Post by JDR04 »

Hi Martin, thanks ever so much for your patience with this.

I'll go through it in the morning and make sure I understand.

Thanks again and take care.....John

Post Reply