Are they all BYTE's?
Is it a PWM output?
7ms is a LONG TIME.
<br>
Are they all BYTE's?
Is it a PWM output?
7ms is a LONG TIME.
<br>
DT
INDEX and A through E are bytes. All five pins are on the same port.
Not sure if it's PWM or not. But at the end of the interrupt handler, all pins are reset to 0. Values A through E each represent a proportion of SOMETHING. If A through E were equal, all five pins would need to turn on as nearly as possible at the same instant.
The interrupt (INT_INT) is being driven by a zero-crossing detector at 60 Hz (120 interrupts/second).
Guess it <i>is</i> PWM, period 120 Hz, and I'm varying the duty cycle on each pin.
Last edited by RussMartin; - 7th February 2010 at 21:05.
Russ
N0EVC, xWB6ONT, xWN6ONT
"Easy to use" is easy to say.
This should be a bit faster ... (untested)
Code:INDEX VAR BYTE BANK0 SOMETHING VAR BYTE BANK0 A VAR BYTE BANK0 B VAR BYTE BANK0 C VAR BYTE BANK0 D VAR BYTE BANK0 PIN1 VAR PORTB.0 PIN2 VAR PORTB.1 PIN3 VAR PORTB.2 PIN4 VAR PORTB.3 ASM TestStart movlw 0 ;FOR INDEX=1 TO SOMETHING movwf _INDEX ForLoop incf _INDEX,F movf _A,W ; IF INDEX>A THEN PIN1=1 subwf _INDEX,W btfsc STATUS,C bsf _PIN1 movf _B,W ; IF INDEX>B THEN PIN2=1 subwf _INDEX,W btfsc STATUS,C bsf _PIN2 movf _C,W ; IF INDEX>C THEN PIN3=1 subwf _INDEX,W btfsc STATUS,C bsf _PIN3 movf _D,W ; IF INDEX>D THEN PIN4=1 subwf _INDEX,W btfsc STATUS,C bsf _PIN4 movf _INDEX,W ; Next INDEX subwf _SOMETHING,W btfss STATUS,Z goto ForLoop ENDASM
DT
Russ,
I am sure there are other ways to get the pwm you need (such as interrupts), since this method takes up a HUGE amount of cpu time. However, if that doesn't matter and you just need a bit more speed, consider asm.
I compiled your snippet with PBP, and it used up 57 words of program space on a 16F. Proton+ did the same code in 36 words; almost 2/3 the size. PBP's asm file is nearly unreadable, so I can't compare them, but here is the Proton output from a single basic line for both 16F and 18F:
16F...
[TEST.BAS] IF INDEX>A THEN PORTA.1=1
MOVF INDEX,W
SUBWF _A,W
BTFSC STATUS,0
GOTO BC@LL4 'go to the next line...
BSF PORTA,1
18F...
[TEST.BAS] IF INDEX>B THEN PORTA.1=1
MOVF INDEX,W,0
CPFSLT _B,0
F@JUMP BC@LL6 'go to the next line...
BSF PORTA,1,0
Thanks for the suggestion, Darrel; I'll try it, expanding to add PIN5 and value E.
Thanks for the comparison, tenaja.
Although now I wonder if I'm looking for the wrong problem. Using the o'scope, I see that each of those IF . . . THENs actually takes only about 22us; that's only 110us for all 5. Maybe it's the FOR . . . NEXT. Each time I added an IF . . . THEN, I had to reduce SOMETHING and rescale each of however many variables I was comparing.
Russ
N0EVC, xWB6ONT, xWN6ONT
"Easy to use" is easy to say.
Yes, I knew about the <b>* SOMETHING</B> !
But now I have the opposite problem . . . since yours is so much faster, I would need to run it almost three times (because the variables can range from 0 to whatever SOMETHING is scaled to). Should I just run it three times in succession, or do I need to go to a WORD variable for SOMETHING? (I need to scale SOMETHING through as much of that time span as possible.)
Russ
N0EVC, xWB6ONT, xWN6ONT
"Easy to use" is easy to say.
since yours is so much faster, I would need to run it almost three times (because the variables can range from 0 to whatever SOMETHING is scaled to).![]()
![]()
Totally Lost me on that one.
<br>
DT
Bookmarks