MIBAM and 12F1822...


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Aug 2011
    Posts
    12

    Question MIBAM and 12F1822...

    first off greetings, been a long time lurker here, can't even remember the number of times posts from this forum has saved me, usually when I'm stuck a quick search get's me unstuck with ease... so thank you everyone.

    now for the stuck part...

    I've been using Darryl's awesome MIBAM with a 12F683 for some time, just
    some fading rgb led's etc.. nothing fancy, everything works great...

    enter the 12F1822, was hoping to eventually utilize the hardware EUSART to send rgb color data to each led, since using MIBAM pretty much rules out any software serial communication on the 683. (and not quite sure when the 12F1501 will be available with 4xPWM)

    So before I go any further I wanted to just setup a simple test program to make sure things in general are working..

    here's how the pic is wired up..


    here is my code for basic testing
    Code:
    '****************************************************************
    '     MIBAM TEST pic12F683 / pic12f1822                         *
    '****************************************************************
    
    #IF __PROCESSOR__ = "12F1822"
        #MSG "Compililng for 12F1822..."
        #CONFIG
           __config _CONFIG1, _FOSC_INTOSC & _MCLRE_OFF
           __config _CONFIG2, _PLLEN_OFF & _LVP_OFF
        #ENDCONFIG
        OSCCON = %01110000        '8mhz
        TRISA  = %00011000        'setup inputs/outputs
        ANSELA = %00010000        'RA4 = analog
        CM1CON0 = 0               'disable comarators
        ADCON0 = %00001101        'Select AN3 enable ADC
        ADCON1 = %11010000        'Right Justify - Fosc/16 & 8mhz
    #ELSE
        #if __PROCESSOR__ = "12F683"
            #msg "Compiling for 12F683..."
            #CONFIG
                __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
            #ENDCONFIG
            OSCCON = %01110001       '8mhz
            TRISIO = %00011000       'setup inputs/outputs
            ANSEL  = %01011000       'RA4 = analog
            CMCON0 = %00000111       'disable comarators
            ADCON0 = %10001101       'Right Justify - Fosc/16 & 8mhz
        #else
            #ERROR "Only 12F1822 & 12F683 are supported!"
        #endif
    #ENDIF
    
    DEFINE OSC 8              '8mhz
    DEFINE ADC_BITS 10        '10 bit ADC
    
    DEFINE DEBUG_REG PORTA    
    DEFINE DEBUG_BIT 5
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_MODE 0
    
    ;____[ For 12F/16F only - Interrupt Context save locations]_________________
    wsave       var byte    $20     SYSTEM  ' location for W if in bank0
    ;wsave       var byte    $70     SYSTEM  ' Alternate save location for W 
                                            ' if using $70, comment out wsave1-3
    ' --- IF any of these next three lines cause an error ?? -------------------
    '       Comment them out to fix the problem ----
    ' -- The chip being used determines which variables are needed -------------
    wsave1      VAR BYTE    $A0     SYSTEM      ' location for W if in bank1
    'wsave2      VAR BYTE    $120    SYSTEM      ' location for W if in bank2
    'wsave3      VAR BYTE    $1A0    SYSTEM      ' location for W if in bank3
    '---DO NOT change these-----------------------------------------------------
    ssave       VAR BYTE    BANK0   SYSTEM      ' location for STATUS register
    psave       VAR BYTE    BANK0   SYSTEM      ' location for PCLATH register
    
    ;----[ MIBAM Setup ]--------------------------------------------------------
    BAM_COUNT CON 3                     ; How many BAM Pins are used?
    INCLUDE "MIBAM.pbp"                 ; Mirror Image BAM module
    
    RED  VAR BYTE
    GRN  VAR BYTE
    BLU  VAR BYTE
    adc_val var word                    'adc value variable
    adc_thresh var word                 'adc trigger threshold variable
    
    ASM
    BAM_LIST  macro                     ; Define PIN's to use for BAM
         BAM_PIN (PORTA,0, BLU)         ;   and the associated Duty variables
         BAM_PIN (PORTA,1, RED)
         BAM_PIN (PORTA,2, GRN)
      endm
      BAM_INIT  BAM_LIST                ; Initialize the Pins
    ENDASM
    
    Speed CON 5         'led fade speed   
    adc_thresh = 300    'trigger threshold
    red = 0
    blu = 0
    grn = 0  
    
    T1CON.0 = 0 'disable mibam
    debug "Program Start..",13,10
    pause 2
    T1CON.0 = 1 'enable mibam
    
    'test MIBAM turn on and fade each led 
    FOR red = 255 to 1 STEP -1
        PAUSE Speed
    NEXT red
    red = 0
        
    FOR grn = 255 to 1 STEP -1
        PAUSE Speed
    NEXT grn
    grn = 0
        
    FOR BLU = 255 to 1 STEP -1
        PAUSE Speed
    NEXT BLu
    blu = 0
    
    '------------------------ MAIN PROGRAM LOOP ------------------------
    main:
        gosub do_adc 'get ADC reading
        pause 20
        
        T1CON.0 = 0 'disable mibam
        debug "ADC: ",dec4 adc_val,13,10
        pause 2
        T1CON.0 = 1 'enable mibam
        
        if adc_val > adc_thresh then 
        
            FOR red = 255 to 1 STEP -1
                    PAUSE Speed
            NEXT red
            red = 0
            
            FOR grn = 255 to 1 STEP -1
                    PAUSE Speed
            NEXT grn
            grn = 0
            
            FOR BLU = 255 to 1 STEP -1
                    PAUSE Speed
            NEXT BLu
            blu = 0
            
        endif  
    goto main
    
    '----------------------------------------------------------------------
    
    Do_Adc:
        pauseus 50
        ADCON0.1=1
        WHILE ADCON0.1 : WEND
        adc_val.highbyte = ADRESH
        adc_val.lowbyte = ADRESL
        return

    when compiled for 12F683, everything works fine... the test program does.
    1. debug output --> "Program Start..."
    2. lights up and fades each led r/g/b
    3. debug output ADC reading
    4. waits for ADC threshold to >300 then triggers the light sequence again.

    now when I first compiled for 12F1822 I was greeted with the following error
    Code:
    PICBASIC PRO(TM) Compiler 3.0.0.4, (c) 1998, 2011 microEngineering Labs, Inc.
    All Rights Reserved.
    [MESSAGE] ledtest.pbp(13): Compililng for 12F1822...
    [ASM ERROR] LEDTEST.ASM (451) : Illegal opcode (_CylonMask)
    [ASM WARNING] LEDTEST.ASM (451) : Found label after column 1. (rrcf)
    [ASM ERROR] LEDTEST.ASM (459) : Illegal opcode (_CylonMask)
    [ASM WARNING] LEDTEST.ASM (459) : Found label after column 1. (rlcf)
    [ASM WARNING] LEDTEST.ASM (547) : Extraneous arguments on the line
    not being one to give up so fast... started to track down what is causing the error message... discovered the following in MIBAM.bas.

    Code:
    ;----[ makes rrf work on 18F's ]--------------------------------------------
    ASM nolist
      ifdef BSR
        #define rrf rrcf
        #define rlf rlcf
      endif 
      list ENDASM
    if I comment out the #define's the program does compile successfully however mibam begins to work correctly and then stops working. The following happens.
    1. debug output --> "Program Start..."
    2. lights up and fades each led r/g/b
    3. debug output ADC reading
    4. waits for ADC threshold to >300 *FAILS* to tigger the light sequence.

    basically you can see that the loops are running due to the pause in debug output but the leds now stay off...

    I am assuming that because the 12F1822 is a new part with added features such as automatic context saving etc, I need to do some changes to the MIBAM code, but I really am not sure where to start.. looking to see if anyone has tried using MIBAM on newer pics?

    untill then going to go brush up on my assembly knowledge some and see what trouble I can get myself into changing things...

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: MIBAM and 12F1822...

    OK so the new parts have BSR which were only available on 18Fs before hence why There's quite a fer IFDEF BSR in MIBAM's code. Spot them and change them accordingly. I think it should work after that. Unfortunately I don't have this spêcific PIC on hand to test drive it
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: MIBAM and 12F1822...

    try the one in the attachement.

    Attachment removed.
    The program was completely destroyed by the modifications.
    Last edited by Darrel Taylor; - 29th August 2011 at 03:45.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: MIBAM and 12F1822...

    Another thing... RA4 = AN3, so you need to modify your ANSELA line
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Aug 2011
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: MIBAM and 12F1822...

    Thanks for the help!

    so just tried the modMIBAM code, unfortunatly still getting strange results. different results but still not correct..

    so now the led's do the initial test light up and fade, r/g/b and then when I
    trigger the adc threshold it does work but only the first 1-3 times then the
    led stops working. hmmm must be something else that needs to be modified..

    I was wondering about this section of MIBAM code as well.
    Code:
      ifdef BSR                      ; 18F
        variable ReloadCount   = 5
        variable Latency       = 6
        variable ExitLatency   = 4
      else
        variable ReloadCount   = 7               ; ---- FIX THESE ----
        variable Latency       = 10  ; 16F
        variable ExitLatency   = 10
      endif
    I tried to change the values swapping between the 16f / 18f values as a test, but didn't seem to do anything.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: MIBAM and 12F1822...

    Again... your ANSELA line do not seems good...
    change it to
    ANSELA = %00001000


    and get rid of the DEFINE ADC_BITS 10 line

    Stil not for... replace the ADC reading by a ADC_VAL loop, see what happen.

    IMHO It has to work... or I still miss a crispy detail.
    Last edited by mister_e; - 29th August 2011 at 01:44.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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