Digital Mathwork on PIC1320

Discussion in 'Programmer's Corner' started by LearnPIC1234, Mar 15, 2007.

  1. LearnPIC1234

    Thread Starter New Member

    Feb 23, 2007
    Hi all,

    This is a very crucial problem for my project. I try to solve it few days ago but still no solution, hope anyone could provide me the idea or solution.

    I have 3 variables in the program (Error , Kp & Control) , "Error" is signed 8 bits, "Kp" is unsigned 8 bits, "Control" is signed 16 bits variables.

    Error = Error - 128 ; //read Error then subtract the offset value
    Kp = Kp; //Read Kp
    Control = Error * Kp; //multiply the error with the Kp


    I want to use 8 bits long to represent the value of "Control", what can i do to match my requirement.

    Actually the idea of this project is control an inverted pendulum by using software PID controller, "Error" is the displacement angle, minus 128 will output 0 error when pendulum is balance. "Kp" is proportional gain vary 0~255.
    "Control" value will copy into PWM register, but the PWM register is an 8bits long register, so i wonder that how to solve this kind of problem.
  2. thingmaker3

    Retired Moderator

    May 16, 2005
    Can you get away with using the 8 most significant bits?