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.

PWM control using push buttons

Status
Not open for further replies.

ashwal31

Newbie level 1
Joined
Jun 2, 2009
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,287
I am new to microcontroller. I am going to build my first project "Push button controlled PWM" using PIC12F675 for dimming of LED.

I want to control the duty cycle of 100Hz pulse from 0-100%.
Two push buttons, one for increment and another for decrement of duty cycle.
Resolution required is in steps of 2%.

Kindly help me with code.


Thx. :)
ashwal.patel@gmail.com
 

infact this this the coding for dc motor control using PWM with increment and decrement key just try with this u may get some idea

#include<pic.h>
#include"delay.c"

__CONFIG(0x1932);

void PWM_INIT();
void PWM_ON(unsigned int);
void PWM_OFF();
void PWM_INC();

static unsigned int inc;
unsigned int pwm;

void main()
{
TRISB=0x0F;
RB4=0;
RB7=0;
RBPU=0;

PWM_INIT();
inc=1;
DelayMs(10);
while(1)
{
if(RB0==0)
{
DelayMs(3);
if(RB0==0)
{
RB7=1;
if(inc<23)
inc++;
}
}
if(RB1==0)
{
DelayMs(3);
if(RB1==0)
{
RB7=1;
if(inc>1)
inc--;
}
}

if(RB2==0)
{
DelayMs(5);
if(RB2==0){
pwm = (inc * 6) + 60;
PWM_ON(pwm);
}
}
if(RB3==0)
{
DelayMs(5);
if(RB3==0)
{
PWM_OFF();
RB7=0;
DelayMs(5);
PWM_INIT();
}
}
}
}


void PWM_INIT()
{
TRISC1 = TRISC2 = 0;
RC1 = RC2 = 0;
PR2 = 199;
CCPR2L = 0;
CCP2CON = 0x0C;
T2CON = 0x06;
}

void PWM_ON(unsigned int val)
{
CCPR2L=val;
}
void PWM_OFF(){
CCP2CON = 0x00;
if(PR2) PR2 = 0;
if(CCPR2L) CCPR2L =0;
TMR2ON = 0;
RC1 = 0;
}
 
  • Like
Reactions: dselec

    dselec

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top