CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PWM Error on PIC16F1939

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PWM Error on PIC16F1939
PostPosted: Sun Sep 30, 2012 5:15 am     Reply with quote

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
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PWM Error on PIC16F1939
PostPosted: Sun Sep 30, 2012 9:14 am     Reply with quote

Update:
I just program the microcontroller and verified the PWM signals with an oscilloscope and in the microcontroller the program work OK, so I thinks it's a bug in the virtual logic analyser. Confused
_________________
Electric Blue
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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