Bit Angle Modulation (BAM) in a PIC


Closed Thread
Results 1 to 40 of 151

Hybrid View

  1. #1
    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; - 26th July 2012 at 23:53.

Similar Threads

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

Members who have read this thread : 3

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