Bit Banging input to output on PIC16F876A


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Posts
    21

    Default 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.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    So why not go a stage further...

    Chose a PIC that not only has Hardware PWM, but also a Hardware Comparator (eg 16F628) with dedicated output. Cross Connect the HPWM to one Comparator Input. The 2nd Comparator Input is cross connected to the PIC pin of your choice. This pin now ANDs (modulates) the Comparator (PWM Carrier) output. Not much need to bit-bang anything... and almost no software overhead...

    Life is simple (or at least it can be)...

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bronurstomp View Post
    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!
    Well, i really depend of the accuracy you can/want to deal with. PICMultiCalc says you can produce up to 2.5 MHz @ 20MHz.. but <4 bit resolution... only 8 duty steps

    To do so, you'll need to configure the CCP registers manually.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Melanie,

    I would love to see an example of how this works. It would be really nice for sending IR serial
    data modulated at 38-40kHz.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Give me a couple of days Bruce to find some spare time and throw an example together - I'll post it here... watch this space...

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    7 days a week, 24 hours a day, you only work 120 hours a week... so you still have spare time huh?

    I see what's you're cooking. I've used something like that in the past... before i lost everything on my hard drive

    I remember that i also modified SEROUT routine... and it also remember me something that Darrel already did here... i'll search for it now.
    Last edited by mister_e; - 26th May 2008 at 21:37.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I've tried what Melanie mentioned, but could never get it to work properly when changing
    Vref with another I/O-pin.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  2. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  3. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  4. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 22:19
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

Members who have read this thread : 0

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