Page 1 of 1

Changing TRM setup "on the run"

Posted: Thu Mar 18, 2010 4:33 pm
by ksor
I do beleave something IS wrong when changing the prescaling in a TMR-setup (at least with TMR0) while program is running in HW.

In two branches of my program I use different prescaler in setup of TMR0 - COUNTING mode have one setting of prescaler for TMR0 and RPM mode has another.

When changing from one mode to the other I DISABLE the TMR, change the prescaler and resume.

In HW the changing DO NOT take place - it seems like the TMR stops or can't be started again in the "new" mode.

I can choose between the two branches with a CHANGE-OVER switch.

If I leave the switch in the position where the timer now do NOT run and cut off power and connects again - then it works fine again - until I change the switch - then I have to cut/connect power again for it to work.

I beleave a "software reset" would do the job - can this be done in Flowcode ?

Re: Changing TRM setup "on the run"

Posted: Thu Mar 18, 2010 9:22 pm
by Benj
Its working fine for me, though I do have other interrupts going on. Try manually clearing the interrupt flag this may help.

Re: Changing TRM setup "on the run"

Posted: Thu Mar 18, 2010 10:14 pm
by ksor
Please send your program to me so I can see.

You didn't comment on if it is possible to make a "software reset".

Re: Changing TRM setup "on the run"

Posted: Fri Mar 19, 2010 10:02 am
by Benj
Hello Ksor,

I have attached the program.

A software reset can be done by using the following C code inside a C code icon in your program.

reset();

Re: Changing TRM setup "on the run"

Posted: Fri Mar 19, 2010 12:19 pm
by ksor
... and you even do no DISABLE before changing TMR-setup.

I made some changes to the structure of my main flowchart to get the reset(); to fit - and it works fine.

I then tried to delete the reset ... and now it works fine too - it's just spooky I think - but never mind, it works !

Re: Changing TRM setup "on the run"

Posted: Fri Mar 19, 2010 12:38 pm
by Benj
The program works so that one of the switch case branches disables the timer interrupt. This is always called before switching the interrupt prescaler and re-enabling.

Re: Changing TRM setup "on the run"

Posted: Fri Mar 19, 2010 12:47 pm
by ksor
Ok - I didn't notice that - but I was very keen remembering to DISABLE, change prescaler and enable again - but it still wouldn't do it !

But now when I changed a little in the structure of the main flowchar ... then it works - even WITHOUT the reset();

So that's it ... no more struckle with that program !

Have a nice week-end ! :lol: