Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] 16-Bit PWM generation

Status
Not open for further replies.

Max.Otto11

Newbie level 6
Newbie level 6
Joined
Oct 13, 2014
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
180
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:
int32 ADC_Result;

uint16 i=0;
int pwmValue, pulseWidth;

int main()
{       
    // Start the components 
	Sys_Init(); 
		 
//	CyGlobalIntEnable;  // Uncomment this line to enable global interrupts.

   	// Start Clock & PWM
	Clock_Start();
	PWM_Start();						

    while(1)
    {														
            		
	pwmValue = ADC_Result  // Which equation i have to use.
	PWM_WritePeriod(pwmValue);
	PWM_WriteCompare1(); 
										
     }    
}

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
 

16-Bit PWM Program

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.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: One Outputs
Period: 65535
CMP Value1: 32767
CMP Type 1: Less
Dead Band: Disable
Interrupt: None

Clock with 12MHz freq.

Here is the code. In ADC_Result i have 16-bit ADC result. From this result i want to generate 1 PWM Output. I know that i have to use WritePeriod(), WriteCompare(), WriteDeadtime() APIs. In Program i have ADC answer into Variable "ADC_Result". I gave Input 1,6v so i get PWM with 50% Duty cycle. But when i run this Programm i got nothing.
Code:
uint16 ADC_Max=65535;
uint16 ADC_Min=0;

uint16 ADC_Result;
float Comp_Val;

int main()
{       
    // Start the components 
	Sys_Init(); 
		 
	//CyGlobalIntEnable;  // Uncomment this line to enable global interrupts.

	
	// Start Clock & PWM
	Clock_Start();
	PWM_Start();						

    while(1)
    {
									
		Comp_Val = (float)(PWM_ReadPeriod() / (ADC_Max * ADC_Result));
						 
                           PWM_WritePeriod(PWM_ReadPeriod() );					                 
                         PWM_WriteCompare(Comp_Val); 									    		
        }
    }
}

pls help me for this.

Regards
Max

- - - Updated - - -

I do it. I gave all variables to uint16.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top