Bit Angle Modulation (BAM) in a PIC


Closed Thread
Results 1 to 40 of 151

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    What's the processor utilization per MHz per LED?
    Utilization is less than 6% of total.

    The limiting factor is the Least Significant Bit in the dutycycle. It's so short that it doesn't give much time to do anything. The mirror image helped some, because I was able to combine the LSB of both halves of the mirror for a longer period, but it's still only 68 instructions (worst case).

    It has to get into the interrupt handler, save context, reload the Timer, service all the LEDs dutycycles, keep track of the bit sequencing, restore context and exit the interrupt within those 68 instructions.

    Each PIN uses 6 instructions, and the rest of the handler uses about 40.
    So @ 4 mhz you can only get 4 LED's (40 + 24 = 64).
    Refresh rate @ 4mhz = 80 hz with 4 LEDs.

    With higher OSC freqs, refresh rates can be as high as 650hz, depends on how many LEDs there are.
    The rate can be set lower with a DEFINE if needed.

    Warnings from the assembler will indicate if your setup is out of range.
    <br>
    Last edited by Darrel Taylor; - 13th February 2009 at 13:28. Reason: Change to less than 6%, forgot the othe half of the cycle.
    DT

  2. #2
    Join Date
    Nov 2004
    Posts
    61


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Utilization is less than 3% of total.

    The limiting factor is the Least Significant Bit in the dutycycle. It's so short that it doesn't give much time to do anything. The mirror image helped some, because I was able to combine the LSB of both halves of the mirror, for a longer period, but it's still only 68 instructions (worst case).

    It has to get into the interrupt handler, save context, reload the Timer, service all the LEDs dutycycles, keep track of the bit sequencing, restore context and exit the interrupt within those 68 instructions.

    Each PIN uses 6 instructions, and the rest of the handler uses about 40.
    So @ 4 mhz you can only get 4 LED's (40 + 24 = 64).
    Refresh rate @ 4mhz = 80 hz with 4 LEDs.

    With higher OSC freqs, refresh rates can be as high as 650hz, depends on how many LEDs there are.
    The rate can be set lower with a DEFINE if needed.

    Warnings from the assembler will indicate if your setup is out of range.
    <br>

    How flickery is 80 Hz x 4 @ 4 MHz?

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


    Did you find this post helpful? Yes | No

    Default

    How flickery is 80 Hz x 4 @ 4 MHz?
    Even though it's 80hz, the ducycycle is put out to the pin twice, so it's visually better than 80hz PWM would be.

    I don't notice any flicker.
    <br>
    DT

  4. #4
    Join Date
    Sep 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Bam sounds great. Does anybody have a sample code? Thank you in advance.
    Last edited by PicLearner; - 26th January 2009 at 07:39.

  5. #5
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    I played with a very simple form of BAM a while back, with at least 24 LEDs on a 20MHz 16F877A. This is the main loop:

    Code:
         BAM:                        'each pass is one cycle, equiv to one PWM period
    delay_index=%00000001
    for i=0 to 7                        'time slots, 0 shortest, 7 longest
        PORTA.1=LED1>>i               
        PORTA.2=LED2>>i          
        PORTA.3=LED3>>i 
        .
        .
        .
        PORTA.n=LEDn>>1
        for j=1 to delay_index      'empty delay loop for each time slot, total 255
        next j
        delay_index=delay_index<<1
    next i  
    GOTO BAM

    where LED1, LED2 are intensity values that are updated when needed by interrupt. Refresh is totally dependent on clock speed and number of LEDs driven, but 100Hz is achievable.

    I came across a scheme to reorder bits to avoid phase shift glitches but didn't get that far myself. See http://www.tenmilesquare.com/library

    I'd love to see Darrel's code...

    Gary

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


    Did you find this post helpful? Yes | No

    Default

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3157&stc=1&d=123328553 8" />

    Had that come up first, I woud have tried it. Looks interesting.

    But the mirror image seems to work great, so no reason to change horses just yet.

    There's 3 of our regular members looking at it now.
    I like knowing they can set CONFIGs and disable A/D on their own.

    Barring any problems, I'll post it soon.
    <br>
    Attached Images Attached Images  
    DT

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


    Did you find this post helpful? Yes | No

    Default Code Released

    After realizing that Pebbles is probably 60-70 years old by now ...
    I'm not so interested in BAMBAM anymore.

    The name has been changed to MIBAM. (Mirror Imaged Bit Angle Modulation)

    And the code for PicBasic Pro is now available here ...
    http://www.picbasic.co.uk/forum/showthread.php?t=10564

    Cheers,
    DT

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