View previous topic :: View next topic |
Author |
Message |
Guest
|
pwm+pic |
Posted: Sun Aug 06, 2006 12:19 pm |
|
|
hi
i want to make a 120khz pwm with timer2 of pic16f877a and with 7.67375mhz cristal and duty cycle 50% in ccs software.
please help me
thanks a lot |
|
|
Ttelmah Guest
|
|
Posted: Sun Aug 06, 2006 2:45 pm |
|
|
It'll actually be 119902Hz (you can't quite do 120KHz with the hardware, given your clock frequency), but the required setup lines are:
setup_timer_2(T2_DIV_BY_1,15,1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(32L);
Note the 'L'. This is important, since it makes the code use the extra two bits in the second register for setting the duty cycle.
Best Wishes |
|
|
Guest
|
|
Posted: Mon Aug 07, 2006 11:59 am |
|
|
Hi
thanks alot for your guidance.
best regards |
|
|
Moeini
Joined: 08 Aug 2006 Posts: 9
|
|
Posted: Tue Aug 08, 2006 1:32 am |
|
|
Hi
Kindly please explain for me about numbers in : setup_timer_2(t2_div_by_1,15,1)
and set_pwm1_duty(32L)
Best Regards |
|
|
Ttelmah Guest
|
|
Posted: Tue Aug 08, 2006 2:35 am |
|
|
Get AN564 from Microchip, and learn how the hardware you are trying to use works.
Best Wishes |
|
|
|