Microcontroller › 8051 › GENERATING VARIABLE PWM
- This topic has 17 replies, 4 voices, and was last updated 11 years, 8 months ago by AJISH ALFRED.
-
AuthorPosts
-
August 10, 2012 at 6:02 pm #8438AJISH ALFREDParticipant
Try the code and update the result,
#include <reg51.h>
sbit INCREASE = P2^6;
sbit DECREASE = P2^7;
sbit MTR = P1^0;
void MSDelay(int value);
void main()
{
unsigned int on,off;
on=20; //initial value of ON time delay
off=0; //initial value of OFF time delay
while (1)
{
while(ONE==1 && TWO==1) //when both keys are open
{//—-generating PWM
//
MTR=1;
MSDelay(on); //applying ON time delay
MTR=0;
MSDelay(off); //applying OFF time delay
//
//
}//—when any of the key is down, exit from while loop and check which key is down–//
if(INCREASE==0 && on<20) //if key increase is down check whether it has max value or not
{on++;
off–; //—-increment ON time delay if it is not maximum–////
//
}
else if (TWO==0 && on>0) // if key decrease is down check whether it ON time delay >0//
{on–;
off++; //—-decrement ON time delay if it is not zero—-////
////***********************************//
//ADD DELAY HERE
MSDelay(1000);
}
}}
void MSDelay(int value) // Delay function //
{
int x;
for(x=0;x<=value;x++);
}August 18, 2012 at 8:29 am #8476Varun SrivastavaParticipantHii,
Ajish
sry fr d delay…!!!
Iwould lyk to let u knw dat the problem is resolved on hardware by considering switch debounce into account.
I would also lyk to give you more overview of wat i m doing.
I am using this GENERATED PWM for driving the GATE of a MOSFET which infact is controlling the current in my LOAD and wid all our previous efforts we are able to vary the DUTY CYCLE of the PWM.
Now the next problem which is faced is that the LOAD is taking HICCUPS due to discontinuity of the GATE driving voltage wen i change the PWM DUTY CYCLE as there is no voltage present at that duration of time when the switch is pressed and the DUTY CYCLE changes.
As per my knowledge, I think that this is happening bcoz dere is no HOLDING CURRENT to sufficiently keep the MOSFET on during that period of SWITCH press.
I would lyk to know about ur suggestion over this thing and whether you have any other possible explanation that why this is happening, also if u cn provide any information how to maintain this HOLDING CURRENT in MOSFET.
Expecting to hear frm u soon.
Thnx
August 19, 2012 at 6:22 pm #8484AJISH ALFREDParticipantHi Varun,
Power electronics a field in which I’ve little knowledge. Hence I dont think it would be appropriate to make any comment on the issue you are facing right now.
Anyway try hard and learn more. All the best.
-
AuthorPosts
- You must be logged in to reply to this topic.