I was creating a simple labs exercise in flowcode6 originally. I downloaded that file to my laptop which has flowcode7.
The exercise purpose was to measure one second's worht of time thru using the internal clock with timer0.
Then the purpose was to utilize that interrupt to create a simple seconds timer, which prints out seconds in the LCD screen.
The file was originally created in the school computer on flowcode6 and there did not seem to be any problem at the scchool computer.
However when I'm using my home laptop with trial version of flowcode7, the simulation seems to work completely differently.
I tried to do these labs exercises on flowcode6 at my school computer class. The filed uploaded are for exercises B2 and B3
http://www.flowcode.co.uk/courses/itm/in ... Labs.Lab13
My gripe was about the utilization of the interrupt macro and the execution of the program which seemed incomprehensible to me at this point.
At the school computer, my teacher said that the interrupt macro does not need to be placed inside an "eternal loop". He said something to the effect that the interrupt macro works even when placed outside any loops in the main program, and the effectively result would be that the macro is entered into , at tthe rate of 75 times per second (using prescaler setting at 1:256)
Running that flowcode file into our E-blocks at the school computers worked perfectly in the e-block hardware... But like I said the file was created on flowcode6. And we had e-blocks and flowcode6 and we did measure the seconds counter in the eblocks LCD compared to my own handheld Samsung phone seconds timer. The timer was accurate on the hardware...
using that timer0, one can measure one second's worth of time accurately and construct a digital clock project.
But when I opened my school exercise the program works totally differently on flowcode7, as compared to flowcode6.
In flowcode7, the simulation only runs the macro once.... Then the main program runs until the end, and finishes basically immediately during simulation. (instead of running the timer0 macro, and counting and printing the seconds on LCD screen)
1. Does the interrupt call (of the macro) required to be placed inside a loop, or not... in the main program in flowcode6? My goal is to refer constantly to the timer0 oscillator, with which I can measure one second's worth of time, and fulfill digital clock time measurement for my project.
2.Why is flowcode7 seeemingly different with regard to interrupts on timer0?
pic16F1937 interrupt weirdness Timer0 in simulation
Moderator: Benj
pic16F1937 interrupt weirdness Timer0 in simulation
- Attachments
-
- Flowcode labs 13 3rd exercise.fcfx
- (11.25 KiB) Downloaded 319 times
-
- Flowcode labs 13 2nd exercise.fcfx
- (6.58 KiB) Downloaded 303 times
-
medelec35
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: pic16F1937 interrupt weirdness Timer0 in simulation
Hi Late347,
Flowcode labs 13 2nd exercise.fcfx demonstrates this well.
The interrupt macro is indeed placed outside the loops.
It's only required to be activated once.
When it has been activated then , at precised interval's (depending on the interrupt settings) the code will pause and the interrupt call macro will be accessed.
As soon as the interrupt macro has been completed and exited, the code will continue from where it was paused from.
For example if clock speed is 19660800Hz and prescaler of timer0 is 1:256 then interrupt frequency is 75Hz, meaning inrerrupt macro is automatically accessed 75 times evey second = once every 1/75 = 13.3ms.
Simulation speed is way different to real speed.
Flwocode V7 simuation speed was significantly increased when compared with V6 so thats why you are seeing a difference.
Martin
Flowcode labs 13 2nd exercise.fcfx demonstrates this well.
The interrupt macro is indeed placed outside the loops.
It's only required to be activated once.
When it has been activated then , at precised interval's (depending on the interrupt settings) the code will pause and the interrupt call macro will be accessed.
As soon as the interrupt macro has been completed and exited, the code will continue from where it was paused from.
For example if clock speed is 19660800Hz and prescaler of timer0 is 1:256 then interrupt frequency is 75Hz, meaning inrerrupt macro is automatically accessed 75 times evey second = once every 1/75 = 13.3ms.
Simulation speed is way different to real speed.
Flwocode V7 simuation speed was significantly increased when compared with V6 so thats why you are seeing a difference.
Martin
Martin
Re: pic16F1937 interrupt weirdness Timer0 in simulation
What you are saying seems to be true to what my teacher taught at the lesson at school, with flowcode6... But I'm having a hard time replicating what you are saying when I'm running simulation on flowcode7 in the exact same program which I uploaded in my beginning post. (labs 13 2nd exercise)medelec35 wrote:Hi Late347,
Flowcode labs 13 2nd exercise.fcfx demonstrates this well.
The interrupt macro is indeed placed outside the loops.
It's only required to be activated once.
When it has been activated then , at precised interval's (depending on the interrupt settings) the code will pause and the interrupt call macro will be accessed.
As soon as the interrupt macro has been completed and exited, the code will continue from where it was paused from.
For example if clock speed is 19660800Hz and prescaler of timer0 is 1:256 then interrupt frequency is 75Hz, meaning inrerrupt macro is automatically accessed 75 times evey second = once every 1/75 = 13.3ms.
Simulation speed is way different to real speed.
Flwocode V7 simuation speed was significantly increased when compared with V6 so thats why you are seeing a difference.
But it does not work that way when I simulated the same file (labs 13 2nd exercise) in flowcode7...???
The simulation starts and stops immediately within a very short time (some amount of milliseconds) with the lcd remaining empty.
The change which could be made according to your description... would be as follows: remove the loop from main program with delete. Then, place component macro lcd start into the first spot. Then after that component macro, you can place the interrupt call. Now the main program should function in a repetitive fashion. But it does not function like that in the simulation for me at least.... (in flowcode7)
I literally had to put a while loop, after the spot where there was the lcd start componment macro. Then, inside that eternal while loop, I put the interrupt macro. (now the seconds timer seems to work fine, with the macro being accessed and the number of seconds print into the lcd screen in the simulation)
Re: pic16F1937 interrupt weirdness Timer0 in simulation
I think that I figured out what was the problem for my program which was the labs 13 2nd exercise.
Hopefully the picture and explanation of the program flow, seem to make sense.
I was struggling to explain why the interrupt macro did not keep working in the simulation at all in flowcode. The simulation ran the program once, and nothin printed in the lcd screen, when I had deleted the empty while loop at the end of the main program.
Hopefully the picture and explanation of the program flow, seem to make sense.
I was struggling to explain why the interrupt macro did not keep working in the simulation at all in flowcode. The simulation ran the program once, and nothin printed in the lcd screen, when I had deleted the empty while loop at the end of the main program.
- Attachments
-
- explanation flowcode.jpg (90.93 KiB) Viewed 7046 times
-
- flowcode macro interrupt.jpg (83.38 KiB) Viewed 7046 times
-
EtsDriver
- Posts: 444
- Joined: Tue Apr 15, 2014 4:19 pm
- Location: Kajaani, Finland
- Has thanked: 345 times
- Been thanked: 227 times
Re: pic16F1937 interrupt weirdness Timer0 in simulation
As a little notice, id personally not recommended to do high amounts of stuff like printing to lcd inside the interrupt macro on real hardware, as this might cause the clock to become even more unaccurate...
For example you can make a global variables for clock seconds, minutes, hours, and update those inside the interrupt macro to keep "accurate" time, and use main while loop to print onto the LCD as that task is not so critical.
For example you can make a global variables for clock seconds, minutes, hours, and update those inside the interrupt macro to keep "accurate" time, and use main while loop to print onto the LCD as that task is not so critical.
Ill just keep the good work up!
-
medelec35
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: pic16F1937 interrupt weirdness Timer0 in simulation
Hi Late347,
No in my opinion the lower Flwochart is wrong.
You can't place the LCD components within the delay.
Here is want you can try.
Load the attached flowchart
Select the interrupt tab at the top and right click on calculation and select toggle breakpoint like this: Then run simulation.
Don't forget you can single step by pressing F8 function key on your PC keyboard.
Martin
Edit: Already a new post as I was creating post, so information could be duplicated.
No in my opinion the lower Flwochart is wrong.
You can't place the LCD components within the delay.
Here is want you can try.
Load the attached flowchart
Select the interrupt tab at the top and right click on calculation and select toggle breakpoint like this: Then run simulation.
Don't forget you can single step by pressing F8 function key on your PC keyboard.
Martin
Edit: Already a new post as I was creating post, so information could be duplicated.
- Attachments
-
- Flowcode labs 13 2nd exercise v2.fcfx
- (8.99 KiB) Downloaded 308 times
Martin
Re: pic16F1937 interrupt weirdness Timer0 in simulation
Did you intend to have in the main tab, decision clause "if UpDate == 1" instead of leaving the condition clause for decision as simply "if UpDate?" I remember that in my previous programming with Python language we had to always be quite clear with the clauses and how they were written.medelec35 wrote:Hi Late347,
No in my opinion the lower Flwochart is wrong.
You can't place the LCD components within the delay.
Here is want you can try.
Load the attached flowchart
Select the interrupt tab at the top and right click on calculation and select toggle breakpoint like this: Then run simulation.
Don't forget you can single step by pressing F8 function key on your PC keyboard.
Martin
Edit: Already a new post as I was creating post, so information could be duplicated.
your suggestion works really well in the simulation when I remove those "toggle breakpoint" red dots...
The simulation file did not work properly when the toggle breakpoint red dots were engaged in the file
With those breakpoints engaged, the simulation only ran for one time, and only printed a single number on the lcd.???
I don't have very clear idea what is the actual purpose of the "toggle breakpoint" red dot, but removing it seemed to cause the simulation to work as intended. ? So in that regard your suggestion was quite effective from the looks of it.
Anyhow, for my clock project...
I was thinking that the idea was to have clock such as (00:00, 23:57 etc... 24 h format)
Would you recommend that there were variables for
*ones place minutes
*tens place minutes
*ones place hours
tens place hours
and utilize those variables to show time such as
00:00 on the lcd
or
06:59
etc...
-
medelec35
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: pic16F1937 interrupt weirdness Timer0 in simulation
The breakpoint is just that.
If you run the simulator then the simulator will stop at each breakpoint.
To continue with the simulation you must select run again!
Its purpose is:
If simulation runs too fast.
if condition changes e.g update changes from 0 to 1
Pause to check variables etc.
just means If any number except 0
Since a Bool can be 0 or 1 then only when update=1 statement will be true.
You can use one variable for hours, one variable for minutes & one for seconds.
If the variable is less then 10 then you can send a string 0 to the display prior to displaying the variable value.
For that you can use a Decision.
So for example if secondsVariable = 5 ,
Martin
If you run the simulator then the simulator will stop at each breakpoint.
To continue with the simulation you must select run again!
Its purpose is:
If simulation runs too fast.
if condition changes e.g update changes from 0 to 1
Pause to check variables etc.
Code: Select all
If updateSince a Bool can be 0 or 1 then only when update=1 statement will be true.
You can use one variable for hours, one variable for minutes & one for seconds.
If the variable is less then 10 then you can send a string 0 to the display prior to displaying the variable value.
For that you can use a Decision.
So for example if secondsVariable = 5 ,
Code: Select all
If SecondsVariable < 10Code: Select all
PrintSting "0" Code: Select all
print SecondsVariable Martin