microsecond timer
Moderator: Benj
- misoct
- Posts: 64
- Joined: Sat Sep 04, 2010 11:03 pm
- Location: Egypt
- Has thanked: 8 times
- Been thanked: 17 times
microsecond timer
I am working in a project to measure the interval of time of range microsecond between two succssive interrput and i used pic16f877a with 8MHz oscillator the flowcode simulation is working in right maner but when i built the hardware the interrput intialize the program without any extenal input by the user and the floting point did not appare on the lcd and gives 0.000000
- Attachments
-
- air(4-9)MSEC.fcf
- (61.45 KiB) Downloaded 318 times
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: microsecond timer
In the timer_pulse macro you have the calculation: msec=sec/1000. To my acknowledge this should be msec=1000*sec. Try once.
Jan Lichtenbelt
Jan Lichtenbelt
-
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: microsecond timer
Hiya misoct.
There are several issues to deal with.
Too much rom used. You need either a target with more rom memory or revise flowchart
In timer-pulse macro you have RB0INT enable in wrong place. This and ALL your interrupts should only be enabled once. You have interrupt within a loop that keeps getting so it keeps enabled.
You should create a decision so interrupt is ignored if already enabled.
Your timer0 interrupts are set for triggering by an external signal, and not from internal clock
In replay macro you have a calculation i=i This will be ignored by Flowcode.
You have got a recursion warning : 'Recursion is allowing a function to call itself within the program'
Also you have exceeded 8 stacks, this will cause your hardware to fail since sofwre will get corrupted.
When you compile to hex or compile to chip, it is advisable to read any warnings. You can ignore
' Warning unreferenced functions removed:'
But warnings like:
Serious Warning: Call stack usage exceeds:8!
Recursion may cause call stack overflow in function:'FCM_start'
WARNING: This interrupt has previously been enabled, so the macro <timer> may never get called.
Should not be ignored.
Warnings like:
Warning: function never returns: 'FCM_timer_pulse'
Can be ignored if you call for that macro and never leave it.
If you leave it via another macro, then you could have stack issues.
To look at all your warnings if you close message box, take a look at a file which is has got the name of your project then .msg.
As for float not being displayed.
If I remember correctly, if you mix a float with a byte or int. within a calculation the result will always be 0.000000 on real hardware, but will look correct on Flowcode simulations.
You should only use functions fadd(), fsub(), fmul() ect when float is used in calculations.
Hope this helps.
There are several issues to deal with.
Too much rom used. You need either a target with more rom memory or revise flowchart
In timer-pulse macro you have RB0INT enable in wrong place. This and ALL your interrupts should only be enabled once. You have interrupt within a loop that keeps getting so it keeps enabled.
You should create a decision so interrupt is ignored if already enabled.
Your timer0 interrupts are set for triggering by an external signal, and not from internal clock
In replay macro you have a calculation i=i This will be ignored by Flowcode.
You have got a recursion warning : 'Recursion is allowing a function to call itself within the program'
Also you have exceeded 8 stacks, this will cause your hardware to fail since sofwre will get corrupted.
When you compile to hex or compile to chip, it is advisable to read any warnings. You can ignore
' Warning unreferenced functions removed:'
But warnings like:
Serious Warning: Call stack usage exceeds:8!
Recursion may cause call stack overflow in function:'FCM_start'
WARNING: This interrupt has previously been enabled, so the macro <timer> may never get called.
Should not be ignored.
Warnings like:
Warning: function never returns: 'FCM_timer_pulse'
Can be ignored if you call for that macro and never leave it.
If you leave it via another macro, then you could have stack issues.
To look at all your warnings if you close message box, take a look at a file which is has got the name of your project then .msg.
As for float not being displayed.
If I remember correctly, if you mix a float with a byte or int. within a calculation the result will always be 0.000000 on real hardware, but will look correct on Flowcode simulations.
You should only use functions fadd(), fsub(), fmul() ect when float is used in calculations.
Hope this helps.
Martin
- misoct
- Posts: 64
- Joined: Sat Sep 04, 2010 11:03 pm
- Location: Egypt
- Has thanked: 8 times
- Been thanked: 17 times
Re: microsecond timer
Hi medelec35
Thank you for your advises
I modified the flowchart according to your notices that you sent me
1-I moved the interrupt RB0 before the while loop in timer_pulse macro
2-I I compressed my flowchart to minimize the used rom
3-I avoid to using float by using integer variable flowed by a units of measuring time out of mili seconds
4-for the external interrupt that is my right choice I do not need an internal trigging
After all of these modification that I made there are some warring massage through the compile the program pls can look at the flowcode file and tell me with your advises
Thank you for your interest
Thank you for your advises
I modified the flowchart according to your notices that you sent me
1-I moved the interrupt RB0 before the while loop in timer_pulse macro
2-I I compressed my flowchart to minimize the used rom
3-I avoid to using float by using integer variable flowed by a units of measuring time out of mili seconds
4-for the external interrupt that is my right choice I do not need an internal trigging
After all of these modification that I made there are some warring massage through the compile the program pls can look at the flowcode file and tell me with your advises
Thank you for your interest
- Attachments
-
- MINIair trac16F877A(test)forum.fcf
- (50.95 KiB) Downloaded 323 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: microsecond timer
If it was my software I would feel uncomfortable with it. For instance
Start macro can call pulse macro= stack. Pulse macro can also call start macro = stack which could call pulse macro. Also interrupts take stack space. Before you know it, you have a stack overflow which leads to corruption as stated in my previous post.
One way round this problem:
You could set up a flag system, so if a macro is called, a flag can be set so same macro is not called again, until out of the 1st macro
Or
If you can guarantee this will not happen then you will either need to increase the stack size by either software method.. See http://www.matrixmultimedia.com/mmforum ... 06&p=17293
Or hardware by using a chip with greater number of stacks available
Maybe someone else could comment? Hope I have helped you out.
Good luck.
Start macro can call pulse macro= stack. Pulse macro can also call start macro = stack which could call pulse macro. Also interrupts take stack space. Before you know it, you have a stack overflow which leads to corruption as stated in my previous post.
One way round this problem:
You could set up a flag system, so if a macro is called, a flag can be set so same macro is not called again, until out of the 1st macro
Or
If you can guarantee this will not happen then you will either need to increase the stack size by either software method.. See http://www.matrixmultimedia.com/mmforum ... 06&p=17293
Or hardware by using a chip with greater number of stacks available
Maybe someone else could comment? Hope I have helped you out.
Good luck.
Martin