Timer2 interrupt no longer working in 18F43K22

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

Post Reply
crispin12
Posts: 51
Joined: Fri Apr 07, 2017 5:51 pm
Contact:

Timer2 interrupt no longer working in 18F43K22

Post by crispin12 »

Can someone please look at this as I need to get an answer. I suspect the Timer2 chip definition is wrong for this chip and probably also the other 44K22 45K22 46K22 devices in this range.
I'm calling a Timer2 interrupt component and the ISR macro simply adds a 1 to a variable on each interrupt overflow. It was working perfectly in sim and HEX hardware on the previous v7.1.1. Just installed the latest version and the interrupt no longer is being triggered in the Flowcode sim i.e the count (var) in the ISR macro is no longer incrementing up from 0. Because the ISR count no longer increments my code is broken!

For the record my Timer2 is set with 1/16 prescale, 1/1 postscale and a rollover value of 24 with a clock osc of 16MHz. IOW the timer is set in the timer hardware at 96uS.
Many thanks in advance.

If some informed user (Medelec?) could check the chip file and tell me how to edit it (assuming this is the problem) I will make the edit myself rather than waiting for the support staff to issue a new file.

Many thanks in advance

crispin12
Posts: 51
Joined: Fri Apr 07, 2017 5:51 pm
Contact:

Re: Timer2 interrupt no longer working in 18F43K22

Post by crispin12 »

Well I just created a simple test circuit using one of the updated chips (1845K40) Benj uploaded earlier and it looks like the way timer interrupts are simulated have changed since the last version. If the interrupt time is set at around 50Hz (20ms) and the simulation speed is set fairly slow you can see the overflow operating and a the ISR macro will increment a variable counter. However, if the timer delay is decreased (the interrupt rate increased) then the simulation stops simulating the overflow and variable counter in the watch window simply stays on 0. This led me to believe the interrupt component wasn't working. It appears the interrupt component is working but the simulation isn't ...unless the timer is around 20mS. Have to confess to being totally baffled as on v7.1.1.0 the simulation was totally consistent with the variable in the watch window incrementing all the time the simulation is running.
Test file uploaded so if anyone wants to play around with the interrupt properties and change the overflow time from mS to uS range and let me know if they are seeing the variable in the macro incrementing I would be grateful. Beginning to wonder if there's something wrong with my installation....
Attachments
test.fcfx
(7.88 KiB) Downloaded 140 times

crispin12
Posts: 51
Joined: Fri Apr 07, 2017 5:51 pm
Contact:

Re: Timer2 interrupt no longer working in 18F43K22

Post by crispin12 »

Update:
Uninstalled and gone back to v7.1.1.0
Interrupt simulation once again working across the board using any sim speed and any timer interrupt setting. For me the latest version is kaput and why suddenly is the product installer now nearly 1.2GB. It takes three times as long to install. What an absolute PITA!!!

User avatar
Benj
Matrix Staff
Posts: 15147
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Timer2 interrupt no longer working in 18F43K22

Post by Benj »

Hello Crispin,

Sorry for the delay.

In 7.2 we changed the way that timer interrupts work to try and make them more reliable to real life in terms of interrupt frequency. Things like the stopwatch demo should now actually simulate and show something like the right time. However this is only when the simulation speed is set to Normal.

When running with a slower simulation speed if the interrupts remained running at the chosen frequency then when debugging/ stepping through the program etc all you would see is the interrupt routine. e.g. when leaving the interrupt the time period would have elapsed and you would go straight back into the interrupt.

To circumvent this we have a divisor that works out the simulation execution speed and then divides down by the speed you have the simulation set to. If this speed is very slow then the interrupt will take a long time to trigger. For example if your computer can process 10,000 icons a second and you have an interrupt of 50Hz when running at normal speed then dropping down to 1Hz icon speed will mean the interrupt rate drops to 0.0005Hz to allow you to correctly see the full speed program flow in slow speed.

Hopefully this explains the problems you experienced with version 7.2.

The larger download size is because we have added a new chip family and compiler (STM32 ARM). We are moving to a more modular installer where you can pick and choose what features you want to download and install to try and remedy this problem in the future and keep patch sizes small etc.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 9188
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: Timer2 interrupt no longer working in 18F43K22

Post by medelec35 »

Hi Ben,
I have to agree with crispin12.
I downloaded his flowchart and at first the interrupt was working (simulation only) just fine.
After starting and stopping the simulation a few times the interrupt refused to work,
i.e interrupt ISR macro is no longer being accessed so variable no longer incremented on any of the simulation speed settings.
Used the reload button and interrupt started working again.

Martin
Martin

User avatar
Benj
Matrix Staff
Posts: 15147
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Timer2 interrupt no longer working in 18F43K22

Post by Benj »

Thanks Martin,

Aha so there is a bug there lurking!

Right I'll investigate a bit further and see if we can do something about it.

User avatar
Benj
Matrix Staff
Posts: 15147
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Timer2 interrupt no longer working in 18F43K22

Post by Benj »

Right after some testing it's working reliably ok for me with the sim speed set to normal. I output the count value to some LEDs to see it incrementing.

However flicking the sim speed from normal to 50Hz and back to normal does seem to cause a problem. You have to stop and restart the sim for the counting to correctly resume.
Test.fcfx
(9.39 KiB) Downloaded 147 times

crispin12
Posts: 51
Joined: Fri Apr 07, 2017 5:51 pm
Contact:

Re: Timer2 interrupt no longer working in 18F43K22

Post by crispin12 »

Hi Benj

I tested this several times and can only say that it was only on one slow sim setting could I get the interrupt and count to simulate. It simply wouldn't start and the flowchart just kept bouncing back and forth across the While 1 loop. At normal full speed you don't see the flowcode icons in the chart being scanned in any case but then the counter wasn't incrementing either. I'm going to stick my neck out here and suggest that it it might be a GUI, Windows resources issue and different computers will see differences in the way it works or doesn't. You really need several people to test this on various computers and report back. I appreciate what you tried to do in changing the way the interrupt sim matches real life hardware but not having an ISR macro counter change means that you can no longer rely 100% on whether you've got the firmware sequence correct. For me the only thing that is reliable is the way it works in v7.1.1.0.
I'm sorry I can't test any "fixes" because I needed to get the circuit debuged so had to uninstall the latest version. I only hope more users jump in and test the 'issue' thoroughly and give their feedback so this gets thoroughly resolved because interrupts are basic staple of uC development.
Thanks for looking into this!

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 9188
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: Timer2 interrupt no longer working in 18F43K22

Post by medelec35 »

Benj wrote:However flicking the sim speed from normal to 50Hz and back to normal does seem to cause a problem.
Sorry Ben, I must have changed the sim speed and not noticed it had cause simulation to fail.
I agree with you.

Martin
Martin

crispin12
Posts: 51
Joined: Fri Apr 07, 2017 5:51 pm
Contact:

Re: Timer2 interrupt no longer working in 18F43K22

Post by crispin12 »

STILL seeing a problem with the way the new interrupts are working. Currently working with 18F45K40 which is cheaper than 18F43K22

The flashing LED port driven interrupt test example you provided does work as described and yet I have simplified my specific design and enclosed it here for your evaluation. Perhaps I have misunderstood the way the interrupt system is supposed to work within Flowcode but when you sart the simulation (at normal speed), the ISR macro counter does not operate at all (either in real time or when the simulation is paused UNTIL you make a change on either the DIP toggle switch or the fader control of analog channel 0. In other words as soon as you change an item on the 2D panel then the interrupt simulation springs to life. Surely the interrupt should be working regardless of what happens on the 2D panel?

I still say the new interrupt is a step backwards. Not only does it not work under simulation when simulating at less than 'normal' speed; it does not begin to operate until you make a change to a component on the panel. This is frankly not user friendly and doesn't even come close to being a diagnostic tool. The greatest thing about Flowcode was being able to slowly watch the simulation step through the icons slowly so you could see at what point the code was broken. Perfect diagnostics! But now with the variable counter under the control of the interrupt not even working until

a) the simulation has been set to a speed where you can't watch the program cycle through the icons
b) until you make a change to an item on the panel

I believe Flowcode has taken a major step backwards.

And things are actually worse than this! The ISR macro interrupt counter in the watch window is totally wrong. In other words even when you have actually got the blessed thing to increment, when you press pause in the simulation the variable value shown is incorrect.

Analyse my file carefully and you will determine that the Timer 2 interrupt occurs every 1mS. Every other part of the code like switching port outputs, taking an analog ADC conversion should be happening in a matter of uS. Each chip instruction is happening at a 16/4 MHz frequency i.e. 250nS. The macro variable should be counting from 0 to 1 to 2 to 3 and then be reset to 0 in a continuous while 1 loop and each incremental step should be 1mS. There are a possible 4000 internal instructions that can take place within each 1mS interrupt window. The variable in the ISR macro should never show any number other than 0,1,2, 3 and yet it shows everything from 0 to 255. So the interrupt is NOT working correctly and the simulation is totally messed up. This same file IS working perfectly under v7.1.1.0.

Please run this file and check out everything I am describing because while your simple LED interrupt driver example does run ok my file does not. This has to be a bug or a computer resource issue because the file simulates perfectly under v7.1.1.0. When you changed the interrupts system for v7.2.1 something went badly wrong.
Attachments
Monitor System.fcfx
(28.69 KiB) Downloaded 137 times

User avatar
petesmart
Valued Contributor
Valued Contributor
Posts: 395
Joined: Thu May 06, 2010 11:42 am
Location: Sydney, Australia
Contact:

Re: Timer2 interrupt no longer working in 18F43K22

Post by petesmart »

Hi MTSL team,

I too have been having difficulties with the simulation of interrupts. Doing some simple checks, it does not seem to matter which chip – looks like a generic problem as I have tested on miac, dsPic miac, ECIO40p etc, all with the same result.

It appears that when you click on a component located on the 3D panel the interrupted starts to work, however at a very slow rate.

Attached is a simple test program that I used to prove out the case.

All the best,

Pete
Attachments
ecio40 - interrupt test.fcfx
(10.42 KiB) Downloaded 130 times
sorry about that Chief!

Post Reply