sorry, got another question!
I've been trying to teach myself how to create a proportional controller with pwm/duty cycle output, so I came up with a program that would read a 10 bit input from an adc,
compare it to a setpoint value, and adjust the duty cycle up or down depending on the feedback delivered by the adc.
For examples sake, the setpoint was 512, so I could see the programs response by adjusting the knob/adc to either extreme.
I have noticed some odd behaviour though, and it normally happens when the duty cycle is changing (going up or down, remember the knob is set to an error, so it should add up to 100 or zero, with the speed of countdown depending on how far the knob is turned).
I don't have a scope, but measuring the voltage whilst the duty cycle is dynamically responding shows that the output jumps around a bit before settling at either extreme. Realising this was probably a crap way of testing, I used a software simulator with a scope 'plugin' to see what was happening.
And I'm confused at the results.
In realtime, with the code running at more or less full speed (ish) the duty cycle on the scope hits 100%, then the correct duty cycle, then 100% again etc. I don't understand why, the recalculation of the error and the duty cycles occurs at 10hz. (using a 100ms delay).
To try and troubleshoot I modified the code so that when a switch was pressed, the duty cycle would not be recalculaed and it would jut reuse the old values. Now the duty cycle settles at the correct value if i hold down the switch, though if i release, it bounces around again, then when i press the switch it stops at the new correct value again.
The duty cycle is capped below 0 and 100 (%)so it's not going out of bounds.
I don't think i've explained this well, but i've done my best. Key thing to note is the adc does not control the duty cycle, it controls the feedback in a proportional loop, so therefore alters whether the duty cycle goes up or down and the rate at which it does such.
cheers, and sorry for another question! as i'm using this for a controller with adc as feedback, the duty cycle will almost never cease adjusting, so if i can make it smoothly go from say, 23% to 25% without a period of 100% between, it would be nice....
I've been trying to teach myself how to create a proportional controller with pwm/duty cycle output, so I came up with a program that would read a 10 bit input from an adc,
compare it to a setpoint value, and adjust the duty cycle up or down depending on the feedback delivered by the adc.
For examples sake, the setpoint was 512, so I could see the programs response by adjusting the knob/adc to either extreme.
I have noticed some odd behaviour though, and it normally happens when the duty cycle is changing (going up or down, remember the knob is set to an error, so it should add up to 100 or zero, with the speed of countdown depending on how far the knob is turned).
I don't have a scope, but measuring the voltage whilst the duty cycle is dynamically responding shows that the output jumps around a bit before settling at either extreme. Realising this was probably a crap way of testing, I used a software simulator with a scope 'plugin' to see what was happening.
And I'm confused at the results.
In realtime, with the code running at more or less full speed (ish) the duty cycle on the scope hits 100%, then the correct duty cycle, then 100% again etc. I don't understand why, the recalculation of the error and the duty cycles occurs at 10hz. (using a 100ms delay).
To try and troubleshoot I modified the code so that when a switch was pressed, the duty cycle would not be recalculaed and it would jut reuse the old values. Now the duty cycle settles at the correct value if i hold down the switch, though if i release, it bounces around again, then when i press the switch it stops at the new correct value again.
The duty cycle is capped below 0 and 100 (%)so it's not going out of bounds.
I don't think i've explained this well, but i've done my best. Key thing to note is the adc does not control the duty cycle, it controls the feedback in a proportional loop, so therefore alters whether the duty cycle goes up or down and the rate at which it does such.
cheers, and sorry for another question! as i'm using this for a controller with adc as feedback, the duty cycle will almost never cease adjusting, so if i can make it smoothly go from say, 23% to 25% without a period of 100% between, it would be nice....