Proportional Controller on a PIC16F9690

Discussion in 'Embedded Systems and Microcontrollers' started by NzoBoss, Jun 2, 2010.

  1. NzoBoss

    Thread Starter New Member

    Jun 2, 2010
    3
    0
    Hello fellow EE Brothers,

    I'm trying to code a very simple proportional controller for the first steps of my internship.

    I'm acquiring an analog continuous signal let's say with voltage between 0 and 5V. I do it through AN0... and then I want to generate a PWM... my problem is that I don't know how to translate the output of the DAC into PWM multiplied by the proportional factor.

    Here's my code, I'm using the CC5X free compiler:

    In the code, I've mentioned were I'm stuck... any help or input would be much appreciated !! :)

    Nzo
     
    Last edited: Jun 4, 2010
  2. ELECTRONERD

    Senior Member

    May 26, 2009
    1,146
    16
    I'm relatively new to C programming myself, but the trick is to think like a compiler or computer. Run through the code and see what the compiler would do. Also, does your free compiler have a simulator? I know that MPLAB does.
     
  3. NzoBoss

    Thread Starter New Member

    Jun 2, 2010
    3
    0
    Hello electronerd, yes I'm using MPLAB too... I did not know there were simulators... that's good to know. CC5X is just to compile from C code to the pic... and is called automatically from MPLAB.

    My problem is how to go from ADRESH the output of the Analog-To-Digital converter... to the PWM... I want ADRESH * P(some gain) = PWM Output on P1A.. Does anyone know how to do this ?
     
  4. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    Is it possible that you mean the PIC16F690? I don't think the PIC16F9690 exists.

    Assuming it's the PIC16F690, what have you found in section 11.0 of the user manual?
     
  5. NzoBoss

    Thread Starter New Member

    Jun 2, 2010
    3
    0
    Hello John, yes you're right it's the PIC16F690.. I've looked at section 11 on the enhenced PWM but still I not able to figure out how to output the results of the DAC i.e. ADRESH through PWM... ? Anyone ?
     
  6. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    All right, now go down to section 11.3.7, "SETUP FOR PWM OPERATION". What are you seeing there?
     
Loading...