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

PIC 18f2331 PCPWM

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



Joined: 25 Jan 2015
Posts: 1

View user's profile Send private message

PIC 18f2331 PCPWM
PostPosted: Sun Jan 25, 2015 2:34 pm     Reply with quote

Hi,

I've been struggling with this for a while now. As far as I can tell I have everything set up correctly (registers etc.) But for some reason it still isn't working and I'm just wondering if I've missed something.

When I run the code in a simulator all the registers I configure are set up correctly but the PTMR register just stays at 0. I thought this was supposed to increment from the internal clock (PTMR clock?)?

Do I need to use an external oscillator or configure a specific timer, or have I just missed something in my code (apologies for the lack of comments)?


Code:

#include <stdio.h>
#include <stdlib.h>
#include <htc.h>
#include <delays.h>

void init();

void init()
{
   //PORT Initialization
   TRISB = 0x00;

   //PWM Module Initialization

   PTCON0 = 0x00;
   PTCON1bits.PTEN = 1;
   PTCON1bits.PTDIR = 0;

   PWMCON0 = 0x57;
   PWMCON1 = 0x01;

   PTPERL = 0x05;
   PTPERH = 0x00;

   DTCON = 0x00;
   
   OVDCOND = 0x2A;
   OVDCONS = 0x00;
   FLTCONFIG = 0xB3;

   SEVTCMPL = 0x00;
   SEVTCMPH = 0x00;

   PDC0L = 0x00;
   PDC0H = 0x00;
}

void main()
{
   init();
   int x;

   while(1)
   {
      //infinate loop

      for(x=0; x<20; x++)
      {
         PDC0L = x;
         PDC0H = 0x00;
         
         Delay100TCYx(5);
      }
   }
}


Thank you for any help you can give me
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 25, 2015 2:44 pm     Reply with quote

This is Hi-tech code but you're on the CCS forum.
CCS had functions to do this. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=37206&start=2
But in Hi-tech you have do it with registers (or write your own functions).
If you want to stay with Hi-tech, they have a forum (use google to find it).
Also Microchip has a Hi-tech forum.
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