Clock cycles used

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
User avatar
robertpatterson
Posts: 44
Joined: Thu Feb 21, 2013 2:16 am
Location: New England
Been thanked: 6 times
Contact:

Clock cycles used

Post by robertpatterson »

I am having a problem with figuring out how many clock cycles are used on a pic 12f629 internal clock no clock out.
Just to toggle an output pin 38khz is about as fast as it can go I was expecting faster than that.


Loop
gp5 on
gp5 off
goto top of Loop

Something is eating instruction cycles I was expecting a higher frequency.

Also any delay less than 250 microseconds doesn't go much less than that.

Is there something going on in the background I can turn off ?

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: Clock cycles used

Post by medelec35 »

Hi robertpatterson,
Are yo using Flowcode V4 of V5?

I have got pin to toggle at 500KHz with internal osc running at 4MHz
pin toggle1.png
Internal osc 4MHz
(155.91 KiB) Downloaded 5116 times
If you post a flowchart that's configured for your device, and register for to access for you version of flowchart:
For Flowcode V4 go to:
http://www.matrixmultimedia.com/mmforum ... =29&t=8762

For Flowcode V5 go to:
http://www.matrixmultimedia.com/mmforum ... =46&t=9958

Then I will explain what's happening and will alter your Flowchart to toggle a pin at 500KHz.
When your registered I will move this thread to a more suitable location.

I maybe able to change duty cycle to 50 % but that will have an affect on the overall frequency.

Martin

Edit I have altered flowchart to toggle as fast as possible with 50% duty cycle and toggle frequency is reduced to 333KHz.
pin toggle2.png
(159.34 KiB) Downloaded 5116 times
Martin

User avatar
robertpatterson
Posts: 44
Joined: Thu Feb 21, 2013 2:16 am
Location: New England
Been thanked: 6 times
Contact:

Re: Clock cycles used

Post by robertpatterson »

I am using v5 student version.

----------------------------------------
Loop:

Loop 21 times
<LOOP>

----------------------------------------
Output:

4 -> PORTB
----------------------------------------

----------------------------------------
Output:

0 -> PORTB
----------------------------------------

</LOOP>
----------------------------------------

delays anything less than 250 us end up at 250 us

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: Clock cycles used

Post by medelec35 »

robertpatterson wrote:I am using v5 student version.
I have moved post to V5 section.
To enable you post on here can you please register by visiting this post:
http://www.matrixmultimedia.com/mmforum ... =46&t=9958

Once registered ,I will post flowchart to do what you stated i.e:
robertpatterson wrote: Loop:

Loop 21 times
<LOOP>

----------------------------------------
Output:

4 -> PORTB
----------------------------------------

----------------------------------------
Output:

0 -> PORTB
----------------------------------------

</LOOP>
----------------------------------------
Martin
Martin

User avatar
robertpatterson
Posts: 44
Joined: Thu Feb 21, 2013 2:16 am
Location: New England
Been thanked: 6 times
Contact:

Re: Clock cycles used

Post by robertpatterson »

I did the register thing.

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: Clock cycles used

Post by medelec35 »

Welcome to the V5 section.

Attached is a flowchart that should toggle at 333.KHz. I have not got a 12F629 to test with, only a 12F615.


It toggles 29 times then after one second has elapsed will again toggle 29 times etc.
Not sure what action you wanted to take after the toggling 29 times?

Martin
Attachments
toggle test.fcf
(5.5 KiB) Downloaded 322 times
Martin

User avatar
robertpatterson
Posts: 44
Joined: Thu Feb 21, 2013 2:16 am
Location: New England
Been thanked: 6 times
Contact:

Re: Clock cycles used

Post by robertpatterson »

it runs about 38 khz i was expecting about 400 khz plus or minus 100khz

make it a endless loop its still 38 khz here. also the delay cant go below 250 us

something is eating my clocks cycles.

User avatar
robertpatterson
Posts: 44
Joined: Thu Feb 21, 2013 2:16 am
Location: New England
Been thanked: 6 times
Contact:

Re: Clock cycles used

Post by robertpatterson »

----------------------------------------
Loop:

While 1
<LOOP>

----------------------------------------
Output:

1 -> PORTA
----------------------------------------

----------------------------------------
Output:

0 -> PORTA
----------------------------------------

</LOOP>
----------------------------------------
RAM available:64 bytes, used:35 bytes (54.7%), free:29 bytes (45.3%),
something is taking allot of ram for a simple program like this also

User avatar
robertpatterson
Posts: 44
Joined: Thu Feb 21, 2013 2:16 am
Location: New England
Been thanked: 6 times
Contact:

Re: Clock cycles used

Post by robertpatterson »

Flowcode1.fcf
(5.5 KiB) Downloaded 303 times
Flowcode1.fcf
(5.5 KiB) Downloaded 303 times
Caution: argument of 'delay_us' calls must have a value of 1 or more
Caution: Delay inaccurrate: 'delay_us', Delay overhead:0.01ms, Unit delay:0.001ms, Delay resolution:4 units
Warning unreferenced functions removed:
FC_CAL_Port_Out__x in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_IO.c
FC_CAL_Port_Out_DDR__x in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_IO.c
FC_CAL_Port_In__x in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_IO.c
FC_CAL_Port_In_DDR__x in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_IO.c
Wdt_Delay_S in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_Delay.c
Wdt_Delay_Ms in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINT_US in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINT_MS in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINTWDT_MS in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINT_S in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINTWDT_S in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_Delay.c
FCI_GETCHAR in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_GETLENGTH in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_MIDSTRING in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_LEFTSTRING in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_RIGHTSTRING in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_TOSTRING in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_TOLOWER in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_TOUPPER in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_COMPARE in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_FLOAT_TO_STRING in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_NUMBER_TO_HEX in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_STRING_TO_INT in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_STRING_TO_FLOAT in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_STRREV in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_STRMOV in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_SHEAD in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
FCI_SCOPY in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_String.c
isinf in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_Float.c
flt_round in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_Float.c
flt_floor in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_Float.c
flt_ceil in: C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_Float.c

Building CASM file
Memory Usage Report
===================
RAM available:64 bytes, used:36 bytes (56.3%), free:28 bytes (43.7%),
Heap size:28 bytes, Heap max single alloc:27 bytes
ROM available:1024 words, used:97 words (9.5%), free:927 words (90.5%)



success
Return code = 0

FINISHED

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: Clock cycles used

Post by medelec35 »

Hi robertpatterson (Or do u want to be called Rob or Robert?)
RAM is used for temporary variables storage area, calculations, stack usage etc.
So RAM will be used even if Flowchart is very small in size.

As for the smallest time it takes.
You need to remember that the very high lvl language namely dragging flowchart Icons on to a work area makes programming a chip what you want it to do a doddle, compared with programming in assembly but it comes at a cost.
Mainly room taken up on chip and time to execute. Normally with the fast speeds microcontroller run at, and the high storage this is not normally an issue, since when weighed up against the very much reduced time and ease of programming, the latter two usually wins hands down.

Going back to your issue.
if you use this:
pin toggle3.png
(28.52 KiB) Downloaded 5019 times
Then look at the assembly language that's created your see:

Code: Select all

main
; { main ; function begin
	MOVLW 0x07
	BCF STATUS, RP0
	MOVWF gbl_cmcon
	MOVLW 0xC0
	BSF STATUS, RP0
	MOVWF gbl_option_reg
label1
	MOVLW 0xFE
	BSF STATUS, RP0
	ANDWF gbl_trisio, W
	MOVWF gbl_trisio
	MOVLW 0xFE
	BCF STATUS, RP0
	ANDWF gbl_gpio, W
	MOVWF CompTempVar2184
	MOVLW 0x01
	IORWF CompTempVar2184, W
	MOVWF gbl_gpio
	MOVLW 0xFE
	BSF STATUS, RP0
	ANDWF gbl_trisio, W
	MOVWF gbl_trisio
	MOVLW 0xFE
	BCF STATUS, RP0
	ANDWF gbl_gpio, W
	MOVWF gbl_gpio
	GOTO	label1
Or You may find this easier to follow:

Code: Select all

LOOP: MOVLW 0xFE
	BSF STATUS,RP0
	ANDWF GPIO,W
	MOVWF GPIO
	MOVLW 0xFE
	BCF STATUS,RP0
	ANDWF GPIO,W
	MOVWF 0x042
	MOVLW 0x01
	IORWF 0x042,W
	MOVWF GPIO
	MOVLW 0xFE
	BSF STATUS,RP0
	ANDWF GPIO,W
	MOVWF GPIO
	MOVLW 0xFE
	BCF STATUS,RP0
	ANDWF GPIO,W
	MOVWF GPIO
	GOTO LOOP
If you add up all lines to be execute in which some take two clock cycles and some take one clock cycle, then with NO delays inserted its takes 13us for port to go from off to on.
It takes 8us for port go from on to off so thats a total period of 13+8 = 21us.
Frequency = 1/21us = 47.6KHz.
Adding your 10us delay will reduce frequency to 1/(21E-6+10E-6) = 32.3 KHz
That is why adding a small delay wont work either.

I have posted a solution for you in an above post.
Here is the assembly language that's produced to toggle a port:

Code: Select all

LOOP: MOVLW 0x1D
	SUBWF 0x042,W
	BTFSC STATUS,C
	GOTO L7
	BSF GPIO,4
	NOP
	NOP
	BCF GPIO,4
	INCF 0x042,F
	GOTO LOOP
Even with extra nop's added to even out the on/off times, instruction count is greatly reduced.

If you want to add a delay you could have:
pin toggle4.png
(27.34 KiB) Downloaded 5021 times
But still with very small delay times compare with relativity slow clock speed, you will still be seeing slightly longer than expected delay. so toggling will be done with 30us delay and not 10us as expected.

The only solutions are either use ASM as I have showed you. or
Use a microcontroller with a much faster speed.
for example 12F1840 which also has 8 pins will run with an internal oscillator set at 32MHz

Not sure why you have posted two flowcharts with the same name?

Hope this helps to clear confusion.

Martin
Martin

User avatar
robertpatterson
Posts: 44
Joined: Thu Feb 21, 2013 2:16 am
Location: New England
Been thanked: 6 times
Contact:

Re: Clock cycles used

Post by robertpatterson »

Yes Martin that makes it clear. I have to go assembly when I need my pins to toggle faster than 30 KHz . It would be a good thing to add a feature that tells how many clocks are used when the code is being made. To help with timing calculations as the code is being made. It would be a good feature.

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: Clock cycles used

Post by medelec35 »

robertpatterson wrote: It would be a good thing to add a feature that tells how many clocks are used when the code is being made. To help with timing calculations as the code is being made. It would be a good feature.
I have asked in the past for a stopwatch function to be able to time events, but since C or assembly can't be simulated then I was told that it's not possible.
The timing function is being built into Flowcode V6(via hardware monitoring (not simulation wise) or the other alternative is to use a third party simulator that uses hex files and has a stopwatch function built in.

MPLAB is one I can think of that's free to use.
Martin

User avatar
robertpatterson
Posts: 44
Joined: Thu Feb 21, 2013 2:16 am
Location: New England
Been thanked: 6 times
Contact:

Re: Clock cycles used

Post by robertpatterson »

Yes mplab is what I used to use That was a function I used to keep my timing on track.

User avatar
robertpatterson
Posts: 44
Joined: Thu Feb 21, 2013 2:16 am
Location: New England
Been thanked: 6 times
Contact:

Re: Clock cycles used

Post by robertpatterson »

Martin,

I have pic 12f1840 ICS in stock as recommended But I cant program them easy whats the codes are needed for getting them programmed

fast and efficient. I have the pickit 2 and 3 Also I am using flow 5 student and flow 6 pro Thanks in advanced.

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: Clock cycles used

Post by medelec35 »

Martin

Post Reply