Toggled Pic flip flop Help Please


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2007
    Posts
    35

    Default Toggled Pic flip flop Help Please

    Hi all

    I have had a bit of a blonde moment and wonder if anyone could help me,

    Thanks...

    Can anyone suggest a small bit of self contained code I can add at the end of my existing code, That will give me a toggled flip-flop output.

    EG, gp0 i/p (triggered high to low via push button)
    gp1 o/p (low at switch on)
    gp2 o/p (high at switch on)

    When i/p triggered the o/p's swap over and latch in that state until the button is pressed again, after it will then return back to the original state.

    Also how difficult is it to get the pic to remember its last state after a power up/down

    This is a test program I tried to get working, before modding and inserting into my existing code.


    ' Define Hardware
    ' ---------------
    InputTrigger var GPIO.2 ' Input normally HIGH, goes LOW to Trigger
    OutputLine0 var GPIO.0 ' Normally LOW, goes HIGH when triggered
    OutputLine1 var GPIO.1 ' Normally LOW, goes HIGH when triggered
    '
    ' Initialise PIC
    ' --------------
    Reset:
    TRISIO=%00000100 ' Preset I/O
    CMCON=%00000111 ' Disable Comparators
    ANSEL=%00000000 ' Disable ADC
    pause 200
    HIGH OutputLine0 ' Set output
    LOW outputline1 ' Set output

    if outputline0=0 then outputline1=1 (these are the two lines i am having)
    if outputline0=1 then ouputline1=0 ( problems with )

    ' Main Program Loop
    ' -----------------
    Loop:
    '
    '
    ' Test for Trigger
    ' ----------------
    If InputTrigger=0 then ' Test for Trigger
    toggle OutputLine0 ' Enable Output

    endif
    Goto Loop

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    I am not sure why you have these two lines – they will always be false since they follow your HIGH and LOW statements ... delete them (in my opinion)

    Code:
    if outputline0=0 then outputline1=1 (these are the two lines i am having)
    if outputline0=1 then ouputline1=0 ( problems with )
    To get you going, try this for your Loop – Goto Loop section (written close to your style).

    Code:
    Loop:
    '
    '
    'Test for Trigger
    '----------------
    If InputTrigger=0 then
    	pause 30				' Debounce time
    	If InputTrigger = 1 then Loop	' Debounce check – exit out of loop if not low after 30 mS
    
    	While InputTrigger=0			' Wait for button release before updating
    	Wend					' so you do not race through your Loop routine a zillion times before you release the button
    
    	GPIO = GPIO ^ 3			' Toggle bits 0 and 1 - See PBP manual section 4.17.14
    Endif
    Goto Loop
    After this works, you can work on saving the state of the toggle in EEPROM. What PIC are you using?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Oct 2007
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Hi,

    Thanks for your help,

    I have transfered your code (i can see where I went wrong) (yours is a better way)
    and it works well,
    I have decided to run the switching code in a 12F675 on its own as I had run out of ports on my 16F627,

    (Just to put you in the picture the unit is part of a two way radio repeater, and the coding was to switch between to linking radios.)

    Cheers
    Dave...

Similar Threads

  1. Flip Flop
    By tazntex in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th November 2008, 21:53
  2. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 22:01
  3. flip flop for driving latching solenoids
    By kitcat in forum Schematics
    Replies: 3
    Last Post: - 4th February 2006, 23:34
  4. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th March 2005, 00:14
  5. need hex code to make 12c509 a flip flop,
    By bruce3mn in forum General
    Replies: 1
    Last Post: - 15th November 2004, 04:23

Members who have read this thread : 1

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