Bit Banging input to output on PIC16F876A
Hi folks.
Some init stuff: I'm using a PIC16F876A.
DEFINE OSC 20 ' use 20mhz xtal.
DEFINE HPWM1_TMR 1 'Use timer 1 for both channels
DEFINE HPWM2_TMR 1
DEFINE CCP1_REG PORTC 'Hpwm 1 pin port
DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
I want to output a bit on PORTB.2. Ok np.
Now I want to logically AND it to the input pulse on PORTA.2 and send it to another pin, say PORTB.6. The input pin PORTA.2 is electrically connected to HPWM pin (output) of this same chip. I want to basically multiplex the PWM output to other output pins via the logical AND. I've generated the HPWM before calling this subroutine.
If (stuff happens)
HPWM 1, percntpwm, 3000 REM ----- 3KHZ output for example. How fast can this be?
Gosub Bitbang
This is the subroutine I'm thinking of using. It seems pretty straight forward, but can it be done like this?
Bitbang:
PORTB.1 = 0 ; These outputs
PORTB.2 = 1 ; are also needed
PORTB.3 = 1
PORTB.4 = 0
PORTB.6 = PORTA.2 AND PORTB.2 ; Perform AND then route the result to the output
RETURN
I'm away from my hardware for a few months on business so I can't test this idea.
The real question is: What is the highest HPWM frequency I can accurately reproduce on the PORTB.6 output assuming a 20MHZ Crystal?
Thanks in advance!
Last edited by Bronurstomp; - 26th May 2008 at 16:57.
The less you expect, the more you get.
Bookmarks