Hello,
I am trying to get the hardware pwm on the 16F88 to work. I currently have it hooked up to an LED, but I am having no luck with the voltage changing. I am basing my code of this tutorial here and have modified it to work with the 16F88.
From looking at the code it should have the LED be at two different brightnesses then shut off and then repeat. However right now all it does is turn on and stay on. Could someone please show me where I am going wrong?
I am using MPLABX and XC8.
I am trying to get the hardware pwm on the 16F88 to work. I currently have it hooked up to an LED, but I am having no luck with the voltage changing. I am basing my code of this tutorial here and have modified it to work with the 16F88.
From looking at the code it should have the LED be at two different brightnesses then shut off and then repeat. However right now all it does is turn on and stay on. Could someone please show me where I am going wrong?
I am using MPLABX and XC8.
Rich (BB code):
#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 100000//Declare internal OSC Freq as 1MHz
#include <xc.h>
#include<pic.h>
__CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_OFF & MCLRE_ON & BOREN_OFF & LVP_OFF & CPD_OFF & WRT_OFF & CCPMX_RB0 & CP_OFF);
__CONFIG(FCMEN_ON & IESO_ON);
main()
{
TRISA=0;
OSCCON=01111110;
CCP1CON = 0b00001100; // Enable PWM on CCP1
TRISB = 0; //
T2CON = 0b00000100; // Enable TMR2 with prescaler = 1
PR2 = 249; // PWM period = (PR2+1) * prescaler * Tcy = 1ms
CCPR1L = 25; // pulse width = CCPR1L * prescaler * Tcy = 100us
while(1)
{
//Shows Chip has been programed
PORTAbits.RA0=1;
__delay_ms(1000);
PORTAbits.RA0=0;
// 50% duty cycle for 500ms
CCPR1L =125 ;
__delay_ms(1000);
// 10% duty cycle for 500ms
CCPR1L = 25;
__delay_ms(1000);
// 0% duty cycle for 500ms
CCPR1L = 0;
__delay_ms(1000);
}
}