One little obstacle and ... it can't be done???
The CCP with Capture mode was just a simple way to get a wide range of constant periods without interrupts/reloading timers etc.
Since it seems that you are only using the original 10mS periods, it doesn't really need that "Wide Range".
10mS periods can be generated with another Timer, and you don't need the CCP module.
In this example, I'm using Timer0 ...
MIBAM uses Timer1.
The EEPROM data labeled Brightness controls the intensity of each LED.
I have 3 LED's with 330 ohms, and 2 LED's with 100 ohms. The existing values equalized their brightness (to my eyes).
And yes, I posted a MIBAM version 1.1 several years ago ... but it seems to be gone, or I just can't find it..Code:;{PIC=12F683} #CONFIG __config _INTOSCIO & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_ON & _IESO_OFF & _FCMEN_OFF #ENDCONFIG DEFINE OSC 8 OSCCON = %01110000 ; 8MHz internal osc ANSEL = 0 ; All Digital CMCON0 = 7 OPTION_REG = %00000110 ; Timer0 prescaler 1:128 TMR0IF VAR INTCON.2 ; Timer0 Overflow bit TRISIO = 0 ; all OUTPUT ;----[ MIBAM Setup ]-------------------------------------------------------- wsave var byte $70 SYSTEM ' Alternate save location for W ssave VAR BYTE BANK0 SYSTEM ' location for STATUS register psave VAR BYTE BANK0 SYSTEM ' location for PCLATH register BAM_COUNT CON 5 ; How many BAM Pins are used? ;DEFINE BAM_INFO 1 INCLUDE "MIBAM.pbp" ; Mirror Image BAM module Bright VAR BYTE[BAM_COUNT] Br0 VAR Bright[0] Br1 VAR Bright[1] Br2 VAR Bright[2] Br4 VAR Bright[3] Br5 VAR Bright[4] ASM BAM_LIST macro ; Define PIN's to use for BAM BAM_PIN (GPIO,0, Br0) ; and the associated Duty variables BAM_PIN (GPIO,1, Br1) BAM_PIN (GPIO,2, Br2) BAM_PIN (GPIO,4, Br4) BAM_PIN (GPIO,5, Br5) endm BAM_INIT BAM_LIST ; Initialize the Pins ENDASM ;----[Setup Blinky parameters]----------------------------------- DEFINE BLINKYFREQ 100 ; 10mS periods LEDcount CON 5 ; Number of LEDs on the PORT OnTimes DATA 50, 22, 38,75, 5 ; default periods for each Output OffTimes DATA 150, 45, 38,95,34 Brightness DATA 150,150,150,80,80 #DEFINE USE_RANDOM_SEQUENCE ; comment for contiuous Sequence #IFDEF USE_RANDOM_SEQUENCE RND VAR WORD : RND = 13864 MIN_ON CON 50 ; Minimum random ON time MAX_ON CON 500 ; Maximum random ON time MIN_OFF CON 50 ; Minimum random OFF time MAX_OFF CON 500 ; Maximum random OFF time RandPeriod VAR WORD[LEDcount] RandPeriods DATA WORD 1000, WORD 1250, WORD 1500, WORD 1750, WORD 2000 #ENDIF ;----[Variables used only by Blinky]----------------------------- LoopLED VAR WORD[LEDcount] OnTime VAR WORD[LEDcount] OffTime VAR WORD[LEDcount] x VAR BYTE ;----[Initialize]------------------------------------------------ FOR x = 0 to LEDcount - 1 ; load the periods from EEPROM READ OnTimes+x, OnTime(x) READ OffTimes+x, OffTime(x) #IFDEF USE_RANDOM_SEQUENCE READ RandPeriods+(x<<1), WORD RandPeriod(x) #ENDIF NEXT X ;----[Main Program Loop]---------------------------------------- Main: x = (x + 1) // LEDcount IF LoopLED(x) < OnTime(x) THEN READ Brightness + x, Bright(x) ELSE Bright(x) = 0 ENDIF LoopLED(x) = (LoopLED(x) + 1) // (OnTime(x) + OffTime(x)) #IFDEF USE_RANDOM_SEQUENCE RandPeriod(x) = RandPeriod(x) - 1 IF RandPeriod(x) = 0 THEN READ RandPeriods+(x<<1), WORD RandPeriod(x) RANDOM RND OnTime(x) = (MAX_ON - MIN_ON)* RND.HighByte / 255 + MIN_ON OffTime(x)= (MAX_OFF - MIN_OFF)* RND.LowByte / 255 + MIN_OFF ENDIF #ENDIF IF x != (LEDcount - 1) THEN Main Waiting: IF !TMR0IF THEN Waiting TMR0 = 99 TMR0IF = 0 GOTO Main
Here's the latest version.





Bookmarks