Allegro A6280 with PICBASIC


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    Join Date
    Aug 2007
    Posts
    10

    Default shiftout doesn't run as expected

    Dear Darrel, sorry for the trouble again, below is the code that I'm trying to work with but it doesn't light up the led as expected. Please kindly advise. Thanks in advance.

    @ DEVICE HS_OSC
    DEFINE OSC 4
    include "bs1defs.bas"

    CMCON = 7 ' PortA = digital I/O
    VRCON = 0 ' A/D Voltage reference disabled
    TRISB = %00000000 ' B.3=PWM,B.0,B.1,B.2 blink LEDs
    PR2 = 25 ' Set PWM for approximately 38KHz
    CCPR1L = 13 ' Set PWM Duty-Cycle to 50%
    CCP1CON = %00001100 ' Mode select = PWM
    T2CON = %00000100 ' Timer2 ON + 1:1 prescale

    d2pin var portb.0
    c2pin var portb.3
    latch var portb.4
    'oe var portb.1


    funct var byte
    rvar var word
    gvar var word
    bvar var word

    funct = 0
    gvar = %0011111111
    rvar = %0000000000
    bvar = %0000000000

    begin:
    high porta.0
    pause 1000
    low porta.0

    CCPR1L = 0
    shiftout d2pin, c2pin, 1, [funct\1,gvar\10,rvar\10,bvar\10]
    gosub latching

    pause 1000
    gosub bringpwm


    goto begin




    bringpwm:
    PR2 = 25 ' Set PWM for approximately 38KHz
    CCPR1L = 13 ' Set PWM Duty-Cycle to 50%
    CCP1CON = %00001100 ' Mode select = PWM
    T2CON = %00000100 ' Timer2 ON + 1:1 prescale
    return

    latching:
    high latch
    pause 500

    low latch
    return

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

    Default

    Putting 0 in CCPR1L just stops the output with a 0% duty cycle. The pin is still controlled by the CCP module.

    CCP1CON = 0   Will allow SHIFTOUT to use the PIN.

    And for 100Khz, use PR2 = 9 and CCPR1L = 5.

    DT

  3. #3
    Join Date
    Aug 2007
    Posts
    10

    Default Thanks Darrel........

    Dear Darrel,

    Thanks to you. The code running well now. I can turn the color from Red to green and to blue. You are really good. Thanks again. But now, the story continue...... I need to know how to use the Dot Correction because I don't really understand the concept. Besides that, Do I really need to use the Dot Correction? Please kindly advise.

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

    Default

    Great! Glad you got it working.

    Besides that, Do I really need to use the Dot Correction?
    I guess you don't "really need" to use them. You could just set the current with the REXT resistor, and use the PWM like normal. But if you want to match the brightness of the 3 LED's, then you'll need to set the DOT correction registers.

    They Power-up at 36% of the REXT current setting.
    So be sure you don't have too much current set-up before trying this. I don't want to blow up your LED's.
    But this should set the DOT registers to full current.
    Code:
    Rdot VAR BYTE
    Gdot VAR BYTE
    Bdot VAR BYTE
    Zeros VAR BYTE : Zeros = 0
    
    Rdot = 127  ; Set these to match LED brightness (max 127)
    Gdot = 127
    Bdot = 127
    
    SetDots:
        funct = 1
        CCP1CON = 0
        shiftout d2pin, c2pin, 1, [funct\1,Zeros\3,Gdot\7,Zeros\3, _
                                   Rdot\7,Zeros\3,Bdot\7]
        high latch
        @ NOP
        low latch
        CCP1CON = %00001100
        funct = 0
    RETURN
    Then just GOSUB SetDots

    HTH,
    DT

  5. #5
    Join Date
    Aug 2007
    Posts
    10

    Red face

    Dear Darrel, thanks for the code so I think maybe you're right. The dot correction might not playing a necessary character in here. I still have a question if you don't mind, I'm trying to dim the led by decreasing the value of bvar (let say from 1023 to 0) but no luck. May I know why? Besides that, do u have a complete set of code for this IC's controller for sale? Hope you have a good day.

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

    Default

    I don't know why it wouldn't, except maybe for the PAUSEs.
    The last code posted would take over 42 minutes to dim from 1023 to 0 with the included pauses.

    Can you post your code again the way it is now?

    DT

  7. #7
    Join Date
    Aug 2007
    Posts
    10

    Red face

    BVar = 1023

    blue:
    shiftout d2pin, c2pin,1 [funct\1,Rvar\10,Gvar\10,Bvar\10]
    gosub latch
    gosub BringUpPWM
    pause 100
    Bvar = Bvar - 2
    if bvar < 3 then goto end
    gosub blue

    end

    I was expecting gradual dimming of the LED, but it pulsates and intensity seems the same.

Similar Threads

  1. Picbasic VS C Compiler
    By koossa in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 11th October 2005, 22:44
  2. Replies: 22
    Last Post: - 12th July 2005, 18:39
  3. 1st 16F877A program in PICBasic
    By Borisw37 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th January 2005, 05:46
  4. PicBasic Fundamentals
    By Billyc in forum General
    Replies: 9
    Last Post: - 4th May 2004, 11:04
  5. PicBasic Pro & PicBasic syntax different
    By Billyc in forum General
    Replies: 5
    Last Post: - 16th April 2004, 22:19

Members who have read this thread : 0

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