Discussion in "Project Doubts" started by    Max    Oct 30, 2014.
Thu Oct 30 2014, 04:39 pm
#1
Hello all,
before generating i have to give PWM period value from given input.
I have Analog Input from 0 to 3,3v. From ADC i get answer into uint16 ("ADC_Result" in code).
Now i want to divide this result to get PWM Period time.
if Input 0,2v then PWM_Period = 149...this value increses with upto 3,3 v.

Last value for PWM_Period = 479.

how can i do this?
uint16 ADC_Max=65535;
uint16 ADC_Min=0;

uint16 ADC_Result1;
uint16 Period1;

int main()
{       
	int32 ADC_Result;
	float Comp_Val; //,CMP;
	
         // Start the components 
	Sys_Init(); 	
	
    while(1)
    {			
      ADC_DelSig_StartConvert();  // Start the ADC conversion
		
        if(ADC_DelSig_IsEndConversion(ADC_DelSig_RETURN_STATUS)) // Check ADC EOC flag
        {
            ADC_Result = ADC_DelSig_GetResult32(); // Get Result
			
		// Limit the result to 0..65535
		if(ADC_Result < ADC_Min)   ADC_Result = 0;	
		if(ADC_Result >
 ADC_Max)  ADC_Result = 65535;
			
		/ Display ADC result in mVolts on LCD
		ADC_Result1 =  ADC_DelSig_CountsTo_mVolts((uint16)ADC_Result);
			
                                    LCD_Position(1u, 0u);				
		LCD_PrintDecUint16(ADC_Result1); 
						
		if (ADC_Result >
= 206)
		Period1 = 149; // like this				
        }}}

pls share ur ideas & suggestions.

Regards
Max


[ Edited Thu Oct 30 2014, 07:11 pm ]
Sun Nov 02 2014, 12:03 pm
#2
You need to make simple equation for PWM conversion. Here is a example:

Maxpwm - minpwm = pwmsteps
E.g 450 - 100 = 350 steps

Maxvolt - minvolt = voltsteps
E.g 3300 - 0 = 3300 mv

PWM Per step = pwmsteps/voltsteps = 350 / 3300 = 0.106

PWM = minpwm + (adc_mv * pwm per step) = 100 + (mv * 117) / 1000

You get your PWM value. Try it and let us know.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

RobertGug
Tue Jun 18 2024, 04:38 pm
Jasonabepe
Tue Jun 18 2024, 04:24 pm
Thomcyday
Tue Jun 18 2024, 08:38 am
WalterWib
Tue Jun 18 2024, 05:44 am
SialisshopWat
Mon Jun 17 2024, 09:22 pm
Thomasraima
Mon Jun 17 2024, 07:17 pm
EriksaLaf
Mon Jun 17 2024, 03:13 pm
Anthonyjinee
Mon Jun 17 2024, 06:23 am