Page 1 of 1

Delay problem!

Posted: Wed Oct 07, 2009 9:09 am
by electronix
I have a problem when craeting a delay, for example if i would like to have a 36KHz signal output on RB3(16F628A), When compiling to *.HEX i get this issue:

Caution: argument of 'delay_us' calls must have a value of 1 or more
Warning unreferenced functions removed:
FCI_FLOAT_TO_STRING in: C:\Program\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_NUMBER_TO_HEX in: C:\Program\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_STRING_TO_INT in: C:\Program\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_STRING_TO_FLOAT in: C:\Program\Matrix Multimedia\Flowcode V4\FCD\internals.h
Wdt_msDelay in: C:\Program\Matrix Multimedia\Flowcode V4\FCD\internals.h
Wdt_Delay_S in: C:\Program\Matrix Multimedia\Flowcode V4\FCD\internals.h
Wdt_Delay_Ms in: C:\Program\Matrix Multimedia\Flowcode V4\FCD\internals.h
isinf in: C:\Program\Matrix Multimedia\Flowcode V4\FCD\internals.h

Building CASM file
Memory Usage Report
===================
RAM available:224 bytes, used:36 bytes (16.1%), free:188 bytes (83.9%),
Heap size:188 bytes, Heap max single alloc:94 bytes
ROM available:2048 words, used:178 words (8.7%), free:1870 words (91.3%)



success

Return code = 0

FINISHED

It simply doesnΒ΄t matter what value i put in the delay... If i make the delay in ms instead then itΒ΄s working just fine.
The strange thing about this is that if i use an older version of this testprogram(36KHz output on RB3) that i made several months ago, itΒ΄s working great.
I have also installed the latest version of Flowcode but there is still no change...
So..what to do??

*EDIT* The PIC is running at 20MHz.

Re: Delay problem!

Posted: Wed Oct 07, 2009 10:49 am
by Benj
Hello

I cant really see how the us delays are failing unless

a) you have flowcode v4.0 - in which case you will need to download and install v4.1

b) the clock speed in the view -> project options window is set incorrectly.

If you want to attach your flowcode file and the C code generated by the file then I will check this for you.

Re: Delay problem!

Posted: Wed Oct 07, 2009 11:54 am
by electronix
Hi Benj.

I did install V4.1 but still the same problem.
I have attached the C codefile.

/Stefan

Re: Delay problem!

Posted: Wed Oct 07, 2009 12:05 pm
by Benj
Hello Stefan

Ok the C code all looks correct. All of the delay_us commands have values. I think that the message in your compilation window is just a message that is generated when micro second delays are included in your program. What is your hardware doing that makes you think this is not working correctly?

If you are measuring the output signal with an oscilloscope then you might need to remove the 9ms delay near the end of your program to allow you to see a constant oscillating output.

Re: Delay problem!

Posted: Wed Oct 07, 2009 12:10 pm
by electronix
Hi Benj.

The problem is when i run the hardware Nothing happens at all...
But if i instead of using delays, create loops that count the corresponding time then everything works just great.

Re: Delay problem!

Posted: Wed Oct 07, 2009 12:28 pm
by Benj
Hello

Are you sure that the program is not simply running too fast to see the LED flashing.

The output is off for the 9ms delay which would consume the majority (approx 99%) of the time.

The output is only ever on for 5us which would be undetectable by the human eye. Are you measuring the output pin with an oscilloscope?

Re: Delay problem!

Posted: Wed Oct 07, 2009 12:37 pm
by electronix
Hi Benj.

Yes iΒ΄m measuring with oscilloscope and frequencymeter, and when i try with delays....nothing, dead, not even a glitc.
If you calculate the delays there should be an approx 36KHz signal on RB3, if i perform the same thing with numerous loops instead of the delay function everything works fine.

Re: Delay problem!

Posted: Wed Oct 07, 2009 12:48 pm
by Benj
Hm that seems very strange

Have you tried creating a simple program to create a 50% on 50% off cleaner waveform eg.

switch on the output
wait 14us
switch off the output
wait 14us
repeat

This should give you approximatley a 36KHz frequency on the output pin. This will also confirm if if is your program at fault or something to do with the us delays.

It might also be worth changing the output pin to see if that makes any difference on your results.

Re: Delay problem!

Posted: Wed Oct 07, 2009 4:22 pm
by electronix
I have already tried both ports and differnt bits, have also changed the PIC a couple of times,I tried too make the same kind of program for a 16F88 but with the same result unfortunattely.......
Strange as it seems, if i set the dutycycle to 50% as you suggested, its working.

Re: Delay problem!

Posted: Wed Oct 07, 2009 4:32 pm
by electronix
Ok...This is really weird, When i change the values back again to the original ones(17us, 5us)....ItΒ΄s all...just working fine.
This is most remarkable, I have been trying these steps over and over several times the past 14 hours.

Re: Delay problem!

Posted: Thu Oct 08, 2009 8:45 am
by Benj
Hello

I wonder if the bugs from the programs you created in V4.0 were still in effect even though you were since running v4.1.

Recreating the programs or even modifying the values in the delay icons may have been enough to allow them to work correctly with v4.1.

Glad its all working correctly for you now anyway.

Re: Delay problem!

Posted: Thu Oct 08, 2009 9:23 am
by electronix
Hello Ben.

That seems most likely, because now that i have re-made all the delays in all of my programs, everything seems too be working just fine.

Thanks a lot for helping me sort this out Ben.

Best regards
/Stefan