Page 1 of 1

Prob. ECIO40P16 and timer larger timer 1 in macros [Solved]

Posted: Tue Mar 07, 2017 5:49 pm
by tiny
I use for my circuit an ECIO40P16, control and display of the periphery via a Nextion display and additionally print buttons for port on / off. Nextion and buttons are controlled by interrupt.

Timer 1 accepts the cyclic tasks (polling the ports, switching date and time, etc.)

If an override is to be controlled via the print button, an IOC port interrupt is triggered and the routine remains in the loop until the button is acknowledged. So that it does not become an endless loop, I activate a timer (Timer 5) and after approximately 2.5 minutes the loop is terminated.

This routine ran smoothly with the PIC18F26K22, with the ECIO40P16 the timer can not be started.

Stop and restart of the timer 1 runs without problems, but not any other timer in the button polling routine.

In the simulation it runs, on chip no reaction.

Here is a short section of my program with the basic functions to show my timer problem.

Can someone give me a tip, how I can activate the timer?

Thanks
Christina
Flowcode1.fcfx
(61.29 KiB) Downloaded 317 times

Re: Problem with ECIO40P16 and timer larger timer 1 in macro

Posted: Wed Mar 08, 2017 5:52 pm
by Benj
Hi Christina,

I'll have a play and see if I can find the issue for you.

Re: Problem with ECIO40P16 and timer larger timer 1 in macro

Posted: Thu Mar 09, 2017 10:55 am
by Benj
Hi Christina,

I've put together a really basic program using timer 5 and this is working well for me on the hardware. I've also attached my C file so you can compile the project to C and compare with my file to see if there is a difference.
FC_Tst.fcfx
(5.76 KiB) Downloaded 304 times
FC_Tst.c
(2.99 KiB) Downloaded 316 times

Re: Problem with ECIO40P16 and timer larger timer 1 in macro

Posted: Thu Mar 09, 2017 3:15 pm
by tiny
Thank you Benj for the work.
With the timer interrupts in the main program I have no problem, which runs without problems.
The example that I have sent shows that a button is interrogated in the Chk_Switch macro (via Interrupt IOC port) and whenever the button is pressed, the status of port 1 is changed and the button quit is confirmed. So far so good.

At the same time, Timer 5 is started, so that after a certain time the loop is interrupted during the probe interrogation, you should forget to press the Quit button.
And there is the problem! Timer 5 (and no other timer) can not be activated. Timer 1 is the only timer that works, but this I need for the main functions of the circuit.

Christina

Re: Problem with ECIO40P16 and timer larger timer 1 in macro

Posted: Thu Mar 16, 2017 11:52 am
by Benj
Hi Christina,

Sorry for the delay.

This is now working really well for me and will hopefully help in your application.

I use an IOC interrupt on the high byte of Port B to trigger timer 5 to be enabled.

When timer 5 interrupts I increment a counter and then disable timer 5 again.

The counter is then show on the low byte of Port B.

I use a bit of C code when enabling the timer to reset the count register and also to clear the interrupt flag just in case it has been set. This seems to help achieve reliable operation.

Re: Problem with ECIO40P16 and timer larger timer 1 in macro

Posted: Thu Mar 16, 2017 12:34 pm
by Benj
Here is a slightly modified FCD which includes the timer flag and counter reset as part of the enable code so you don't have to manually add it using a C icon.

Simply copy this to your "Flowcode 7/FCD/PIC16" folder before starting Flowcode and hopefully this should allow your program to function as expected.
ECIO40P16.fcdx
(44 KiB) Downloaded 298 times
Let me know how you get on.

Re: Problem with ECIO40P16 and timer larger timer 1 in macro

Posted: Thu Mar 16, 2017 2:02 pm
by jgu1
Hi Ben!

Your FCDX file, is this a bug correction or is custom for Christina.

Thanks in advance

Jorgen

Re: Problem with ECIO40P16 and timer larger timer 1 in macro

Posted: Thu Mar 16, 2017 2:14 pm
by Benj
Hi Jorgen,

The FCD file now has the following changes.

Timer enable resets the timer register to 0 and clears the interrupt flag in case there was an interrupt pending. Avoids the timer interrupt instantly firing which is what I was seeing here.

Timer disable switches off the timer peripheral as well as the interrupt. This should stop the timer interrupt flag being set and should also save a little bit of power.

I've rolled out this change to the family of devices (xxxEPxxxxGUxxx and xxxEPxxxxMUxxx), the dsPIC MIAC, the Formula AllCode and the EB091 and the change will likely stay going forward. I am yet undecided on whether to roll it out to all 16-bit PIC devices or not.

Re: Problem with ECIO40P16 and timer larger timer 1 in macro

Posted: Thu Mar 16, 2017 9:49 pm
by petesmart
Hi Ben,

Any chance you could post the dspic MIAC fed file when it's cooked? Working with MIAC now using interrupts for frequency counter.... This would be helpful.

Best

Pete

Re: Problem with ECIO40P16 and timer larger timer 1 in macro

Posted: Fri Mar 17, 2017 9:06 am
by LeighM
Hi Pete,
Ben's updates attached.
Regards,
Leigh

Re: Problem with ECIO40P16 and timer larger timer 1 in macro

Posted: Fri Mar 17, 2017 9:09 am
by petesmart
Brilliant...thank you...

Re: Problem with ECIO40P16 and timer larger timer 1 in macro

Posted: Fri Mar 17, 2017 6:15 pm
by tiny
Thank you Ben for the many work, but the timer 5 works now!
But my program still needs to be considered.
In the function Chk_Switch, I activate the timer 5 and then I go to the keystroke. If the routine immediately enters the keystroke, the timer is not activated. If I disable the keystroke then it works. Here I have to think about how I can continue to work with the time delay or to activate the keystroke only when the timer 5 is activated.
Until now, I'm still hanging around on this problem, otherwise everything works!

Thanks again!
Christina