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
Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Timing

Post by Xavier »

Hi guys

I'm trying to get a timing in us, I used osccon=0x20; but I seem to be lost now, how do I get the LCD to display the correct frequency? also I have noticed that the display slows down the PIC a lot, using these frequencies, should I not have a second PIC to control the LCD? can I use the internal clock or should I use a crystal?

All the best
Xavier

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: Timing

Post by medelec35 »

Hi Xavier, can you post a flowchart so we can see the target device and configuration settings etc.

Martin
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: Timing

Post by Xavier »

Ho dear I thought that I had LOL I forgot to click on add the file.

Regards
Xavier
Attachments
PI_Simple (2).fcf
(23.58 KiB) Downloaded 266 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: Timing

Post by medelec35 »

The osccon sets the internal oscillator speed.
To set speed at the required value see:
http://www.matrixmultimedia.com/mmforum ... 29&#p28829

It's important that clock speed in project options matches the osccon value.
Yours do not.
You have osccon set at 250KHz (not recommended at its too slow) but the clock speed is set at 19.66MHz so they don't match.
The clock speed in project options does not set the internal oscillator speed of the microcontroller, it's mainly used for delay timings.
The osccon is used to set the actual speed of internal microcontroller clock.
Crystals, resonators are used for setting the external oscillator frequency.

So with osc running at 250KHz microseconds delays are going to be tricky.

You will need to set internal osc for the highest speed possible.
with 16F690 its 8MHz. so osccon is set at 0x70;
Clock speed in build options has to also be set on 8MHz then LCD should work fine.

Martin
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: Timing

Post by Xavier »

Thanks Medelec35

Thanks for the info I had no clue that they had to be the same.
The thing is that there is no 8mhz in Build - Project option but I do have 4Mhz so I've set osccon at 0x60, am I looking in the wrong place? I also see that this sets the interrupt frequency at 3906.250Hz is this OK? Could you also point me in the right direction so as to be able to read the correct pulse rate on the LCD? One more thing what would be the best pot value to use with the ADC?

All the best
Xavier

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: Timing

Post by medelec35 »

Xavier wrote:The thing is that there is no 8mhz in Build - Project option
You will need to manually change the first digit from a 4 to 8
So you have 8000000 instead of 4000000
You don't have to use the fixed values, you can enter your own.
I personally would go for the 8MHz instead of 4MHz
Reason being Flowcode converts flowchart to C then after Compiled into hex.
At 4MHz each assembly line takes a small time e.g 1 - 2 us depending on the assembly instruction.
There are approximately 9 assembly lines for every delay function.
This means the minimum delay without dong anything else is about 13us
Since after delay something else has to be done e.g set o/p high then your talking 21ish microseconds.

Xavier wrote:I also see that this sets the interrupt frequency at 3906.250Hz
It depends on what your trying to achieve with the interrupt.
A guide is set the interrupt for as low frequency as possible, to the nearest whole number.
Xavier wrote:what would be the best pot value to use with the ADC?
Probably in the region of 4K7 to 10K.
The higher the resistance the more the ADC value will be changing by outside influences.
The lower the resistance the more power will be used, and if power exceeds the rating of the pot, then it will get damaged.


Martin
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: Timing

Post by Xavier »

Thank's Martin

This has cleared up quite a few things. Now to put them into practice. I think that if I want to get a very precise timing I should use one PIC just to do timing, I have a delay before the sample of 10 to 15us so if the delay between macros and the sort is 21us, I have a problem. I think that I should use another PIC to do the rest of the work where the timing is not important like Update LCD and turning things on and off, by doing it this way I could keep a very short macro. What is your opinion?

All the best
Xavier

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: Timing

Post by medelec35 »

Hi Xavier.
If it was me I would probably use a PIC that has PLL so I can get the internal osc running as fast as possible.
If accuracy was critical then I would consider using a more accurate external crystal with PLL enabled.
Even if you use two pic's one of them will have to run at the highest clock rate possible e.g 32 to 48MHz to achieve the shortest delay time.

I had a thought.
A different way of obtaining a short delay for lower clock speeds like 4MHz is to use a Code block with nop (used in assembly).
a nop command will take 1 clock cycle = 1/(Clock speed/4) = 1uS
E.g you want 4us you can use a c code block with:

Code: Select all

asm
{
nop
nop
nop
nop
}
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: Timing

Post by Xavier »

Hi Martin

I changed the clock speed to 8Mhz, I removed all the LCD, switches and LED's from my flow chart so that should make it quite a bit faster, Now I'm going to try out the nop but the problem is that I need to use the ADC to be able to set the required speed, well at least for now. Once the detector is functioning like it should I can set the time once and for all, no more need for the ADC nor any pot's, the LED's are only there to show me whats happening and the LCD for me to be able to read the timing as I do not have a scope any more. Once this code is working like it should I'll be using it for all my new PI detectors, for this reason I want it to be as accurate as I can make it.

All the best
Xavier PS thanks for the assistance

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: Timing

Post by medelec35 »

At 8MHz will allow you to have lower value delays and they should be within 2us

So if you choose 4us the actual delay from start to return part will be 6us.
So if that is accurate enough, then you have it sorted.

Martin
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: Timing

Post by Xavier »

Thanks Martin

I will keep in mind the extra 2us. I'll see if I can get the display to show the required delay range that I need, if i can get it from 5 to 50us then I should be fine. I'm not sure on the formula that I need to use to have the display show the correct value though.

Regards
Xavier

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: Timing

Post by medelec35 »

Xavier wrote:I'm not sure on the formula that I need to use to have the display show the correct value though.
If you readAsByte then:
Delay = Delay * 9 / 50 + 5

So before the formula Delay is 0 to 255 then after formula Delay should be 5 to 50
Martin

Xavier
Posts: 99
Joined: Sat Mar 17, 2012 11:26 pm
Location: South Africa
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: Timing

Post by Xavier »

Thanks Martin

You have helped me out a lot. I will put all of this into practice then post the result.

All the best
Xavier

Post Reply