Changing variable value over time
Jasp
Posts: 7
Hi everybody,
I'm working on a project in which I control a VCA with the prop. I'm trying to introduce an attack- and releasetime in which the prop changes the control voltage (for the vca).
Here's how my code looks now:
CV is the variable which is written to the adc and controls the VCA. It's standard value is 3093. What I need is a little piece of code which changes the CV-value from 3093 to a calculated value (which is already calculated with the formula in the code above) over a time between 1ms and 1000ms (the releasetime, the releasetime-value is written in the variable RTIME). Afterwards, if the first if-condition which leads to a return (not the last two) is true, CV has to change back from the calculated value to 3093 in a time between 1ms and 200ms (the attacktime, ATIME). The calculated value from CV can be between 0 and 4095.
I tried a lot of things already but it just won't work... Does anybody has any hints on how to program the attack- and/or releasetime in this code?
Thanks,
Jasper
I'm working on a project in which I control a VCA with the prop. I'm trying to introduce an attack- and releasetime in which the prop changes the control voltage (for the vca).
Here's how my code looks now:
PRI Expander ADYN := 1 if EHOLD > 0 waitcnt ((EHOLD * (Clkfreq / 1000)) + cnt) Repeat CV := 3093 + (OutCon * EGAIN) + (OutCon * (((RMSdB - ETRHD) * ERTIO) - (RMSdB - ETRHD))) ADin := AD.in(1) RMSdB := ((ADin - 3280) / InCon) REDdB := (-(3093 - CV) / OutCon) if (ADin > ((InCon * ETRHD) + 3280)) and (ADYN == 1) ADYN := 4 Return if (ADin =< ((InCon * GTRHD) + 3280)) and (ADYN == 1) and (GBP == 1) Gate Return if (EBP == 0) and (ADYN == 1) ADYN := 4 Return
CV is the variable which is written to the adc and controls the VCA. It's standard value is 3093. What I need is a little piece of code which changes the CV-value from 3093 to a calculated value (which is already calculated with the formula in the code above) over a time between 1ms and 1000ms (the releasetime, the releasetime-value is written in the variable RTIME). Afterwards, if the first if-condition which leads to a return (not the last two) is true, CV has to change back from the calculated value to 3093 in a time between 1ms and 200ms (the attacktime, ATIME). The calculated value from CV can be between 0 and 4095.
I tried a lot of things already but it just won't work... Does anybody has any hints on how to program the attack- and/or releasetime in this code?
Thanks,
Jasper
Comments
I found it difficult to follow the logic of your code.
The reasons are
- you didn't posted your complete code
- the variablenames are not selfexplaining
So I wrote some code from scratch wich does what you described in your post.
You need to diffentiate on two cases
difference between start and endvalue is bigger / smaller than the time in which the endvalue should be reached.
below working code that shows a demo on Parallax Serial Terminal (F12)
that gives you feedback what values the content of variable ActualValue has in each loop
just as a first hint
best regards
Stefan
you should not have started a new thread! The old one gives a lot more informations about your problem. Especially the part where I told you that it does not make sense to increase CV more often than your other COG can send the value to the DAC!