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

PWM on a PIC16F1575

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



Joined: 19 Dec 2014
Posts: 23

View user's profile Send private message

PWM on a PIC16F1575
PostPosted: Fri Dec 20, 2019 3:47 am     Reply with quote

Hi all,
I am trying to control various LEDs via PWM using a PIC16F1575.
I tried the CCS examples for PWM but the function used in it is not defined in this device. So I had a look at the 16f1575.h file and tried to figure it out. But so far no pulses showing.
I did run a basic blinking LED test to make sure the board is alive, all works well...
I am using CCS compiler Version 5.090.
Thanks for any help... See code attached below...

Code:

/****************************************************************************************/
/*   Pre Processor Commands                                                             */
/****************************************************************************************/
#INCLUDE "16f1575.h"
#DEVICE ADC = 10
#FUSES INTRC_IO,NOPROTECT,NOBROWNOUT,PLL,MCLR

#PIN_SELECT PWM1OUT = PIN_C0
#PIN_SELECT PWM2OUT = PIN_C1
#PIN_SELECT PWM3OUT = PIN_C2
#PIN_SELECT PWM4OUT = PIN_C3

#DEFINE DEBUG_LED   PIN_A4

#USE delay(clock=32MHz)

/****************************************************************************************/
/*   Global Variables / constants                                                       */
/****************************************************************************************/
int1 PIC_ready = FALSE;

/****************************************************************************************/
/*   Function Prototypes                                                   */
/****************************************************************************************/
void init_PIC(void);


/****************************************************************************************/
/*   Main Loop...                                                                       */
/****************************************************************************************/
void main ()
{
   init_PIC();
   
   while (TRUE)
   {

   }
}

/****************************************************************************************/
/*      PIC setup                                                                       */
/****************************************************************************************/
void init_PIC()
{
   setup_adc(ADC_OFF);

   set_pwm1_duty(100L);
   set_pwm1_period(50L);
   set_pwm2_duty(500L);
   set_pwm2_period(200L);
   set_pwm3_duty(800L);
   set_pwm3_period(1000L);
   set_pwm4_duty(500L);
   set_pwm4_period(5000L);
   
   setup_pwm1(PWM_ENABLE);
   setup_pwm2(PWM_ENABLE);
   setup_pwm3(PWM_ENABLE);
   setup_pwm4(PWM_ENABLE);
   
   output_low(DEBUG_LED);      // GTurn ON Debug LED
   
   PIC_ready = TRUE;
}

/****************************************************************************************/
/*                                    END                                               */
/****************************************************************************************/
Ttelmah



Joined: 11 Mar 2010
Posts: 19326

View user's profile Send private message

PostPosted: Fri Dec 20, 2019 5:45 am     Reply with quote

Your setup_pwm lines need quite a lot more parameters:

setup_pwm1(PWM_ENABLE | PWM_STANDARD | PWM_CLK_DIV_BY_1 |
PWM_CLK_FOSC);

Currently you are not setting up the clock for the PWM....
The default for the clock selection will almost certainly be '11', which is
'reserved' and probably will not generate any clock.

Then you can't set 'period' less than 'duty'. Doing so will disable the PWM.
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