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

Simple PWM on CCP1 with 18f45k22 (solved)

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



Joined: 16 Apr 2007
Posts: 64
Location: Stuttgart, Germany

View user's profile Send private message Visit poster's website

Simple PWM on CCP1 with 18f45k22 (solved)
PostPosted: Wed Dec 01, 2010 11:58 am     Reply with quote

Hi,
I am trying to have a simple PWM on CCP1 (PIN_C2) using compiler version 4.114
Code:

setup_oscillator (OSC_64MHZ);
SETUP_ADC_PORTS(sAN0 | sAN1);
SETUP_ADC(ADC_CLOCK_INTERNAL);
SETUP_DAC(DAC_OFF);
setup_comparator(nc_nc_nc_nc);

setup_timer_2(T2_DIV_BY_16, 1023, 16);
setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
set_pwm1_duty (120);

SETUP_WDT(WDT_OFF); //WDT

setup_uart(19200,COM1);
setup_uart(9600,COM2);

set_tris_a(0b00000011); //
set_tris_b(0b11000000); //
set_tris_c(0b10011000); //
set_tris_d(0b00000000); //
set_tris_e(0b00001000); //


All I see is 2.5V at pin_C2.

Thanks in advance!

Michael


Last edited by mdemuth on Thu Dec 02, 2010 6:54 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21370

View user's profile Send private message

PostPosted: Wed Dec 01, 2010 1:04 pm     Reply with quote

I stripped your program down to the minimum necessary code to show
the problem. There is a problem with the setup_timer_2() function in
vs. 4.114 for the 18F45K22. It writes to incorrect registers. This can
be fixed with the work-around macro shown below. The compiler will
substitute the macro code for it's own built-in function. Then it works.

This bug should be emailed to CCS support. Do you want to do it, or
do you want me to do it ?
Code:

#include <18F45K22.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)

#byte T2CON = 0xFBA
#byte PR2 = 0xFBB

#define setup_timer_2(prescaler, PR2val, postscaler) \
if(prescaler)   \
  {             \
   PR2 = PR2val;  \
   T2CON =  prescaler | ((postscaler -1) << 3);  \
  }             \
else            \
  T2CON = 0;

//======================================
void main(void)
{
setup_timer_2(T2_DIV_BY_1, 255, 1);
setup_ccp1(CCP_PWM); 
set_pwm1_duty(120);

while(1);
}
mdemuth



Joined: 16 Apr 2007
Posts: 64
Location: Stuttgart, Germany

View user's profile Send private message Visit poster's website

PostPosted: Thu Dec 02, 2010 2:51 am     Reply with quote

Good work! Laughing
Thanks for your effort!

If you don't mind I will forward the complete topic to the official support.
Best regards,

Michael
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