Changing variable value over time
Jasp
Posts: 7
Hi everybody,
I'm working on a thesis in which I make an audioprocessor which is controlled by the Propeller. It's my first project ever with Propeller and I tried to teach the programming to myself, I don't have a background in programming. I only know the spin-language, assembly is still unknown to me. After three days of trying to solve the last problem in my program, I still have four days before my deadline, so I'm getting kind of nervous. What I try to do is change the value from a variable to another value in a certain time interval.
I attached the program in this message, PUB-routine 'CH1' is the routine which starts one of the following PRI-routines (Gate, Expander, Compressor or Limiter). In those PRI-routines I have to change the value of CV from 3093 to another (calculated) value. When some conditions are met, CV has to go back from the calculated value to 3093. Everything works as long as I don't introduce the timing stuff. The time in which CV has to change between values is controlled by the ATCK- en RLSE-variables (GATCK and GRLSE for Gate, EATCK and ERLSE for Expander, ...). All those times are in milliseconds.
The 'Thesis, with time problem'-object is the top-object in which the times have to be introduced. 'Scriptie' is the original top-object where I tried some stuff already.
I tried to explain myself as good as I can. I hope somebody can help... Does anybody have any hints?
Thanks!
Jasper
I'm working on a thesis in which I make an audioprocessor which is controlled by the Propeller. It's my first project ever with Propeller and I tried to teach the programming to myself, I don't have a background in programming. I only know the spin-language, assembly is still unknown to me. After three days of trying to solve the last problem in my program, I still have four days before my deadline, so I'm getting kind of nervous. What I try to do is change the value from a variable to another value in a certain time interval.
I attached the program in this message, PUB-routine 'CH1' is the routine which starts one of the following PRI-routines (Gate, Expander, Compressor or Limiter). In those PRI-routines I have to change the value of CV from 3093 to another (calculated) value. When some conditions are met, CV has to go back from the calculated value to 3093. Everything works as long as I don't introduce the timing stuff. The time in which CV has to change between values is controlled by the ATCK- en RLSE-variables (GATCK and GRLSE for Gate, EATCK and ERLSE for Expander, ...). All those times are in milliseconds.
The 'Thesis, with time problem'-object is the top-object in which the times have to be introduced. 'Scriptie' is the original top-object where I tried some stuff already.
I tried to explain myself as good as I can. I hope somebody can help... Does anybody have any hints?
Thanks!
Jasper
Comments
I don't have time today to look at your code but monitoring time is pretty easy with the Propeller.
Here's code that updates a counter every half second. The time interval could easily be changed and some other task besides displaying the counter could be done whenever the interval is reached.
Edit: The red font messes up the formatting a bit. I think the code will still work as it is now.
I tried implementing your code and I think there's just something strange going on elsewhere. I attached a small piece of code to this message and commented it.
Somehow the attacktime (EATCK) doesn't work at all, the releasetime introduces some crazy audio artefacts.
Am I overlooking something in this code?
Thanks!
Jasper
Welcome to the forum. It is not clear what your problem is from your post. Assuming that your code is fine and should work as written, often when variables are not showing up as intended, it is possible the stack space is being ran over. In your case, you can do a quick test by changing StackDac to 48, also the other stacks may be increasing as well. If a stack is too small, it can run over to the next address in memory beyond the stack allocation you, causing problems there.
CV is a variable that is calculated with some other variables, the calculated value will always be lower than 3093.
There are two time-variables (EATCK and ERLSE), both of them are expressed in milliseconds.
Before CV was calculated, it has a 'standard'-value of 3093, what I want to do is bring CV from 3093 to the calculated value in the ERLSE-time.
What I tried to do is calculate the amount of clock cycles that have to pass each time CV is subtracted by one. I made a loop that subtracts 1 from 3093 and then waits the calculated amount of clock cycles each time the program goes through the loop.
When some conditions are met however, CV has to go back from the calculated value to 3093. This has to happen in the EATCK-time.
Somehow, the code I included in my previous message won't work. I tried increasing the stackspace for all cogs, but I still have the same problem. I don't know where to look for the problem anymore, so I tried my luck on this forum.
Jasper
If this is your original intendation ...
... then it should propably be
But you should also give us an idea of the ranges we talk about. If your ATime and RTime is shorter than the execution time of the loop, then you might not get what you want!
Yay .... 2000th post for me ;o)
About the timing, CV can go from 3093 to a value as low as 0 in a time as short as 1ms. So when CV has to go from 3093 to 0, I tried to split 1ms in 3093 loopcycles in which each loopcycle decrements CV with 1.
ATime := ((EATCK * 80_000)/(3093-CV))
What you say is that EATCK can be 1 and CV can be 0! ATime in this case would be 25. 25 clock cycles are 6 PASM instructions (only 4 cycle instructions). So, no jump and no HUB-access.
I'm sorry, but what you want to do is even to fast for PASM, unless I missed something.
Where is CV used? I'd guess that the place where it is read is not faster than your Expander routine. Maybe you should calculate an increment which is bigger than 1 but therefore gives you more ATime.
What I'd do is to measure the time that your loop needs. This should give you an idea about how big ATime needs to be minimum.
The unrolled loop of DAC is:
So, as is, this should give you some time for the Expander, but it could also be improved! For example you could move the MCP-code into your own code and optimize:
Just to make everything a bit clearer: CV is the control voltage used to control an analog VCA.
Now, something else happened: the attack-part doesn't work at all and the release-part sounds like a hold (CV stays 3093 for the RTime and than suddenly drops to it's calculated value). I'm thinking there's something wrong with the if-conditions in the Expander-routine. This is how the code looks now:
About the DAC-stuff, I'm not sure I understand what you're saying. Looking at the datasheet, I think the DAC-value is updated every 16 clockcycles.
In any case, thanks for your support already!