are microsecond (us) delays working?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
andygraves
Posts: 18
Joined: Wed Jan 06, 2010 2:59 pm

are microsecond (us) delays working?

Post by andygraves »

Hi Guys,
I have been trying to use microsecond (us) delays, I understand the accuracy warnings and implications but i see the following
"Caution: argument of 'delay_us' calls must have a value of 1 or more" any time us delay is used. Is the delay value getting passed to the delay correctly?
This might explain why my prototype is not working... :roll:
The error is produced even with a 1 icon fcode of just a 100us delay.
Thanks Andy

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: are microsecond (us) delays working?

Post by Benj »

Hello Andy,

Yes this warning message is a little strange but I can assure you that the C code is going in correctly.

This is what should be generated in the C code.

delay_us(100);

andygraves
Posts: 18
Joined: Wed Jan 06, 2010 2:59 pm

Re: are microsecond (us) delays working?

Post by andygraves »

Hi Ben,
Thanks for the reply,

So just to confirm my logic...

A:
porta>1
delay 4 us
porta>0
delay 4 us
> A:

would give a datarate of 250k on RA0 of the PIC

(16f872 on the dev board 3 runninhg with the XTAL)

andygraves
Posts: 18
Joined: Wed Jan 06, 2010 2:59 pm

Re: are microsecond (us) delays working?

Post by andygraves »

Hi Guys, please confirm if my previous post is correct?
Thanks Andy

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: are microsecond (us) delays working?

Post by Benj »

Hello Andy

The code you are showing would generate a signal of 125KHz.

I calculated this by dividing 1 by the overall time period.

1 / 0.000008 = 125000

andygraves
Posts: 18
Joined: Wed Jan 06, 2010 2:59 pm

Re: are microsecond (us) delays working?

Post by andygraves »

Hi Ben,
Thanks for the info..
However upon testing the frequency generated is 80.59 Khz not ~125 Khz?
Please explain?
thanks
Andy

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: are microsecond (us) delays working?

Post by Benj »

Hello Andy,

The value you are getting suggests an overall delay of 12.4us every cycle.

Are you using the 19.6608MHz clock onboard the dev board and have you specified this in Flowcode.

The logic to control the loop and the output commands will take a little amount of time so you will not get an exact frequency however I wouldn't have thought it would be that much lower. If you need to output an exact frequency then maybe using a timer interrupt would be a better option.

andygraves
Posts: 18
Joined: Wed Jan 06, 2010 2:59 pm

Re: are microsecond (us) delays working?

Post by andygraves »

Hi Ben,
Hmm, as per my original post "are microsecond (us) delays working?"

I think unfortunately, the answer is "no not always!"

Crystal and Flowcode set to 19.66meg

1us on 1us off = 158.6 KHz should be 500k
2us on 2us off = 119.9 KHz should be 250k
4us on 4us off = 80.6 KHz should be 125k

to confirm that all is correct with the hardware..
100us on 100us off = 4.8k should be 5k = OK

Please urgently let me know when this can be fixed in Flowcode?
Thanks
Andy

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: are microsecond (us) delays working?

Post by Benj »

Hello Andy

As I mentioned before there is an overhead for switching on and off leds and for jumping back to the start of the loop which will mean that your timings are not exact.

One way around this is to use a timer interrupt. This way you will not need any delay icons and your output frequency will be much easier to get right.

Try this attached program, it should give you a very solid output of 4800hz.
Attachments
Freq_Gen.fcf
(5.5 KiB) Downloaded 262 times

andygraves
Posts: 18
Joined: Wed Jan 06, 2010 2:59 pm

Re: are microsecond (us) delays working?

Post by andygraves »

Hi Ben and Steve,
Thanks for the reply and info...

Whilst I understand there is an overhead, these seem far too excessive?
e.g. I believe the chip is capable of almost 5 MIPs - therefore not being able to perform a simple on/off Flowcode loop at say 125 KHz seems to indicate something is very inefficient? What other Flowcode instructions are being added to the final machine code and why?

My problem is that I am trying to generate an almost fully packed RS485 signal at 250k baud,
If I use the interrupts to trigger the start of each word, how can I successfully space the bits without using (accurate) delays?
I don’t think I can use the UART because generation of special breaks and marks are required. Also I am now not confident that Flowcode will get the data to the UART quick enough (9 databit mode due to needing and extra stop bit)?

Please advise on how to solve this situation with Flowcode?

Thanks
Andy

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: are microsecond (us) delays working?

Post by Benj »

Hello Andy,

I have done some testing with an 16F877A running at 19.6608MHz using the attached test program and have found the following.

uS Delay : 1
Delay Period : 4.5us

uS Delay : 2
Delay Period : 6us

uS Delay : 30
Delay Period : 35us

I then switched to the Hi Tech C compiler and repeated the testing.

uS Delay : 1
Delay Period : 7us

uS Delay : 2
Delay Period : 10.5us

uS Delay : 30
Delay Period : 105us ???

I then switched back to BoostC and used an ECIO running at 48MHz (12MIPS)

uS Delay : 1
Delay Period : 2.6us

uS Delay : 2
Delay Period : 3.75us

uS Delay : 30
Delay Period : 32us

So my conclusion is to either use a faster device like the ECIO or another 48MHz PIC. Or alternativly you could use an AVR as these run around 4 x faster then a PIC running at the same clock speed. A 48MHz PIC can process 12 MIPS, a 20MHz AVR can process 20 MIPS.
Attachments
uS_Tests.fcf
(7 KiB) Downloaded 254 times

andygraves
Posts: 18
Joined: Wed Jan 06, 2010 2:59 pm

Re: are microsecond (us) delays working?

Post by andygraves »

Hi Ben,

Thanks for your update on this.

Going to 12 MIPs for 250kbaud seem to be somewhat extreme!

I ended up doing in in ASM with FlowCode doing the front end, works well...

Please take a look at the excessive overhead somtime...

One thing, cant seem to use CALL / RETURN in ASM, cant find in in the boostc manual or forum...?

Do you know if its possible and if so whats the syntax?

Thanks

Andy

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: are microsecond (us) delays working?

Post by Benj »

Hello Andy

Best way is to put the assembler code inside a C function in the supplementary code which is available inside the project options menu,

Inside the defines window

void assembler(void);

Inside the code window

void assembler(void)
{
ASM code
}

Then call from your program using a C code icon

assembler();

Post Reply