* Run on internal oscillator at 4 MHz
* Get rid of the RUNAT32MHz definition
* Adjust PWM for ~ 1 kHz frequency, at Fosc = 4 MHz
* Loop processing <= 12 ms, out of a period of 32 ms
*
*/
-#define RUNAT32MHZ /* else 16 MHz */
-
#include <htc.h>
#include <stdlib.h>
#include "picinit.h"
#include <htc.h>
-#define RUNAT32MHZ /* else 16 MHz */
-
-#if defined(RUNAT32MHZ)
__CONFIG(WDTE_OFF & FOSC_INTOSC);
-__CONFIG(LVP_OFF & PLLEN_ON);
-#else
-__CONFIG(WDTE_OFF);
__CONFIG(LVP_OFF);
-#endif
void pic_init()
{
-#if defined(RUNAT32MHZ)
- OSCCON = 0b11110000;
-#else /* 16 MHz */
- OSCCON = 0b01111010;
-#endif
+ /* Setting below must match _XTAL_FREQ in picinit.h */
+ OSCCON = 0b01101000;
/* OSCSTAT.HFIOFL is set when oscillator is locked (accurate within 2%) */
while (!HFIOFL);
#ifndef _PICINIT_H
#define _PICINIT_H
-#if defined(RUNAT32MHZ)
-#define _XTAL_FREQ 32000000
-#else
-#define _XTAL_FREQ 16000000
-#endif
+#define _XTAL_FREQ 4000000
void pic_init();
{
/* Initialize rgb
* CCP1 on RB3, CCP2 on RA7, CCP3 on RA3, CCP4 on RA4
- * - Fosc = 32MHz
- * - Prescale = 16
+ * - Fosc = 8 MHz, 4 MHz
+ * - Prescale = 4, 4
* - PRx value = 0xff
- * = f(rgb) = 1.95 kHz
+ * = f(rgb) = 1.95 kHz, 0.98 kHz
*/
/* Set rgb Rxn pins as outputs. */
CCPTMRS = 0; /* All CCPx use Timer 2 */
TMR2IF = 0;
PR2 = 0xff;
- T2CON = 0b00000011;
+
+ T2CON = 0b00000001;
}
void rgb_off()