View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 09, 2010 2:17 pm |
|
|
Try this program. It will go from 0 to 100% duty cycle. It starts at 50%.
When you press 'F', it increases the duty cycle. When you press 'R' it
decreases the duty cycle. When you press 'S', it goes to 50%.
I tested this program in hardware with compiler vs. 4.107.
Code: |
#include <16F877.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//===========================
void main()
{
char c;
int8 pwm_duty;
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 49, 1);
pwm_duty = 25; // Initially set pwm duty cycle to 50%
set_pwm1_duty(pwm_duty);
while(1)
{
c = toupper(getc()); // Wait for input
if(c == 'F')
{
if(pwm_duty < 50)
{
pwm_duty++;
set_pwm1_duty(pwm_duty);
}
}
if(c == 'R')
{
if(pwm_duty > 0)
{
pwm_duty--;
set_pwm1_duty(pwm_duty);
}
}
if(c == 'S')
{
pwm_duty = 25;
set_pwm1_duty(pwm_duty);
}
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Neo
Joined: 06 May 2010 Posts: 5
|
|
Posted: Mon May 10, 2010 12:28 pm |
|
|
Thank you PCM programmer, but i tried my code today and it worked fine ;)
But i have new question, i want to get complemented pulse on other pwm out port. How can i turn first pulse to inverse? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 10, 2010 1:07 pm |
|
|
The 16F877 doesn't have the ability to do that. You need to use another
type of PIC.
It would help if you tell us what is the purpose of your project. |
|
![](templates/subSilver/images/spacer.gif) |
Neo
Joined: 06 May 2010 Posts: 5
|
|
Posted: Mon May 10, 2010 1:40 pm |
|
|
I'm trying to make boost converter with Mosfet, and this control circuit dirves mosfet at 100kHz.
I asked that inverted pulse for my friend, he tries static compensation and need to drive 2 mosfets with complemented pwm. |
|
![](templates/subSilver/images/spacer.gif) |
|