Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Bam test

Status
Not open for further replies.
That example was for an 8 bit timer. I understand updating 16 bit timers may involve updating each half of the register in a certain order.
 
Last edited:
16 bit timer registers have an interlock: write to either half requires a write to the other to be accepted, it'll just hang until the 2nd write. Checkout any of Freescales' 9S08 series uC w/TPM, flexible enough to be confusing but can do a lot.

I'm just old enough to not get this "bam" nonsense. PWM has been around since before LEDs existed, so how can an LED company patent or copyright it? Am I missing something? Let these clowns sue Allen Bradley or GE over the use of PWM... I'll make popcorn for that movie..... <<<)))
 
@Mike yes that was what I was doing in that 'strange code'
it was only to see if I could get the timings right with TMR0
at higher refreshes in 16bit mode.
With your tip I might as well change to 8bit mode in TMR0
and still have good timings.(thats my project for today :) )
Edit: Thought this over and won't work at bit0 since there is only
1 or 2 counts so back to 16bit mode.


@OlPhart I'm only trying BAM to get more free CPU time for
doing other stuff while maintaining a high Bit Depth for my matrix
an because I like learning new PicStuff also.
I also find it unbelievable that PWM is patented.
 
Last edited:
Code below should dim led according to level values.
But I experience strange behaviour.
Can anyone spot an error?

UPDATE: I think my isr took too many cycles and thats why it behaved oddly

Code:
if(PIR1.CCP1IF) // CCP1 REGISTER COMPARE TMR3 Interrupt?
   {
     sCCPR1=BamH;
     sCCPR1<<=4;  // (changing this to 7 and then it works????)
     CCPR1=sCCPR1;
     itmp=0x01;
     itmp<<=Bambit;
     if(gamma[level] & itmp) LEDRED=1; else LEDRED=0;

     asm INCF   _BAMbit+0, 1       //
     asm MOVLW  7                  //
     asm ANDWF  _BAMbit+0, 1       // BAMbit = ( BAMbit+1 ) & 7
     asm BZ LBL00                  // if(Bambit==0) BamH= 0b11111110;
     asm RLCF _BamH                // BamH<<=1;
     asm GOTO LBL01                // Were done for now
     asm LBL00:
     asm MOVLW 0b00000001          //
     asm MOVWF _BamH               // BamH= 0b11111110;
     asm LBL01:


     PIR1.CCP1IF = 0;    // clear T0 Int flag
    }
 
Last edited:
Here's my optimized isr for BAM total code is approx 60 cycles
So that leaves me about 60 for the 1T interval .
I've been saving some registers on isr entry and restoring them
back at the end , but I don't know if its really necessary.

Code:
if(PIR1.CCP1IF) // CCP1 COMPARE TMR3 16mhz  (1T=128 cycles) refrsh = 488 hz
   {              // Total now is 60 cycles
     asm MOVWF _BamL               // Save W
     asm MOVFF STATUS,_sSTATUS     // Save STatus
     asm MOVFF FSR0L,_sFSR0L       // Save STatus
     asm MOVFF FSR0H,_sFSR0H       // Save STatus
// Load next BamTiming
     asm MOVFF _sCCPR1H,CCPR1H
     asm MOVFF _sCCPR1L,CCPR1L
// Start Precalc
// itmp<<=Bambit (51 cycles optimized to 7 cycles)
     asm MOVLW 0x90                // masks[] at 0x90
     asm MOVWF FSR0L               // Point to masks[]
     asm CLRF FSR0H
     asm MOVF _Bambit,0            // Store in W
     asm ADDWF FSR0L,1             // Store in F
     asm MOVFF INDF0,_itmp

     if(gamma[level] & itmp) LEDRED=1; else LEDRED=0; // 20 cycles

     // LEDRED^=1;                    // Invert Bit at LATA,2
// BAMbit = ( BAMbit+1 ) & 7 and calculate next CCP COMPARE value
     asm INCF   _BAMbit+0, 1       //
     asm MOVLW  7                  //
     asm ANDWF  _BAMbit+0, 1       // BAMbit = ( BAMbit+1 ) & 7
     asm BZ LBL00                  // if(Bambit==0) BamH= 0b11111110;
     asm RLCF _BamH                // BamH<<=1;
     asm GOTO LBL01                // Were done for now
     asm LBL00:
     asm MOVLW 0b00000001          //
     asm MOVWF _BamH               // BamH= 0b11111110;
     asm LBL01:
// sCCPR1<<=7; // Takes > 40 cycles  optimized to 6 cycles
     asm CLRF _sCCPR1L
     asm MOVFF _BamH,_sCCPR1H
     asm RRCF _sCCPR1H,1           // Rotate Right store in F
     asm BNC LBL02
     asm BSF _sCCPR1L,7            // Set bit 7
     asm LBL02:                    // Result 0BBBBBBB:B0000000 / 1T=128 cycles
     
     PIR1.CCP1IF = 0;    // clear T0 Int flag
     asm MOVFF _sFSR0H, FSR0H   // Restore FSR0H
     asm MOVFF _sFSR0L, FSR0L   // Restore FSR0L
     asm MOVFF _sSTATUS, STATUS // Restore STATUS
     asm MOVF _BamL,0           // Restore W

    }
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top