View previous topic :: View next topic |
Author |
Message |
RNR107
Joined: 19 Dec 2014 Posts: 23
|
PWM on a PIC16F1575 |
Posted: Fri Dec 20, 2019 3:47 am |
|
|
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: 19766
|
|
Posted: Fri Dec 20, 2019 5:45 am |
|
|
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. |
|
 |
|