RC5 and Stack problem

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Clive44
Posts: 52
Joined: Tue Oct 18, 2011 12:35 pm
Has thanked: 3 times
Contact:

RC5 and Stack problem

Post by Clive44 »

Hi

I have quite a large program which complies on Flowcode V5 and runs fine on the target device.
However if I add the RC5_RX_Enable() macro I get compile errors as follows -

Building CASM file
Serious Warning: Call stack usage exceeds:8!

Call Stack Usage Report
=======================
main and Task(s): hw used:6, exceeded by:0
interrupt: hw used:4, exceeded by:0

Serious Warning: Possible sw stack corruption, function 'FCD_RC50_RC5_Initialise_States' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Memory Usage Report
===================
RAM available:368 bytes, used:169 bytes (46.0%), free:199 bytes (54.0%),
Heap size:199 bytes, Heap max single alloc:95 bytes
ROM available:8192 words, used:6246 words (76.3%), free:1946 words (23.7%)

success
Return code = 0

And program malfunctions on the target device. Is there a fix/work around or am I doing something wrong?
Thanks for any help.

Clive

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: RC5 and Stack problem

Post by Benj »

Hi Clive,

On a standard 8-bit PIC there are only 8 levels of stack. That is 8 macro jumps away from the Main function. This unfortunately includes macro calls made by the underlying component C code.

If you go to Build -> Compiler options and then click on the linker tab then you can add the following text to the end of the parameters text field to give you an extended software based stack.

-swcs 6 2

Remember to remove the extra parameter from the linker options when you are finished compiling using the software stack.

The serious warning can be ignored as the component ensures that the stack corruption with the init states function does not happen.

Clive44
Posts: 52
Joined: Tue Oct 18, 2011 12:35 pm
Has thanked: 3 times
Contact:

Re: RC5 and Stack problem

Post by Clive44 »

Hi Ben

Thanks for your reply and sorry I've taken so long to reply - been away in the sun for a few days!!
I've done what you said but I've still got problems.
I have a large working program. It works fine if I just use the push buttons on an EB007, but I need to have an IR remote control as well.
If I just add the RC5 RX Enable macro (nothing else) it hangs the program in a seeming endless loop. The problem seems to be associated with the Delay 100mS macro.
Program structure in my 'check buttons' macro is -
1. RC5 Enable Macro
2. Send 1 to Port D5 to light LED
3. Delay 100ms
4. Send 0 to Port D5 to turn off LED (ie flash LED for 100mS)
5. RC5 disable Macro

In practice the LED comes on and stays on - nothing else happens.

Any help appreciated - I'm stumped!

Thanks

Clive

Clive44
Posts: 52
Joined: Tue Oct 18, 2011 12:35 pm
Has thanked: 3 times
Contact:

Re: RC5 and Stack problem

Post by Clive44 »

Problem seems to be related to TMR0 which I was using as a seconds counter interrupt. Using TMR2 solves some of the problems and I'm getting closer to a working solution, although RC5 reception seems a little intermittent.
One point - the RC5 macros only seem to run with an oscillator of 19.660800MHz. Is this correct? I was hoping to use an internal osc at 4MHz.
I'm using Flowcode V5.2 with a PIC16F887.

Any pointers much appreciated

Clive

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: RC5 and Stack problem

Post by medelec35 »

Hi Clive,

This type of issue is normally caused by a delay or component containing delays, or maths functions like Mod being placed within interrupts, when the same type of delay or function is elsewhere in a macro e.g main.

for example if a component containing a ms delay (LCD for example) is within timer0 interrupt , then ms delay is placed within main (or any other macros), then there will be corruption issues.
Best thing is to keep interrupts as short as possible.
If a component containing a delay is placed withing an interrupt, and there is no way round it then either change all delays in the rest of the flowchart with us delays (to the same ms equivalent) or just edit the component custom code to use us delay (equivalent to ms).

If you need a bit help, and your flowchart is not commercially sensitive, then if you post flowchart, I can take a look and see if a solution can be found.

Martin
Martin

Clive44
Posts: 52
Joined: Tue Oct 18, 2011 12:35 pm
Has thanked: 3 times
Contact:

Re: RC5 and Stack problem

Post by Clive44 »

Thanks Martin. I'll have a look at the points you've raised. The program is pretty huge now with about 20 macros so I don't want to burden you with looking through that lot!!

Do the RC5 macros need a 19.6608 MHz clock or should they run at lower frequencies?

Best regards

Clive

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: RC5 and Stack problem

Post by Benj »

Hi Clive,

The RC5 component should be ok to run at pretty much any speed. As long as the clock frequency in the Flowcode project options is correct for the hardware then the RC5 should work correctly.

Clive44
Posts: 52
Joined: Tue Oct 18, 2011 12:35 pm
Has thanked: 3 times
Contact:

Re: RC5 and Stack problem

Post by Clive44 »

Thanks again for your help Ben

I can get it to consistently work with an HS oscillator and a 19.6608 crystal, but no joy at all on an internal 4MHz osc. Must be finger troubles - I'll check further!!!

Clive

Clive44
Posts: 52
Joined: Tue Oct 18, 2011 12:35 pm
Has thanked: 3 times
Contact:

Re: RC5 and Stack problem

Post by Clive44 »

Hi Ben
I've taken your original RC5 test file and modded it a little.
Port B is the EB005 LCD board
and Port A.3 is the RC5 RX input from an EB060 board.
PIC is 16F887 in an EB006 although I'm using a PICKit 2 to program it.
If configured to 19.6008MHz and using the EB006 crystal it works fine
Also I found a 4.096MHz crystal in my junk box - again the program works OK.
If configured to Internal Osc at 4MHz - no joy. I've put an oscilloscope on the CLKOUT pin (pin 14 on a DIP40 PIC16F887) and it measures 1MHz as expected.
I can add an external crystal to my design but I'm curious why it doesn't work at 4MHz?
Is this an OSCTUNE problem?

Regards

Clive
Attachments
RC5-cesf-int4MHz.fcf
(10.5 KiB) Downloaded 431 times

Clive44
Posts: 52
Joined: Tue Oct 18, 2011 12:35 pm
Has thanked: 3 times
Contact:

Re: RC5 and Stack problem

Post by Clive44 »

A bit more detective work -
Putting a frequency counter on pin 14. As expected I read with a few Hz of 4.096MHz with the crystal oscillator.
Switching to the internal RC oscillator I read 999.464KHz (Fosc divide by 4). If I then put the oscillator frequency into Flowcode as 4 times this ie 3997.856MHz and recompile. Program still does not work.
So it looks like the RC5 subroutines definitely do not like internal oscillators??? Seems strange. Wonder what I'm missing here?

Thanks for all your help

Clive

Clive44
Posts: 52
Joined: Tue Oct 18, 2011 12:35 pm
Has thanked: 3 times
Contact:

Re: RC5 and Stack problem

Post by Clive44 »

Here's a puzzle for you!
If I set the osc as internal and the frequency as 999.464KHz into Flowcode (which is actually a quarter of what it should be) then the RC5 works, but the LCD doesn't seem to like it. Bit of a clash.

Regards

Clive

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: RC5 and Stack problem

Post by bercioiu »

Hi Clive!

I know it's been a long time since the last post but I have the same issue like yours, Did you succeed to manage your RC5 with 4 MHz internal oscillator? If yes, can you tell me how? I tried a lot of chips but with no luck... Only way to go is external 19,660800 MHz...
Thank you!

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: RC5 and Stack problem

Post by Benj »

Hmm, this is interesting. please can you confirm which version of Flowcode your using, looks like your all on v5?

The RC5 rate should be controllable via a define so rather then changing the clock speed you can just do a /4 or *4 to the definitions.

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: RC5 and Stack problem

Post by bercioiu »

Yes, I confirm that I have V5 professional with all updates (V5.5). My goal is to use 16F690 in my application. I manage with the compilation thanks to Martin ( I have posted in his topic with 8 Chanel receiver) but still have that issue with the internal clock. With 16f690 does not work at all, nor external nor internal oscillator ... But for 16F690 I will wait the response in that topic.
Thank you again for your support!

Edit next day:

Today I try all kind of configuration with no success... my RC5 work only with external oscillator (inclusive RC)

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: RC5 and Stack problem

Post by bercioiu »

I managed to start RC5 in 16F628 with internal oscillator but at a frequency no more than 2MHz with all off/disable (WDT, PWRT, INT RESET etc config word is 0x3F18) If I raise the frequency, all stack...
For the moment, I will make my program with that chip at that frequency until someone help me (in the Martin`s thread) with 16F690...
I wish you all the best!
Puiu Bercioiu

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: RC5 and Stack problem

Post by medelec35 »

I have asked Ben if he would be able to take a look at the issue with 16F690 and RC5, since I do not know the reason for it not working.
If any one can sort it... its Ben :)
Martin

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: RC5 and Stack problem

Post by bercioiu »

Thank you Martin, I read that in your thread. I am waiting patiently for Ben to fix that issue with 690. Meanwhile, I struggle to make my program with another chip that does not want to go with RC5 and 4MHz internal oscillator... :oops: any idea ?

Post Reply