Delay incorrect

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
echase
Posts: 429
Joined: Mon Jun 11, 2007 11:55 am
Has thanked: 49 times

Delay incorrect

Post by echase »

I need a 4.9 second delay so I have put in a 4 sec delay then a 900 msec one. But it simulates to a >150 sec delay. And in the real 18F25210 PIC it isn’t right either, although not sure what it is coming out to there.

Seem to remember this problem before but can’t remember the solution. Does it not like more than say 256 msec delay?

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: Delay incorrect

Post by Benj »

Hello

When dealing with delays in Flowcode you must get two things correct for the delays to be correct.

1) The Flowcode clock speed,

This is configured in the Chip -> Clock speed menu. This assigns the number of loops needed for specific delays. Make sure this value matches your crystal or internal oscillator frequency,

2) The chip hardware clock speed,

This is configured by the Chip -> Configuration settings to use either a fixed frequency oscillator or an internal oscillator. If you are using the internal method then you will have to refer to the chip datasheet for clock speed settings.

It sounds like either your Flowcode clock frequency is set far too high or your chip configuration is incorrect.

echase
Posts: 429
Joined: Mon Jun 11, 2007 11:55 am
Has thanked: 49 times

Re: Delay incorrect

Post by echase »

Yes but no but. I have the right clock speed set but can’t absolutely guarantee the fixed frequency oscillator or an internal oscillator is right, however the circuit basically works so it’s probably right. Many other delays of around ½ to 1 secs that I use are all simulating / running (aprox) correctly, so why is only this one vastly wrong? When it simulates a little progress box comes up that ticks through 180 or so secs. It does not do that for the smaller delays even though they are within an order of magnitude.

Can't see that misentering the clock frequency would affect the simulation as it should just self adjust to get the right delays.

One thing I am not clear about is the frequency to set for the internal oscillator. E.g. the datasheet states a frequency of 125kHz. Is that entered into Flowcode as 125,000 exactly or is it some near equivalent like 262144 i.e. 2^18. And what does the PIC/Flowcode do if I enter a number that is slightly out such as 126,000? Does it assume I meant 125,000 or give up the ghost and revert to one end of the scale like 8,000,000?
Last edited by echase on Mon Dec 22, 2008 4:46 pm, edited 1 time in total.

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: Delay incorrect

Post by Benj »

Hello

Ok if the Flowcode simulation is off then this does not rely on the clock speed variables sorry.

Best guess is one of your delays for 180ms has been accidentially switched to seconds and is now causing the long delay.

When setting the frequencies is this for the internal oscillator? You will see that the internal oscillator only has a few values you can configure it to. There will be no in between values. For the Flowcode clock speed setting please enter a decimal number that matches your chip setting. Eg the value of your external crystal or the value you have written to the internal oscillator configuration register osccon.

echase
Posts: 429
Joined: Mon Jun 11, 2007 11:55 am
Has thanked: 49 times

Re: Delay incorrect

Post by echase »

Sorry, the delay was not 4 secs as I was reading an incorrect value off the EEPROM which just had a random number stored. When corrected Flowcode simulates a 4 secs as about 5 secs whatever clock speed I set which is good enough.

However I may not have the right config/OSCON words for the oscillator. PPP lists 12 clock types. I want “INTIO1 Internal Oscillator with FOSC/4 output on RA6 and I/O on RA7” but PPP does not seem to list this one exactly but I assume it disguised as “INT RC CLKOUT on……” ? If I use that one I am getting the CLKOUT signal but the “4 sec” delay is about 10secs with a 125kHz set speed and 15secs at 250k. At 31kHz it’s about right. Surely the real delays should not vary with clock speed as Flowcode should recalculate the clock cycles per second delay to get them right, unless I have got the config words wrong? Also, if there was an error, I would expect the delays to get shorter the higher the clock and not vice versa. So something is wrong somewhere.

I have a statement in C of oscon=0x08A at beginning of my code, possibly a hangover from when I used an 886 PIC. I guess that could be messing it up. Would it be better to edit this to the correct value to match the clock speed and what would that line be for a 125k clock speed, which is what I am trying to use? Or does Flowcoide write its own oscon statement from the clock speed I enter in its menu?

In experimenting I am entering 31k as 31000. But the datasheet says that strictly it is 31250 for the internal precision oscillator and 31000 for the non precision internal one. Which number does Flowcode recognise and what does it default to if I type in a number that is not exactly correct?

echase
Posts: 429
Joined: Mon Jun 11, 2007 11:55 am
Has thanked: 49 times

Re: Delay incorrect

Post by echase »

Or to summarise all that into one line, does Flowcode set OSCCON or do I have to do it in C?

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

Re: Delay incorrect

Post by Steve »

That's an easier question to answer...

No - Flowcode does not set osccon at all. The entry of numbers into the "clock speed" window is only used to create the appropriate code for delays.

Post Reply