Single PIC to Blink 5 LEDs Independently?


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Single PIC to Blink 5 LEDs Independently?

    On the 12F683, the CCP1IF bit is PIR1.5.
    Why they have to change things all the time ... I don't know.
    Code:
    CCPIF         VAR PIR1.5
    Both the OSCCON and CMCON0 values don't have enough digits.
    added: CMCON0 won't matter cause it's still 7, but to keep things consistent ...
    Code:
    OSCCON   = %01110000        ' 8Mhz
    CMCON0   = %00000111	    ' Turn off comparators
    Not sure how this got changed, it should be ...
    Code:
    FOR x = 0 to (LEDcount - 1)           ; Load the periods from EEPROM

    Last edited by Darrel Taylor; - 27th March 2014 at 04:47.
    DT

  2. #2
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: Single PIC to Blink 5 LEDs Independently?

    Again, not wholly sure what your trying to do... I have trouble following someone else's code (even my own sometimes), but a PWM output tied to one input of each (yes, 5) "AND" gate, the other input to each I/O. Toggling I/O then controls modulated output. I am thinking of IR communications where a serial data stream and 38K PWM are "ANDed" for IR transmission.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Single PIC to Blink 5 LEDs Independently?

    Quote Originally Posted by Amoque View Post
    Again, not wholly sure what your trying to do... I have trouble following someone else's code (even my own sometimes), but a PWM output tied to one input of each (yes, 5) "AND" gate, the other input to each I/O. Toggling I/O then controls modulated output. I am thinking of IR communications where a serial data stream and 38K PWM are "ANDed" for IR transmission.
    I was initially intending to make the brightness of the LEDs controllable via PWM, but now the chips are moving off the main board to another PCB that will be buried deep within my model where they will only have +5V & GND wires. These boards are too small to add any other components (even SMTs) so I'll just have to breadboard them with various series-limiting resistors to get the right brightness.

    Your suggestion is something I will investigate for the rest of my circuit where I do intend to provide brightness control on the main board. Right now, I'm daisy-chaining 2 NPNs which someone on SparkFun suggested but I haven't breadboarded it yet to see if it works.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Single PIC to Blink 5 LEDs Independently?

    Quote Originally Posted by RossWaddell View Post
    BTW, what software is that you are using to test out the code?
    It's Proteus Design Suite from Labcenter Electronics.

    Quote Originally Posted by RossWaddell View Post
    I was initially intending to make the brightness of the LEDs controllable via PWM, ... so I'll just have to breadboard them with various series-limiting resistors to get the right brightness.
    That can be done in software using MIBAM.
    The blinky's timer will have to be changed, but it's doable.
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Single PIC to Blink 5 LEDs Independently?

    Spent a very happy afternoon reading up on MIBAM - can't wait to try it out (is there a later version of the .pbp code or is the v1.0 you posted on the melbas page the one I should use?).

    In preparation for that, I converted the now-workiing code to use Timer2. I think that since Timer2 is 8-bit (versus 16-bit for Timer1) that I don't need to worry about using the Least Significant register as you did with Timer1 but can just use TMR2:

    Code:
    CCPR1val      CON EXT      : @CCPR1val = (OSC*1000000/4)/ BLINKYFREQ
    ;CCPR1         VAR WORD EXT : @CCPR1 = CCPR1L
    Timer2        VAR WORD EXT : @Timer2 = TMR2
    CCPIF         VAR PIR1.5
    And then this to turn it on:

    Code:
    ;-- setup CCP1 and Start Timer2 --
    CCPR1   = CCPR1val          ; set compare value
    CCP1CON = %00001011         ; compare mode, special event 
    Timer2  = 0                 ; clear Timer2
    T2CON.0 = 1                 ; start Timer2
    Is that it?

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Single PIC to Blink 5 LEDs Independently?

    Or maybe not. The PIC12F683 data sheet seems to indicate that the Compare mode uses only Timer1, and if that's needed for MIBAM then I don't think I can use that on a PIC12F683 with this blinky code.

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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).
    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
    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..
    Here's the latest version.
    Attached Files Attached Files
    DT

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: Single PIC to Blink 5 LEDs Independently?

    Quote Originally Posted by Darrel Taylor View Post
    On the 12F683, the CCP1IF bit is PIR1.5.
    Why they have to change things all the time ... I don't know.
    Code:
    CCPIF         VAR PIR1.5
    Both the OSCCON and CMCON0 values don't have enough digits.
    added: CMCON0 won't matter cause it's still 7, but to keep things consistent ...
    Code:
    OSCCON   = %01110000        ' 8Mhz
    CMCON0   = %00000111	    ' Turn off comparators
    Not sure how this got changed, it should be ...
    Code:
    FOR x = 0 to (LEDcount - 1)           ; Load the periods from EEPROM

    Thank you SOOOO much, Darrel!

    BTW, what software is that you are using to test out the code?

Similar Threads

  1. Single button function
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 40
    Last Post: - 4th April 2020, 18:33
  2. How to blink 8 LEDs at different rates- concurrently?
    By rmteo in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th April 2010, 23:47
  3. single sided PCB
    By schu4647 in forum General
    Replies: 1
    Last Post: - 10th December 2008, 18:22
  4. Can't Blink 2 LEDs
    By dfort in forum mel PIC BASIC
    Replies: 2
    Last Post: - 5th March 2008, 22:36
  5. Tx and Rx of Single Pin PIC's
    By Dwayne in forum Code Examples
    Replies: 0
    Last Post: - 26th May 2004, 14:55

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts