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

Another PWM question, this one with PPS on 18F24J11

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



Joined: 26 Aug 2009
Posts: 6

View user's profile Send private message

Another PWM question, this one with PPS on 18F24J11
PostPosted: Tue Sep 08, 2009 10:09 pm     Reply with quote

I'm attempting to get the PMW1 module on an 18F24J11 functioning to control an LED on RA0. I believe I have correctly configured PPS as the PPSCON register sets correctly in PICSIM (#pin_select doesn't appear to be implemented in PCH 4.088 for this pic so I went the ASM route). I cannot get any output on RA0, voltage or LED changes or otherwise (the LED takes a Fw supply of 1.5V, 2.4V max, pic Vdd=3.3v).

The 18F24J11 is running at 4mhz and my math says that TMR2 is configured for PWM1 to have a period of 3.90625 kHz (setup_timer_2(T2_DIV_BY_1,0xFF,1) ). The datasheet is very straightforward for this pic (not using the enhanced PWM mode reduces it to a total of a page and a half for vanilla PWM). My calculations show that TMR2 has a period of 256ms, and the maximum 10-bit duty cycle I could assign (0x3FF) should produce 255.75ms cycle. I've had all manners of calls to set_pwm1_duty() incrementing from 0x00 through 0xFF (8-bit) as well as 0x00 to 0x3FF (10-bit) with no detectable results. This has been done with various delays ranging from letting it increment at Fosc to a 500ms delay between increments. The code below is the 8-bit flavor; I don't really care if it works at 8-bit or 10-bit at this point.

The final state state I'm working toward is this PWM module driving a MOSFET controlling a 12V system (fans and whatnot, but PWM2 will control LEDs). This is my first time attempting to use PWM and there appears to be something fundamental that I've left out.

Any ideas?

Code:

#include <18F24J11.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, NOFCMEN, NODEBUG
#include "humidor_common.h" // Contains i2c addresses, some other shared globals
#use delay(clock=4000000)
#use i2c(MASTER, SCL=PIN_C3, SDA=PIN_C4, FORCE_HW, RESTART_WDT, SLOW)
#zero_ram

[...additional globals and some defines/includes omitted...]

#define EECON2  0xFA7
#define PPSCON  0xEFF
#define RPOR0   0xEC6
#define RPOR1   0xEC7
#define P1A      0x0E      
#define P2A      0x12
#define IOLOCK  0

volatile unsigned INT8     duty=0;

void main(void)
{

   // Set up PPS
   #asm
   MOVLB 0x0E            // Bank 14
   MOVLW 0x55            // 1st unlock code into W
   MOVWF EECON2         // 1st unlock code from W to EECON2
   MOVLW 0xAA            // 2nd unlock code into W
   MOVWF EECON2         // 2nd unlock code from W into EECON2
   BCF   PPSCON, IOLOCK   // Clear IOLOCK of PPSCON, unlocking PPS
   
   MOVLW P1A            // Set P1A select in W
   MOVWF RPOR0            // Move W into RPOR0
   MOVLW P2A            // Set P1A select in W
   MOVWF RPOR1            // Move W into RPOR0
   
   MOVLW 0x55            // 1st lock code into W
   MOVWF EECON2         // 1st lock code from W to EECON2
   MOVLW 0xAA            // 2nd lock code into W
   MOVWF EECON2         // 2nd lock code from W into EECON2
   BSF   PPSCON, IOLOCK   // Set IOLOCK of PPSCON, locking PPS
   #endasm//*/

   delay_ms(100); // power up delay

   setup_timer_2(T2_DIV_BY_1,0xFF,1);
   setup_ccp1(CCP_PWM);

   setup_timer_4(T4_DIV_BY_4,0xF9,8);
   enable_interrupts(INT_TIMER4);
   enable_interrupts(GLOBAL);

   [... some i2c and housekeeping omitted ...]

   while(1)
   {
      duty++;
      if(duty==0xFF) duty=0;
      set_pwm1_duty(duty);

      [... more i2c and whatnot ...]
      [... plenty of time burnt in here, about 230ms on average...]

   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 09, 2009 12:48 pm     Reply with quote

Quote:

enable_interrupts(INT_TIMER4);
enable_interrupts(GLOBAL);

You don't have an isr for #int_timer4. This means that when a Timer4
interrupt occurs, the PIC will jump to the interrupt vector location, but
there won't be any legitimate code there and the program will crash.

The compiler has a #pin_select directive. Why aren't you using it ?
Is it because your compiler version doesn't supportt ? What is your
compiler version ?


Your test program is too complicated. Re-write it so it's a lot more simple.
See this example. This program is setting up two PWM channels. Your
program only needs to setup 1 channel. It could be even more simple
than this program. This is all you need for the initial testing:
http://www.ccsinfo.com/forum/viewtopic.php?t=39786&start=1
Cut out everything that isn't needed for testing PWM, such as the #use i2c
statement.
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Sep 09, 2009 11:22 pm     Reply with quote

the 18FxxJ11's should work fine with #pin_select now..

I'm using it on one project... however, I would still check the code... and not be surprised by a discrepancy.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
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