How to use "cognew" to execute more than one method?
Siri
Posts: 220
I have 2 programs - they work well individually but I require one program share data with the other.
Each program has 7-8 Public methods.
What I am trying to do is to run at least 2 methods in one cog so I can put both programs in one prop - rather than
using 2 props.
In other word can 2 methods be made to run in one cog sequentially/serially.
Thanks
Siri
Each program has 7-8 Public methods.
What I am trying to do is to run at least 2 methods in one cog so I can put both programs in one prop - rather than
using 2 props.
In other word can 2 methods be made to run in one cog sequentially/serially.
Thanks
Siri
Comments
One program produces data that changes fairly rapidly and the other uses this data to open and close couple of solenoid valves.
There is enough memory as the two programs do not use much.
I am going through the Prop kit labs and I am using more than one cog for each program.What I am trying now is to
put 2-3 methods together to bring the number of methods down so I can run all of them in one prop.
I am checking the memory usage - there is enough memory.
What I thought was ? may be there was some way of adding more than one method to the "cognew" parameter list.
Thanks
Siri
The number of methods or the number of objects has nothing to do with how many cogs you need or how they work.
A cog is just a microprocessor that can run a piece of code. The COGNEW statement just gives a starting point and
supplies a stack to use for local variables and calls to other methods. One method can simultaneously be executed by
more than one cog. You can also have two cogs that execute completely separate sections of code. If you're using a
cog to execute assembly language, you don't need a stack for that cog since only the Spin interpreter needs a stack.
It sounds like you could use a single cog to do what you want. It sounds like one program goes through a cycle collecting
data. If the decision to open or close the valves is only made at the end (or beginning) of a measurement cycle, then why
not just call that code at the end of the cycle? The only time you need a separate cog is when you really have to execute
two things at the same time, either because of speed considerations or because it makes the program simpler.
thanks for the help.
I will try what you suggested.
Siri
There are programs, and there are subroutines. Some are exported and available to other source files.
There are memory address locations you write to and read from.
You can always, from a program, sequentially call different subroutines that handle different things, and then loop back to the beginning and do it all over again.
Thanks you.
I manged to put both programs to run in one prop and it works as it is intended.
Siri