Plan:
This week I decided to work on the control loop. I decided to add a simple adjustment scheme to the 5 mS system timer event. And then create a way to change the required voltage in increments of 0.1 Volts starting at 10.0
Implementation:
I created a local “static” variable in the events.c file for the target voltage. I then created a function to set this variable target_voltage and another function to get the value of target_voltage. I then added a simple if statement into the 5ms event that increments the duty cycle of the Sigma Delta if the measured value is too low and decrements it otherwise. I compiled and tried this, Vpp is ugly.
The automatic measurements of the scope show a minimum voltage of 4.0 Volts and a maximum of 26.6V and it is repeating. My best guess was it’s always incrementing. So I checked for a copy and paste error in the adjustment code. And that is exactly what I found. I had made the increment line, then I copied it and forgot to change it to decrement. This is a classic copy and paste error or mistake. I fixed the code uploaded it and it was ugly again. I had forgotten to scale the output of the adc. Once I fixed that I was getting the 10 Volts I was looking for.
I get the voltage I am looking for, unfortunately with a lot of ripple. There is something that happens about once every second that causes a blip of about ±2.8Volts from my target voltage. This is unacceptable, I need to figure out what is causing this ripple. I disabled the radio to see what would happen. Vpp settled down to 9.8 to 11.4 volts. So about 1.6 volts P-P verses 5.2. Much better, but I need the radio to be working.
Conclusion:
I got the control loop working, but I have some issues to work through. The ripple lasted longer than 5mS. This suggests that if I had stopped adjusting while the radio is active, it might be a bit more stable. I would like to see some way to set/clear a variable based on whether the radio is in an active state or not. I will be considering my options. I have uploaded the code to github, click the link in the right hand column to go look at it.
I want to know how the 2.0 SDK will affect my code. I plan on upgrading to it next week.
Have you written a simple control loop? How about a more complex one such as a PID control loop?