Bit Angle Modulation (BAM) in a PIC


Closed Thread
Results 1 to 40 of 151

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Bit Angle Modulation (BAM) in a PIC

    I notice this is an old thread (Starting in 2009 with the last post in 2011). I downloaded Darrel Taylor's BIBAM ver 1.1 and had it working great with a 16f690.
    I am now trying it on a 18f14k22 and I can't get it working at all. From what I am reading it should work with the 18F's. I am trying to control 9 outputs (3 RGB LEDs). The 16f690 is too slow @8MHz

    Does anyone know if there are any issues using this with the 18f14k22 or if there is an updated BIBAM available?
    I am getting assembly errors when I try to compile: Symbol not previously defines (_VarIn), Missing arguments.

    Jim

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


    Did you find this post helpful? Yes | No

    Default Re: Bit Angle Modulation (BAM) in a PIC

    Hi Jim,

    It should work with the 14K22.

    That error can only be generated by a BAM_PIN statement.

    Make sure it looks something like this ...

    BAM_PIN (PORTB,0, Duty1)

    Note the comma between PORTB and 0.
    Duty1 should be a BYTE var.

    Make sure the designated pins are available.
    The 14K22 only has RA0-RA5, RB4-RB7 and RC0-RC7
    DT

  3. #3
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Bit Angle Modulation (BAM) in a PIC

    Darrel,
    I don't know what I did, but I got it to work. The code was working on the 16f690. The ports are the same on the 18f14k22 so that error should not have been there.

    Anyway, I swiched to the 18f14k22 because I am trying to control 9 ports (3 RGB LEDs) and the Ramps up/down were not smooth at all on the 16f690. I was hoping the speed from 8MHz to 16MHz would fix the problem, but it didn't.

    I just made a copy of the program and removed all the BIBAM code and replaced it with PWM statements (One for each of the 9 ports with a cycle of 1 and no pause). It works smooth and looks good, except the LED's are not quite as bright since they are actally taking turns being on, but they show no visible flicker.

    If I could just get the BIBAM to work as smoothly. I must be doing something wrong. I am controling all 9 LED ports directly from the micro. I did try using transistors, but it made no difference.

    I will keep trying, but I am running out of ideas.

    Jim

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


    Did you find this post helpful? Yes | No

    Default Re: Bit Angle Modulation (BAM) in a PIC

    What does the BAM_INFO report?

    Are you using the Cylon example, or something you wrote?
    DT

  5. #5
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default Re: Bit Angle Modulation (BAM) in a PIC

    Unfortunately varying duty cycle incrementally does not produce linear changes in brightness.

    I use brightness level correction in the form of a "gamma" array which contains a smaller set of duty cycle values, which produce linear changes in brightness, spanning the larger PWM duty cycle range. For example, the C program below for a 12F1822 uses the PWM module for a very smooth fading output with 64 brightness corrected levels using duty cycle values in the 64 element "gamma" array which span the 256 step PWM duty cycle range. Unfortunately, I'm not sure how you would implement something like this in PBP.

    Good luck on your project... Cheerful regards, Mike

    Code:
       #include <system.h>
    
       #pragma DATA _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _MCLRE_ON
       #pragma DATA _CONFIG2, _LVP_OFF & _PLLEN_OFF
    
       #pragma CLOCK_FREQ 8000000   // 8-MHz INTOSC
    
       #define r08 const rom unsigned char
    
    
       r08 gamma[] = {  0,  1,  2,  2,  2,  2,  3,  3,  3,  4,
                        4,  5,  5,  6,  6,  7,  8,  8,  9, 10,
                       11, 12, 13, 14, 15, 17, 18, 20, 21, 23,
                       25, 27, 29, 31, 34, 36, 39, 42, 45, 49,
                       53, 57, 61, 65, 70, 75, 81, 87, 93,100,
                      107,114,123,131,140,150,161,172,183,196,
                      209,224,239,255 };
    
       void main()
       { ansela = 0;                // make pins digital
         trisa = 0b00000000;        // porta all outputs
         porta = 0;                 // all output latches low
         osccon = 0b01110010;       // initialize 8-MHz INTOSC
         while(!oscstat.HFIOFS);    // wait until OSC stable
    
         ccp1con = 0b00001100;      // pwm mode, p1a active hi
         ccpr1l = 0;                // 0% duty cycle initially
         pr2 = 255;                 //
         t2con = 1<<TMR2ON;         // pre 1, post 1, 7812.5 Hz
    
         while(1)                   //
         { static char duty = 32;   // start at ~50% brightness
           while(duty < 63)         // fade up to 100%
           { ccpr1l = gamma[duty++];
             delay_ms(30);          // over period of ~1 sec
           }                        //
    
           while(duty > 32)         // fade down to ~50%
           { ccpr1l = gamma[duty--];
             delay_ms(30);          // over period of ~1 sec
           }                        //
           delay_ms(100);           // pause at 50% brightness
         }                          //
       }


    Here's another example using 64 brightness level steps on a 20 LED Charlieplexed matrix with 8-bit (256 level) BAM modulation. While only one LED is being faded in the video, all twenty LEDs could be faded at the same time.

    Last edited by Mike, K8LH; - 27th July 2012 at 00:53.

  6. #6
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Bit Angle Modulation (BAM) in a PIC

    It is something I am writing. I was assuming that the duty in the BIBAM routine was directly related to the brightness level so that a loop from 0 to 255 should be a smooth increase in brightness. All I am doing right now is fading colors up and down to smoothly blend colors together. I will play with it a bit more next week.
    Thanks,
    Jim

Similar Threads

  1. decoding quadrature encoders
    By ice in forum mel PIC BASIC Pro
    Replies: 93
    Last Post: - 28th February 2017, 10:02
  2. Cordic trig assembly code for PIC18f
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 54
    Last Post: - 8th September 2015, 06:36
  3. AT/PS2 Keybord - PIC Interface?
    By Kamikaze47 in forum Code Examples
    Replies: 73
    Last Post: - 9th August 2009, 17:10
  4. MIBAM - (Mirror Imaged Bit Angle Modulation)
    By Darrel Taylor in forum Code Examples
    Replies: 2
    Last Post: - 15th February 2009, 17:02
  5. Bit Angle Modulation
    By BH_epuk in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th November 2008, 08:01

Members who have read this thread : 2

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