View previous topic :: View next topic |
Author |
Message |
nicenoise
Joined: 10 May 2004 Posts: 17 Location: barcelona
|
pic16f628 pwm problems!!!!!! |
Posted: Fri Nov 26, 2004 3:37 pm |
|
|
hello,
i have a problem with the PIC16F628 and the outputs CCP1, A3 and A4.
I use the CCP1 how PWM for control a dc motor with a MOSFET. For test i use a led, and i want to see the light intensity, this intensity tell my about the duty cycle is, but not works. The output is 5V always... when i put the duty to 0... the output is the same... and the intensity of led not change... the state not change...
another problem are the outputs A3 and A4.... A3 is always 5V and A4 not respond... i think that the problem is with the comparator setup because this pins are the comparator inputs.... i dont know what's happend...
the output A2 works correctly, it lights every second...
i put my test code here...
anybody can help me???
thanks
Alex
Code: |
#include <16F628.h>
#fuses HS,NOWDT,NOPROTECT,NOMCLR,NOBROWNOUT
#use delay(clock=20000000)
//#use rs232(baud=31250, xmit=PIN_A1, parity=N, bits=8)
main() {
byte value = 0x7F;
setup_comparator(NC_NC_NC_NC);
setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
setup_timer_2(T2_DIV_BY_16, 127, 1); // f=1.2 Khz
while (TRUE) {
output_high(PIN_A2);
output_high(PIN_A3);
set_pwm1_duty(127);
delay_ms(500);
output_low(PIN_A2);
output_high(PIN_A3);
set_pwm1_duty(0);
delay_ms(500);
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 26, 2004 3:57 pm |
|
|
What is your version of the compiler ? |
|
|
nicenoise
Joined: 10 May 2004 Posts: 17 Location: barcelona
|
|
Posted: Fri Nov 26, 2004 4:29 pm |
|
|
my version is 3.200...
now, i changed to the old 3.187 and the pwm works....
but, the outputs A3 and A4 not works... its the same problem...
what do you think??
thanks
Alex |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 26, 2004 4:37 pm |
|
|
Vs. 3.200 should not be used. It was the first version of the 3.2xx
series, and it has lots of bugs.
The problem with pin A3 is because your test program never sets
pin A3 to a low level. Both statements set it to high level.
The problem with pin A4 is because that pin has an open-drain output.
The PIC can't drive that pin to a high level by itself. You need to add a
pull-up resistor to that pin. You can use a 4.7K resistor. |
|
|
nicenoise
Joined: 10 May 2004 Posts: 17 Location: barcelona
|
|
Posted: Fri Nov 26, 2004 4:54 pm |
|
|
ok
thanks for your help!!!!!! |
|
|
|