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] dsPIC30f4011 duty cycle calculation problem

Status
Not open for further replies.

kushal nandanwar

Full Member level 3
Joined
Jun 9, 2013
Messages
177
Helped
6
Reputation
12
Reaction score
6
Trophy points
18
Activity points
1,258
I'm trying to measure on time of a PWM signal using dsPIC30F4011 (Input capture mode), when I increase duty cycle of my signal from 20% to 50% it show correct value , but when increase it form 50% to 80% it's again display 50% to 20% duty cycle on my LCD display. Can someone help me, why this is happening .
 

I'm trying to measure on time of a PWM signal using dsPIC30F4011 (Input capture mode), when I increase duty cycle of my signal from 20% to 50% it show correct value , but when increase it form 50% to 80% it's again display 50% to 20% duty cycle on my LCD display. Can someone help me, why this is happening .
sounds like you are getting an overflow with integer calculations, e.g. when adding to an unsigned 16 bit integer if the result goes over 65535 it starts from 0 again

can you show the algorithm use are using to calculate the PWM %
 

sounds like you are getting an overflow with integer calculations, e.g. when adding to an unsigned 16 bit integer if the result goes over 65535 it starts from 0 again

can you show the algorithm use are using to calculate the PWM %


Thanks for replay ,

I am using long and double variable for holding data.
 

Thanks for replay ,

I am using long and double variable for holding data.
could you be getting overflow in the calculations within expressions
e.g.
Code:
unsigned int a=50000, b=60000;
unsigned long int c=a+b;
printf("c = %lu",c);
on a PIC24 gives c = 44464
the a+b is calculated as an unsigned int (16 bits) then the result promoted to unsigned long int (32 bits)
 

timeintervelon =((t[1]-t[0]));
timeinterveloff=(t[2]-t[1]);
timeintervel=(t[2]-t[0]);
timePeriodoff= (double)(0.0000128*(timeinterveloff));
timePeriodon=(double)(0.0000128*(timeintervelon));
timePeriod=(double)(0.0000128*(timeintervel));

frequency=((1/timePeriod));

duty=(timePeriodon/timePeriod);

this logic showing frequency correct upto 30KHz

but problem with duty cycle .
 

are all the variables double?
how do you convert the variable duty to a text string for display on the LCD?
have you tried using printf() to print the variable values to a serial port for display on a PC
 

long timeintervel= 0,timeintervelon= 0,timeinterveloff= 0,pluse=0;

double frequency,freqavg[200],f,duty=0,timePeriodoff= 0, timePeriod= 0,timePeriodon=0,fon,count=0;

unsigned char Buffer[10],Buffer1[10],Buffer2[10];
long t[8];
unsigned int i=0,j=0,m=0,c,k=0;


sprintf(Buffer,"%f",f);
sprintf(Buffer1,"%f",duty);
 

clearly if the LCD displays the duty cycle from 20% to 50% OK but gives problem over 50% the basic calculation is OK and I can see no obvious problem with calculation of duty cycle over 50%

the problem may be more fundamental - can you print t[0], t[1] and t[2] to ensure that the time measurements are correct at the various duty cycles - in particular over 50%?

what happens if you calculate the duty cycle using timePeriodoff?
 

it's also same as duty cycle .
I think my controller start interrupt at positive cycle t0 ,t1 and t2.
after that it start again interrupt at negative cycle t0 , t1 and t2.

when i try to display duty cycle at low frequency it's duty cycle toggling
30% and 70%
20% and 80%
40% and 60%

- - - Updated - - -

t=IC1BUF;
i++;
//i=i+i;
if(i==5)
{
i=0;

if(t[0]<t[2])
{
 

it's also same as duty cycle .
I think my controller start interrupt at positive cycle t0 ,t1 and t2.
after that it start again interrupt at negative cycle t0 , t1 and t2.

when i try to display duty cycle at low frequency it's duty cycle toggling
30% and 70%
20% and 80%
40% and 60%
when you get an interrupt on change read the PORT value to see if it was a rising or falling edge?

also Section 11. I/O Ports - dsPIC30F FRM
https://ww1.microchip.com/downloads/en/DeviceDoc/70058D.pdf
says
When a CN interrupt occurs, the user should read the PORT register associated with the CN
pin(s). This will clear the mismatch condition and setup the CN logic to detect the next pin
change. The current PORT value can be compared to the PORT read value obtained at the last
CN interrupt to determine the pin that changed.
 

sorry i do't understand that , can you pls elaborate it little more.
 

sorry i do't understand that , can you pls elaborate it little more.

if after interrupt on change you read
1. a high you know is was a rising edge and to start you T1 timing
2. a low it was a falling edge and you finish T1 and start T2
 

There is no input change pin for IC1 and I have my LCD at IC8 and IC7
 

How can use long double variable with sprintf() function .

sprintf(Buffer1,"%f",duty);

%f

showing error.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top