Page 1 of 2

Help with Interupt please

Posted: Sun Nov 17, 2013 8:42 pm
by acestu
Hi,

Could somebody help me with an interupt on this chart please, I just want to add a variable time Boost control to the heating timer, it is not that simple because it can't just switch off after the timed period has elapsed because one or more of the timers may be active......
Heating-TimeclockV3.fcfx
(20.74 KiB) Downloaded 410 times
Cheers
Acestu

Re: Help with Interupt please

Posted: Sun Nov 17, 2013 9:46 pm
by medelec35
Hi Stu,
If you want to add an interrupt then its best to changed LCD from port B to port C or D so interrupts on port B can be used.
Since port C had other functions like RS232, I personally would change LCD to port D and use either RB0 or RB4 to RB7 as interrupts for any switches.
I can help you by modifying your flowchart and posting it when i can a chance.

Martin

Re: Help with Interupt please

Posted: Sun Nov 17, 2013 9:53 pm
by acestu
Hi Martin,

I will have a go myself as well at changing the charts LCD connections, it's funny because I was trying to copy the interrupt timer that you did for me on the power alarm project, however I am still not quite sure how the interrupts work.... Is this the best way to go to count up to an hour ?


cheers
Acestu

Re: Help with Interupt please

Posted: Sun Nov 17, 2013 10:08 pm
by acestu
Hi Martin,

I have now changed the LCD connections, so I just need help with the timer really....
Heating-TimeclockV4.fcfx
(22.91 KiB) Downloaded 408 times
Thanks
Acestu

Re: Help with Interupt please

Posted: Sun Nov 17, 2013 10:14 pm
by medelec35
For changing the interrupt properties:
Make sure that you have a interrupt source of internal clock and not Transition of T0CKI Pin
What you will need to do is find the nearest (lowest) value to a whole number (e.g if 19.66 crystal then choose 1:256) that gives an interrupt frequency of 75Hz.
This means interrupt macro is accessed 75 times every second, no matter what is happening within the rest of the program (so long as other interrupts are not being triggered).
So if you add within timer interrupt:
Count = Count + 1: If Count = 75 then count =0 : Seconds = Seconds +1
If Seconds = 60 then Seconds = 0 : Minutes = Minutes +1
Etc .

Just had a look at your flowchart.
What I would do is change switch from A1 to B0.
Then have INT0 Pin interrupt to call a macro that has Seconds = 0 and minutes =60

Then no matter what part of flowchart is being accessed, your hour boost will start as soon as button is pressed.

Re: Help with Interupt please

Posted: Sun Nov 17, 2013 10:34 pm
by acestu
Hi Martin,

Does this interrupt setting mean that it will be interrupted by any pin on the B port, because there is no pin setting ?


Also I am finding it hard to understand:

Count = Count + 1: If Count = 75 then count =0 : Seconds = Seconds +1
If Seconds = 60 then Seconds = 0 : Minutes = Minutes +1


I try to break it down

count = count +1 - means that it goes up in increments of 1
If Count = 75 then count =0 - means that the count is reset after 75 I would imagine that this is something to do with the 75 times per second


cheers
Acestu

Re: Help with Interupt please

Posted: Sun Nov 17, 2013 10:42 pm
by acestu
Hi Martin,

I have tried setting up my interrupt as you say but I don't get 75 HZ I get 75000 HZ


cheers
Acestu

Heating-TimeclockV5.fcfx
(23.92 KiB) Downloaded 407 times

Re: Help with Interupt please

Posted: Sun Nov 17, 2013 11:05 pm
by medelec35
acestu wrote:but I don't get 75 HZ I get 75000 HZ
I just looked at your flowchart and it is 75.00Hz:
75Hz.png
(22.46 KiB) Downloaded 7706 times
So if you add the seconds and minutes.
Instead of Seconds = Seconds +1,
It my be better to have - for both seconds and minutes instead of +

Re: Help with Interupt please

Posted: Sun Nov 17, 2013 11:14 pm
by acestu
Hi,

course it is :oops:

I have edited post and left version5, did you see my question:

Does any pin on port B call the interupt ?

thanks
Acestu

Re: Help with Interupt please

Posted: Sun Nov 17, 2013 11:20 pm
by medelec35
acestu wrote:Does any pin on port B call the interupt ?
No
Only B0 will call INT0 (you can select rising or falling edge).
B4 to B7 will call IOC PORT B
But word of warning:
Since there is not a masking register, then if using IOC there must be a routine to detect which pin has activated interrupt if more than one switch is used.
Since IOC is interrupt on change, the interrupt will be triggered on rising AND falling edges of pins B4 to B7

Re: Help with Interupt please

Posted: Sun Nov 17, 2013 11:36 pm
by acestu
Hi Martin,

If I am right then this chart should call the Boost Macro and light the Heating On LED when the Boost switch is pressed, but it doesn't.....

Not sure why not

cheers
Acestu
Heating-TimeclockV6.fcfx
(23.9 KiB) Downloaded 435 times

Re: Help with Interupt please

Posted: Mon Nov 18, 2013 8:08 am
by Creative25
Hi Acestu
I find some things in your code that I do not understand.
First the macro tick is empty are you not using it anymore?
Secondly I do not understand what you want to do with the boost macro.
Are you checking if all the Timer Status variables are 0 ?
If that is what you want to do I guess you should rather use the AND function.
Or you can create a bit variable and add all the Timer status values. If the result is O then all the TimerStatus variables would be 0 too.

Best regards:
Uli

Re: Help with Interupt please

Posted: Mon Nov 18, 2013 8:27 am
by medelec35
Hi Stu,
You do not make any calls to any type of interrupt macros.
These are fully automatically called for you

The Timer0Tick macro is automatically accessed every

Code: Select all

1/75 = 13.33ms 
Since interrupt is 75.000Hz, in 1 second this macro has been automatically accessed a total of 75 times
So if you place Count = Count +1 at the start of the interrupt macro then since in exactly one second, count = 75 you then need to subtract a Second.
If counting down you could use:

Code: Select all

If Boost = 1: Count  = Count +1: If count = 75: if yes: Count = 0 :if BoostSeconds>0 if yes: BoostSeconds = BoostSeconds - 1: if no: if BoostMinutes > 0: If yes:  BoostMinutes =BoostMinutes - 1 if No: Boost = 0
As for the INT0 macro.
All you do is place:

Code: Select all

BoostSeconds = 0
BoostMinutes = 60
Boost = 1
Note the Boost=1 is to allow the

Code: Select all

 Count  = Count +1
etc to be accessed since at the beginning of the timer interrupt macro I have suggested placing

Code: Select all

If Boost = 1: Count  = Count +1 
etc.
Boost = 0 at the very end stops

Code: Select all

Count  = Count +1
and the all the other decision icons for being accessed

One more important note:
If using bytes you must make sure you don't take one away from 0 or add one to 255 (unless its deliberate )
Because If count = 0 and 1 is taken away:
0 - 1 = 255. so it rolls under.
If Count = 255 and 1 is added:
255 + 1 = 0 So it rolls over.

Hope this helps

Martin

Re: Help with Interupt please

Posted: Mon Nov 18, 2013 10:39 am
by acestu
Hi Creative,

My chart is unfinished which is why there is nothing in one of the Macros, basically I am trying to add a Heating Boost button which will eventually turn the heating on for an hour if the heating timed periods are off, also it won't affect any timed period that turns on, ie if I just switch the power on to pin and then switch off after an hour, if a timed period has started it would be cancelled, Martin is trying to explain interrupts to me but I am struggling with it, thanks for your interest...

cheers
Acestu

Re: Help with Interupt please

Posted: Mon Nov 18, 2013 10:47 am
by acestu
Hi Martin,

I have a few days off work this week so I am going to try and get my head around these interrupts .....

thanks
Acestu

Re: Help with Interupt please

Posted: Mon Nov 18, 2013 12:17 pm
by acestu
Hi Martin,

If I am right you are saying:

Boost Button B0 triggers the INT0 interrupt which calls the Boost Macro

The Boost Macro simply adds the calculation of Boost = 1 , Boostseconds = 0 , and Boostminutes = 60

This then changes the parameters of the Timer0 interupt which is running constantly and runs its routine..


cheers
Acestu

Re: Help with Interupt please

Posted: Mon Nov 18, 2013 12:58 pm
by acestu
Hi Martin,

I am working this out slowly but I am having trouble with the TIM0 interupt as in:

We are counting down from 60 minutes

Boost = 1 activates the routine

Boostseconds are set to 0
Boostminutes are set to 60

count = count +1 this adds 1 every 13.33 milliseconds

When count = 75 this is 1 second, so count is reset to 0 but where is it subtracting the second off the 60 minutes ?
Heating-TimeclockV7.fcfx
(25.34 KiB) Downloaded 297 times

cheers
Acestu

Re: Help with Interupt please

Posted: Mon Nov 18, 2013 2:17 pm
by medelec35
Sorry I was rushing a bit getting ready for work this morning.
What I did miss was BoostSeconds= 60 near the end.

Code: Select all

If Boost = 1: Count  = Count +1: If count = 75: if yes: Count = 0 :if BoostSeconds>0 if yes: BoostSeconds = BoostSeconds - 1: if no: if BoostMinutes > 0: If yes:  BoostMinutes =BoostMinutes - 1:  if No: BoostSeconds =60:  Boost = 0
If you're still struggling then I will edit your flowchart the way I would do it.

You may be best adding variables to debugger, and running simulation at a slower speed.

Check that the seconds are counting down and when seconds go from 1 to 0 then next time (1 second later) seconds go from 0 to 60 and minute goes down 1 as well.

Re: Help with Interupt please

Posted: Mon Nov 18, 2013 4:40 pm
by acestu
Hi Martin,

I am working it out slowly and putting comments in my chart as I go ( I think this will be great for others to learn also), I was working it out logically and it must be working because I realized that once the ticks got to 75 this was a second but a second then had to come off a minute somewhere as we are counting down from 60 minutes. I am really enjoying trying to work this out and I think it is a lot better than you just doing the chart for me as I am learning how to do it for myself, so thanks for spending the time Martin :D

P.S. Not sure what you mean here "You may be best adding variables to debugger"

And You don't have to rush to reply to me before work, I have plenty of time, I don't want you to burn your toast :lol:

cheers
Acestu

Re: Help with Interupt please

Posted: Mon Nov 18, 2013 5:12 pm
by medelec35
To be honest I believe you are spot on with working things out as you go along.
So I don't mind at all going through things step by step :)
acestu wrote:P.S. Not sure what you mean here "You may be best adding variables to debugger"
I am refering to the simulation debugger.
With versions prior to V6, it was referred to the 'Watch Window'
In Flowcode,just hit F8 key.
Simulation Debugger will only load when able to simulate OK.
If there are any errors stopping simulation,the Simulation Debugger will not load.
Once loaded hover to the left of Expression and select the drop down arrow.
The option 'Add Variable' will appear, select it, then just add all your variables.
You can add multiple variables by selecting top variable, hold shift key, then select bottom variable.
Or
you can hold right mouse button an swipe over all the variables.
Once all variable are loaded, you can either single step, or run simulation at a slower speed.
You will then see your variable being updated as their values change.
acestu wrote: I don't want you to burn your toast
No worries of that, I don't eat breakfast :lol:

I don't mean to rush, but my typing skills leave a lot to be desired.
Im very slow. Must be my age :P :lol:

Martin

Re: Help with Interupt please

Posted: Mon Nov 18, 2013 6:09 pm
by acestu
Hi Martin,
debug.png
(9.58 KiB) Downloaded 7643 times
Do you have to enable at the top before the watch window is ungreyed ?


P.S I was 50 on Friday, I know what you mean about the age thing :lol:

cheers
Acestu

Re: Help with Interupt please

Posted: Mon Nov 18, 2013 7:20 pm
by medelec35
acestu wrote:P.S I was 50 on Friday, I know what you mean about the age thing
Happy belated Birthday for Friday.
Don't forget Flowcode simulation has to be running or else Watch window option will be grayed out.

What I did was press F8 to start simulation,
selected all the errors and selected disable in the options:
Simulation Debugger1.png
(94.6 KiB) Downloaded 7636 times
Then I was able to start simulation as soon as all icons was disabled and select variables to watch:
Simulation Debugger2.png
(146.26 KiB) Downloaded 3120 times
Martin


P.s I was in Manchester then Rotherham on Thursday,
Not far from you?

Re: Help with Interupt please

Posted: Mon Nov 18, 2013 7:54 pm
by acestu
Hi Martin,

Thanks for the birthday wishes,

I am sorry I forgot that you might not have Jordy's DS1307 component version 1.4 available here:

http://www.matrixmultimedia.com/mmforum ... 58&t=12882


I don't have any errors when I run simulation, however the watch window always opens without me having to, I just changed sim speed to 10 and ran sim and I got a error message pictured below


Yes Manchester not far from me you should of called in for a brew :D


cheers
Acestu

EDIT:
flowerror.png
(10.86 KiB) Downloaded 7631 times
However I can click on ok then stop the simulation and it is ok

Re: Help with Interupt please

Posted: Mon Nov 18, 2013 8:17 pm
by acestu
Hi Martin,

That is weird, I dropped the speed to 0.25 and added the variable BoostSeconds to the window and I got the following error:
missing.png
(39.03 KiB) Downloaded 7628 times
cheers
Acestu

Re: Help with Interupt please

Posted: Mon Nov 18, 2013 8:28 pm
by medelec35
acestu wrote:I am sorry I forgot that you might not have Jordy's DS1307 component version 1.4 available here:
NO I did not download it, but I have now :)

Simulation is working for me at a setting of prob best for a setting of 50. but now you can single step and manually change variable value to you can test all is working ok.
You can set a break point if you want simulator to pause and show variable values.

The Other thing I do is use RS232 for sending debugging data from microcontroller to my PC.
I send variable values, so I can observe in real time all is working as expected.

Wished I had time to pop in for a cuppa :lol:
But thanks anyway.
acestu wrote:That is weird, I dropped the speed to 0.25 and added the variable BoostSeconds to the window and I got the following error:
I know I moaned about that before. I don't like it when that happens. I did not do that with any other version of flowcode.
Is it possible to resolve the unknown or missing warning when running a simulation please?

Have you tried holding down F8 key or running at 50Hz, and see if that's any better?

It will probably be better if you let the flowcode simulation run at normal speed but fist set a break point where the seconds count down, it will stop at the break point, you can view the seconds variable,
Or you can use the LCD to view variables in simulation.