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 CCS Technical Support

Problem With Multiple PWM Outputs (PIC18F66K22)

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



Joined: 30 Dec 2011
Posts: 55

View user's profile Send private message

Problem With Multiple PWM Outputs (PIC18F66K22)
PostPosted: Mon Jan 23, 2012 12:26 pm     Reply with quote

Hello all,

I'm having a little trouble getting all 10 of the available PWM outputs to work on a PIC18F66K22. I've programmed each of the PWM's for a duty cycle ranging from 10% to 100% which corresponds to the PWM channel. This allows me to use my scope to find out which pin a particular PWM shows up on. I also enabled Timers 2, 4, 6, & 8 just to make sure I had a timer associated for each PWM. I'm using the 64 pin TQFP package.

Here's a list of the PWM's that have been verified on the scope:

PWM1 - Pin 33, ECCP1 (not working)
PWM2 - Pin 59, ECCP2 (only when CCP2B3 fuse is set)
PWM3 - Pin 3, ECCP3
PWM4 - Pin 6, CCP4
PWM5 - Pin 8, CCP5
PWM6 - Pin 60, CCP6
PWM7 - Pin 61, CCP7 (not working)
PWM8 - Pin 62, CCP8
PWM9 - Pin 63, CCP9 (not working)
PWM10 - Pin 64, CCP10

So there are three PWMs (1,7,9) that don't work at all. I wrote come code to toggle each of these pins (with PWM disabled) and all but RC1 (pin 29) toggled correctly. RC1 appears to be setup as an input even though I have Port C set to all outputs. I did find a reference to RC1 being shared with another module, but can't seem to set it to an output. Also, when I set the fuse 'CCP2C1', the CCP2 PWM does not appear at RC1.

Thanks in advance for any help.


Here's a snipit of the code. Only the pertinent lines are shown:

Code:

#include <18F66K22.h>
#fuses NOWDT,PROTECT,BROWNOUT,PUT,NODEBUG,NOCPD,CPB,NOMCLR

//#fuses CCP2C1  //selects Pin C1 for CCP2
#fuses CCP2B3  //selects Pin B3 for CCP2

#device *=16
#device HIGH_INTS=TRUE
#device ADC=12

#

#use delay(clock=8000000)   //8 MHz osc

void main()
{   

setup_oscillator(OSC_8MHZ);  // Fosc = 8 MHz

setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(sAN0|VSS_VDD);

set_tris_a(0x01);
set_tris_b(0xff);   
set_tris_c(0x00);   
set_tris_d(0x00);
set_tris_e(0x00);
set_tris_f(0x00);
set_tris_g(0x00);
   
PORTA = 0x01;
PORTB = 0xff;
PORTC = 0;
PORTD = 0;
PORTE = 0;
PORTF = 0;
PORTG = 0;

port_b_pullups (true);

setup_timer_2(T2_DIV_BY_1, 100, 1); // 19.8 kHz
setup_timer_4(T4_DIV_BY_1, 100, 1);
setup_timer_6(T6_DIV_BY_1, 100, 1);
setup_timer_8(T8_DIV_BY_1, 100, 1);

enable_interrupts(INT_TIMER2);
enable_interrupts(INT_TIMER4);
enable_interrupts(INT_TIMER6);
enable_interrupts(INT_TIMER8);
enable_interrupts(GLOBAL);

setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_ccp3(CCP_PWM);
setup_ccp4(CCP_PWM);
setup_ccp5(CCP_PWM);
setup_ccp6(CCP_PWM);
setup_ccp7(CCP_PWM);
setup_ccp8(CCP_PWM);
setup_ccp9(CCP_PWM);
setup_ccp10(CCP_PWM);

set_pwm1_duty(10);
set_pwm2_duty(20);
set_pwm3_duty(30);
set_pwm4_duty(40);
set_pwm5_duty(50);
set_pwm6_duty(60);
set_pwm7_duty(70);
set_pwm8_duty(80);
set_pwm9_duty(90);
set_pwm10_duty(100);

for (;;);

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon Jan 23, 2012 3:39 pm     Reply with quote

The obvious thing on RC1, is the timer1 oscillator input.
Have you tried configuring timer1, and specifying that it should use the Fosc/4 source?. I'd suggest it is defaulting to using an external source, and this is overriding RC1. If you look at table 12-5, this setting overrides the port pin, whatever TRIS is set to....
Can't see anything obvious on CCP7/9. The way to approach this is to extract the listing snippet setting these up, and verify it is addressing the right registers.

Best Wishes
n-squared



Joined: 03 Oct 2006
Posts: 99

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Jan 25, 2012 11:31 am     Reply with quote

The following code is from a product of mine that runs on PIC18F67K22 and uses PWM 1 through 9:
Code:


void init_system(void)
  {
  output_a(0);
  output_b(0);
  output_c(0);
  output_d(0);
  output_e(0);
  output_f(0);
  output_g(0);
  set_tris_a(0b00000000);
  set_tris_b(0b11001111);
  set_tris_c(0b11011000);
  set_tris_d(0b00000000);
  set_tris_e(0b00000000);
  set_tris_f(0b00000000);
  set_tris_g(0b11100110);

  setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8|RTCC_8_bit);    //1.0 ms overflow
  setup_timer_1(T1_INTERNAL|T3_DIV_BY_4);
  setup_timer_2(T2_DIV_BY_16,255,1);  //512 us overflow, 512 us interrupt
  setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
  setup_timer_4(T4_DIV_BY_16,100,5);

  setup_ccp1(CCP_PWM); set_pwm1_duty(100);
  setup_ccp2(CCP_PWM); set_pwm2_duty(100);
  setup_ccp3(CCP_PWM); set_pwm3_duty(100);
  setup_ccp4(CCP_PWM); set_pwm4_duty(100);
  setup_ccp5(CCP_PWM); set_pwm5_duty(100);
  setup_ccp6(CCP_PWM); set_pwm6_duty(100);
  setup_ccp7(CCP_PWM); set_pwm7_duty(100);
  setup_ccp8(CCP_PWM); set_pwm8_duty(100);
  setup_ccp9(CCP_PWM); set_pwm9_duty(100);
  }



Timer 2 is the default timer for PWM's.
I have a CCP2B3 fuse in the header.
Notice that timer1 is defined as T1_INTERNAL.

Hope this helps.
BR
NN
_________________
Every solution has a problem.
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