Problem passing variables inside an if statement
Posted: Tue Apr 19, 2011 2:53 pm
Hi All,
I have attached the flowocde & compiled C file for a DC Servo control for 1-axis of a Robot using a PID Macro that I obtained from the flowcode examples section of this website.
Bascially, this is a PID positional control loop for a DC motor with a potentiometer connected to its shaft to feedback the shaft position . It operates as follows:-
The digital inputs are:--- 1)Enable 2) Mode 3) Home 4) Away
The Analog ADC inputs are:--- 1) Setpoint for potentiometer 2) Feedback potentiometer.
The Digital outputs are:--- 1)PWM output to drive an amplfier board which is used to drive the DC Motor bi-directionally (50:50 Duty Cycle = no drive).
There are 2 modes:--- (1) Manual (2)Automatic
In Manual mode, an external potentiometer is connected to an ADC on the PIC which sets the position for the shaft. When in Manual mode, if the Home position switch is set momentarily high this stores the Home position setpoint.
Similarily, if the shaft is moved to an alternative position and the Away position switch is set momentarily high this stores the Away position setpoint.
In Automatic mode, if both the home and away switch are low then the shaft stays in the same position as it previously was.
In Automatic mode, if the Home position switch is set high then the Motor shaft should move to the Home postion setpoint recorded when in Manual mode, but this is not working correctly. It simulates fine, but in reality the Motor seems like it is getting a zero setpoint and it cannot control the shaft position.
In Automatic mode, if the Away position switch is set high then the Motor shaft should move to the Away postion setpoint recorded when in Manual mode, but this is not working correctly. It simulates fine, but in reality the Motor seems like it is getting a zero setpoint and it cannot control the shaft position.
I have written hardcoded values to the assigned vaiables and it works fine when I do this but I dob't understand why it has a problem passing a value in one variable to another variable.
I have verfied that all the switches are all wired to the correct pins on the 16F1824 chip. I had to use the Hi-Tech C compiler as suggested by Ben to get this working. The chip is controlling the position fine and operates 90% correctly but I'm suspicious that the translation from flowcode to assembly is not as it should be and maybe introducing a bug in the passing of values from one variable to another variable from two branches of an if statement.
Rgds,
Paul
I have attached the flowocde & compiled C file for a DC Servo control for 1-axis of a Robot using a PID Macro that I obtained from the flowcode examples section of this website.
Bascially, this is a PID positional control loop for a DC motor with a potentiometer connected to its shaft to feedback the shaft position . It operates as follows:-
The digital inputs are:--- 1)Enable 2) Mode 3) Home 4) Away
The Analog ADC inputs are:--- 1) Setpoint for potentiometer 2) Feedback potentiometer.
The Digital outputs are:--- 1)PWM output to drive an amplfier board which is used to drive the DC Motor bi-directionally (50:50 Duty Cycle = no drive).
There are 2 modes:--- (1) Manual (2)Automatic
In Manual mode, an external potentiometer is connected to an ADC on the PIC which sets the position for the shaft. When in Manual mode, if the Home position switch is set momentarily high this stores the Home position setpoint.
Similarily, if the shaft is moved to an alternative position and the Away position switch is set momentarily high this stores the Away position setpoint.
In Automatic mode, if both the home and away switch are low then the shaft stays in the same position as it previously was.
In Automatic mode, if the Home position switch is set high then the Motor shaft should move to the Home postion setpoint recorded when in Manual mode, but this is not working correctly. It simulates fine, but in reality the Motor seems like it is getting a zero setpoint and it cannot control the shaft position.
In Automatic mode, if the Away position switch is set high then the Motor shaft should move to the Away postion setpoint recorded when in Manual mode, but this is not working correctly. It simulates fine, but in reality the Motor seems like it is getting a zero setpoint and it cannot control the shaft position.
I have written hardcoded values to the assigned vaiables and it works fine when I do this but I dob't understand why it has a problem passing a value in one variable to another variable.
I have verfied that all the switches are all wired to the correct pins on the 16F1824 chip. I had to use the Hi-Tech C compiler as suggested by Ben to get this working. The chip is controlling the position fine and operates 90% correctly but I'm suspicious that the translation from flowcode to assembly is not as it should be and maybe introducing a bug in the passing of values from one variable to another variable from two branches of an if statement.
Rgds,
Paul