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 code generation using 16f676

Status
Not open for further replies.

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,554
Hi,

Can anybody plz tell me logic to generate PWM using 16f676 and mikroc pro for pic.
 

Hi,
Main issue is pic 16f676 doesn't have inbuilt PWM module. So mikroC pro also doesn't have library for the same. So i have to use software PWM. So plz tell logic for that.

- - - Updated - - -

Hi,
Main issue is pic 16f676 doesn't have inbuilt PWM module. So mikroC pro also doesn't have library for the same. So i have to use software PWM. So plz tell logic for that.
 

See if there is Soft PWM library.

Use two timers. One to toggle an output pin and another to generate delay time for toggling. delay time decides pulse width. First timer decides pulse frequency.
 
Last edited:

ok, but what if i want to set particular intensity of an LED using software PWM using above logic . Can i do it?
 

ok, but what if i want to set particular intensity of an LED using software PWM using above logic . Can i do it?

Yes. The LED intensity is set by the PWM duty cycle. The software PWM does allow for duty cycle setting (if it didn't, it would be useless). So, adjust the duty cycle of the software PWM to adjust the intensity.

Also, if you're interested in hardware PWM, take a look at PIC16F684. It's very similar to the PIC16F676 but has an extra CCP module that you can use for hardware PWM.

Hope this helps.
Tahmid.
 

Thanx Tahmid,

I have implemented hardware PWM in PIC 16f72. Now m working on a solar panel project using 16f676 which doesn't have hardware PWM and in which i have to maintain constant voltage across the load which is sure array of LED's. So when voltage of battery comes down up to 9 v from say 12 v, LED's should glow with the same intensity.
 

Adjust the duty cycle to give constant 'average' voltage. Say, if you wanted a certain intensity at 12V, you need 50% duty cycle. So, that's an average voltage of 6V. To maintain the same intensity at 9V, you'll need the same 'average' voltage. So, your duty cycle must be increased to 6/9 * 100% = 66.7%

Hope this helps.
Tahmid.
 

I am trying, but dont know wts happening, load is not getting off when solar panel ADC value is incresing. I have taken minimum value for it '1' but still not working. Don't know wt wrong i am doing.
 

Hi Tahmid,

Can you plz post c code for software PWM using pic16f676. I am getting confused and mine code is not working. Plz help.
 

THIS is my code
Code:
#define ON 1
#define OFF 0
#define timer_val 200   //LED toggle frequency

int OnPulse = 217;
int OffPulse = 38;
char TOG = 0;
int i = 0;

void interrupt(){

     if(INTCON.T0IF){
     T0IF_bit = 0;
     }
     PORTC.B0 = 1;
     //RC0_bit = 1;
     //Delay_us(10000);
     //PORTC.B2 = 1;
     for(i=0;i<=500;i++)    //For varying intensity
     TMR0 = timer_val;
}


void main() {

     TRISC = 0x00; //PortC as output
     PORTC = 0x00; //Initial value on PortC
     
     INTCON = 0b10100000;
     INTCON.T0IF = 0;
     
     T0CS_bit = 0;
     PSA_bit = 0;  //Prescaler is assigned to Timer0 module
     PS0_bit = 1;  //TMR0 rate 1:2
     PS1_bit = 1;
     PS2_bit = 1;
     
     TMR0 = timer_val;
     
                 while(1){
                 PORTC.B0 = 0;
                 //PORTC.B2 = 0;
                 //Delay_ms(5);
                 }

}

- - - Updated - - -

THIS is my code
Code:
#define ON 1
#define OFF 0
#define timer_val 200   //LED toggle frequency

int OnPulse = 217;
int OffPulse = 38;
char TOG = 0;
int i = 0;

void interrupt(){

     if(INTCON.T0IF){
     T0IF_bit = 0;
     }
     PORTC.B0 = 1;
     //RC0_bit = 1;
     //Delay_us(10000);
     //PORTC.B2 = 1;
     for(i=0;i<=500;i++)    //For varying intensity
     TMR0 = timer_val;
}


void main() {

     TRISC = 0x00; //PortC as output
     PORTC = 0x00; //Initial value on PortC
     
     INTCON = 0b10100000;
     INTCON.T0IF = 0;
     
     T0CS_bit = 0;
     PSA_bit = 0;  //Prescaler is assigned to Timer0 module
     PS0_bit = 1;  //TMR0 rate 1:2
     PS1_bit = 1;
     PS2_bit = 1;
     
     TMR0 = timer_val;
     
                 while(1){
                 PORTC.B0 = 0;
                 //PORTC.B2 = 0;
                 //Delay_ms(5);
                 }

}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top