PSoC 16-Bit PWM generation C Language

Discussion in 'Programmer's Corner' started by Max.Otto, Oct 27, 2014.

  1. Max.Otto

    Thread Starter New Member

    Oct 27, 2014
    7
    0
    Hi all , i am working with PSoC 5LP. I have continious changable Analog Signals. I convert it to Digital with help of ADC. From this Result i want to generate PWM (Output1 Forwards, Output2 Ruckwards). All in 16-Bits. So i have range upto 65536.
    I have Analog Input 0,1 to 3,3v. So if i gave Input 1,6v than i have 50% Duty Cycle of generated PWM.
    PWM Basic Configuration:
    16-Bit UDB
    PWM Mode: Two Outputs
    Period: 65535
    CMP Value1: 32767 CMP Value2: 32676
    CMP Type 1: Less CMP Type 2: Greater
    Dead Band: Disable
    Interrupt: None
    Clock with 12MHz freq.
    Here is the code. In ADC_Result i have 12-bit ADC result. From this result i want to generate 2 PWM Outputs. I know that i have to use WritePeriod(), WriteCompare(), WriteDeadtime() APIs.
    Code (Text):
    1.  
    2. int32 ADC_Result;
    3. uint16 i=0;
    4. int pwmValue, pulseWidth;
    5. int main()
    6. {  
    7.   // Start the components
    8.  Sys_Init();
    9.  
    10. // CyGlobalIntEnable;  // Uncomment this line to enable global interrupts.
    11.    // Start Clock & PWM
    12.  Clock_Start();
    13.  PWM_Start();
    14.   while(1)
    15.   {
    16.    
    17.  pwmValue = ADC_Result  // Which equation i have to use.
    18.  PWM_WritePeriod(pwmValue);
    19.  PWM_WriteCompare1();
    20.  
    21.   }  
    22. }
    23.  
    I read the PWM datasheet & also check the Example PWM Programms but still i am much confsed for this following questions.
    1. Need i Dead Band?
    2. Which equation for converting ADC result into PWM?
    3. Need i Interrupt/Global Interrupt ?

    Regards
    Max
     
  2. JWHassler

    Member

    Sep 25, 2013
    201
    33
    You should ask this at http://www.cypress.com/?app=forum
     
Loading...