Pulse counting using MonitorPWM object.
msiriwardena
Posts: 301
I am trying to count pulses using the MonitorPWM object.
The count is to be displayed on the TV monitor.
When I run the attached code what I see on the TV is " Pulse Count:0 "and nothing else happens.
The code is attached.
The count is to be displayed on the TV monitor.
When I run the attached code what I see on the TV is " Pulse Count:0 "and nothing else happens.
The code is attached.
Comments
Thanks for your help.
Siri
that's the way I like it! You did your "homework" very well. You provided all files that were nescessary to compile your code.
There is an even easier way to do provide code
the propellertool has a archive-project function
it can be found in the mainmenu under file - archive - project ...
This will create a zip-file by one click that includes all files needed to compile
Now to your code. That was a quite easy one
you have to call your methods PulseCount and HallEffect repeately
so inserted code
As I don't have a TV handy I used PC_Text_advanced which emulates the tv_text-object through the PropTerminal-Tool on the PC
Simply change back to the normal TV_Text-object to use it again with a TV
keep the questions coming
best regards
Stefan
Thanks you for the help.I am now going to try it.
Siri
It did work as intended.Thanks.
Please can you explain to me where in my thought process ,I was incorrect.
My logical thinking was that each method would run on its own cog for ever and keep updating the global variables and use the updated variables in another method in its own cog.
I had more cogs available and not being used.
Thanks again
Siri
again congrats to your stile in asking questions!! Well done. You added your own thoughts to the question how you think it works.
This is very important information for me. Now it is much easier for me what details should be included in my explanation:
If you write a program all methods run in one single cog as long as the command "cognew" is not used.
Only the cognew-command starts another cog.
If you are using objects like MonitorPWM.spin
these object have a start-method. Inside the method start there is the command cognew.
To code in this way that an object has a start-method and INSIDE this start-method is the cognew-command is recommended as standard.
This means as long as methods - even if they are distributed over several objects (= other *.spin-files) they all use the same cog.
only the command cognew starts another cog and then in this second cog only those methods that are called from the initial cognew-command are executed in this new cog
Each method runs as long as there are codelines left to be executed. Except that you code a loop with the command repeat.
This means if a method has no repeat-loop the code is executed one time and if the method ends the code returns "upwards" to the calling method.
if there is no calling method "above" then the cog is stopped.
Have you ever taken a look into the PE Kit-labs?
There are lot's of exercises to examine how spin works with objects and cogs
http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/PELabsFunBook-v1.1.pdf
In Chapter 5 Methods and cogs lab you find code examples and more explanation on that.
keep the questions coming
best regards
Stefan
Thanks for explaining that to me.I do have the PE Education Kit and that is where I got the MonitorPwm object.
My problem is I read/do the lab for a couple of days and then my job takes me away at times a long
periods - so everything looks new again - but I still like to tinker with electronics.
Thanks again
Siri
P.S: I am sure I will have more questions later.