]> oss.titaniummirror.com Git - rgblamp.git/commitdiff
Run at Fosc = 4MHz
authorR. Steve McKown <rsmckown@gmail.com>
Tue, 6 Dec 2011 18:36:13 +0000 (11:36 -0700)
committerR. Steve McKown <rsmckown@gmail.com>
Tue, 6 Dec 2011 18:36:13 +0000 (11:36 -0700)
* 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

main.c
picinit.c
picinit.h
rgb.c

diff --git a/main.c b/main.c
index ec3d4257dfc10595522972e879e35f2ca4c7656d..e00cdbc49a8bb096143bf59d49912a381fdd14b9 100644 (file)
--- a/main.c
+++ b/main.c
@@ -25,8 +25,6 @@
  *
  */
 
-#define RUNAT32MHZ /* else 16 MHz */
-
 #include <htc.h>
 #include <stdlib.h>
 #include "picinit.h"
index 40843b203b5f752faedb9b1a5dcfd4655036bcac..4274e2a43e9dc752554cc7e97479000f850fef8f 100644 (file)
--- a/picinit.c
+++ b/picinit.c
@@ -7,23 +7,13 @@
 
 #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);
index c349b9cc72f8ddb487ad90601781965c0fe72279..e2a50cfde7b851f3ddfaed2cd177837aa24da19d 100644 (file)
--- a/picinit.h
+++ b/picinit.h
@@ -7,11 +7,7 @@
 #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();
 
diff --git a/rgb.c b/rgb.c
index 5fb2849a26988cb0299f4e836d7d34728870fb2c..43fec9ef21aae0071e75ccca3f461eac13e8424f 100644 (file)
--- a/rgb.c
+++ b/rgb.c
@@ -13,10 +13,10 @@ void rgb_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. */
@@ -46,7 +46,8 @@ void rgb_init()
     CCPTMRS = 0; /* All CCPx use Timer 2 */
     TMR2IF = 0;
     PR2 = 0xff;
-    T2CON = 0b00000011;
+
+    T2CON = 0b00000001;
 }
 
 void rgb_off()