|
|
View previous topic :: View next topic |
Author |
Message |
ahmad
Joined: 09 Mar 2007 Posts: 6
|
Need help for pwm |
Posted: Fri Mar 09, 2007 3:43 am |
|
|
I write the following program to generate pwm and there is no output 0n rc2/ccp1 pin ,any body help me.
#include <16F877A.h>
#fuses HS
#fuses NOWDT
#fuses NOPROTECT
#fuses NOLVP
#fuses NODEBUG
#fuses NOPUT
#fuses NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#pragma zero_ram
#define motora PIN_B7
void main(void)
{
set_tris_c(0b00000000);
setup_timer_2(T2_DIV_BY_16,255,1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(1023);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
} |
|
|
Ttelmah Guest
|
|
Posted: Fri Mar 09, 2007 4:54 am |
|
|
Two things:
Unless you add:
while (TRUE);
at the end of your code, the processor will go to sleep, and no output at all will occur.
Second, you need a lower duty cycle, to see any pulse.
Set_pwm1_duty(512L);
will give a square wave, which will be easier to see. The 'L', is not necessary with 512 (since it is above 255), but ensures that the code 'sees' a 'long', no matter what value is given, and treats the number as such.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|