|
|
View previous topic :: View next topic |
Author |
Message |
mdemuth
Joined: 16 Apr 2007 Posts: 71 Location: Stuttgart, Germany
|
Simple PWM on CCP1 with 18f45k22 (solved) |
Posted: Wed Dec 01, 2010 11:58 am |
|
|
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: 21708
|
|
Posted: Wed Dec 01, 2010 1:04 pm |
|
|
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: 71 Location: Stuttgart, Germany
|
|
Posted: Thu Dec 02, 2010 2:51 am |
|
|
Good work!
Thanks for your effort!
If you don't mind I will forward the complete topic to the official support.
Best regards,
Michael |
|
|
|
|
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
|