E_Blue
Joined: 13 Apr 2011 Posts: 417
|
PWM Error on PIC16F1939 |
Posted: Sun Sep 30, 2012 5:15 am |
|
|
Hi, I'm working on a PIC16F1939 and I need to have a 1KHz PWM on CCP1,CCP2,CCP4.
So I set:
TMR4 Prescaler=1
PR4=255
CCPTMRS0 = 0b01000101
CCPR1L=0x80
and The PWM works fine but not at 1KHz, at 250Hz, the same rate as TMR2 overflow.
Did I forgot something or is a bug in MPLAB SIM?
Code: |
#include <16F1939.h>
#FUSES INTRC_IO,NOWDT,PUT,MCLR,PROTECT,BROWNOUT,CLKOUT,NOIESO,NOVCAP,BORV25,NOLVP,NOFCMEN,PLL_SW
#device adc=10
#use delay(clock=4M)
void main(void)
{
#use fast_io (all)
disable_interrupts(GLOBAL);
set_tris_a(0xFF);
set_tris_b(0xFF);
set_tris_c(0x06);
set_tris_d(0x02);
set_tris_e(7);
clearPorts();
setup_lcd(LCD_DISABLED);
setup_oscillator(OSC_4MHZ|OSC_INTRC|OSC_PLL_OFF);
setup_timer_2(T2_DIV_BY_16,250,1);// 16*250*1=4mS @4MHz
setup_timer_6(T6_DIV_BY_4,250,1);// 1ms
clear_interrupt(INT_TIMER2);
setup_timer_4(T4_DIV_BY_1,255,1);
setup_ccp1(CCP_TIMER4|CCP_PWM);//Pag 233
setup_ccp2(CCP_TIMER4|CCP_PWM);
setup_ccp4(CCP_TIMER4|CCP_PWM);
set_pwm1_duty(64);
set_pwm2_duty(128);
set_pwm4_duty(32);
set_tris_c(0);
set_tris_D(0);
setup_vref(VREF_ON|VREF_ADC_4v096);
setup_adc(ADC_CLOCK_DIV_16);
setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|sAN5|sAN6|sAN8|sAN10|sAN12|VSS_FVR);
|
_________________ Electric Blue |
|