12f675_fuse_about_to_blow!


Closed Thread
Results 1 to 40 of 929

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Henrik thanks for that.

    I'm trying to use the COUNT command that mackrackit put me onto to jump from one loop to the next after a button is pressed. There are three loops (count up to nine when button pressed once - Jump to second loop and count down from nine if button pressed a second time and to a final third loop, count down from five after button is pressed a third time).

    Is this code anywhere near to where I need to be? If I'm close but not quite there please let me carry on thinking. If I'm miles off course then a pointer would be much appreciated.

    Code:
    COUNT PIN.n, 10000, VAR B_P_C WORD  'Set GPIO.n as input, define Button Push 
    Count as VAR WORD B_P_C, with a loop count time of 10 secs.
    
    Let i = B_P_C
    
    IF B_P_C = i GOTO  FIRSTLOOP ' Button pressed once
    IF B_p_c = i+i GOTO SECONDLOOP ' Button pressed twice
    IF B_P_C = i+i+i Goto THIRDLOOP   ' Button pressed a third time
    My code tags are working today, I didn't touch anything.

    David
    Last edited by LEDave; - 2nd March 2010 at 14:58.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Not quite sure I understand. Are you saying that you want it to execute one of the three loops depending on how many times the butten is pressed within a certain amount of time? Or are you saying that you want to execute the three loops, one after the other, but to wait for a button press between the loops?

    In any case, I'm afraid what you have there ain't gonna work....

    Code:
    B_P_C VAR WORD
    COUNT GPIO.5, 10000, P_B_C
    The above will define a 16 bit variable called B_P_C and then immediatley start counting how many times the button connected to GPIO.5 is pushed. It will keep counting for 10 seconds (10000mS) after which it continues in the program.

    Code:
    Let i = B_P_C
    What this does is to say that i should be assigned whatever value B_P_C is. So, after this is exectued i has the same value as B_P_C, provided i is declared the same size as B_P_C - a WORD in this case.

    Code:
    IF B_P_C = i GOTO  FIRSTLOOP ' Button pressed once
    IF B_p_c = i+i GOTO SECONDLOOP ' Button pressed twice
    IF B_P_C = i+i+i Goto THIRDLOOP   ' Button pressed a third time
    Now, since i is the same as B_P_C (it is because you told it to be) the only condition that can ever be true is the first one.

    /Henrik.

    PS. Pushbuttons are quite "bouncy", the COUNT command may register several counts even though you only push the button once.
    Last edited by HenrikOlsson; - 2nd March 2010 at 17:32.

  3. #3
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Cheers Henrik. The idea is to run the first loop when the button is pressed, if the button is pressed again the counter would count two button pushes and run / goto loop two, if pressed three times would goto loop three, run that loop then stop.

    Somehow I need to get the button pushes to increment a counter: One push = run loop1 two pushes = run loop2 three pushes = run loop3....then Stop until button pressed again.

    Is there anyway when a button is pressed to just count how many times that's happened then jump to a given loop without the count timer running?

    Thanks for your help.

    David

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hi,
    You say that if the button is pressed one time it should run the first loop - no problem there. But how fast should you need "double-click" or "tripple-click" it in order to run the second or third loop instead of the first one? Or should it run the first loop as soon as it sees a button press and THEN wait for the button the be pressed again?

    With the count command but you need to understand that it counts for a certain amount of time during which nothing else will get executed, once that time has passed (10000ms in your case) the code will continue.

    So, your idea was on the right track but the implementation had a couple of problems as explained in my previous message. Here's ONE aproach to the single, double, triple-click solution but remember that it might not work in reallity due to the switch bouncing as described before.

    Let's say your button pulls the input low when pushed.
    Code:
    B_P_C VAR BYTE
    
    WaitForButton:
      If GPIO.5 = 1 THEN GOTO WaitForButton 'Button is not pressed, go back and check again
      PAUSE 10           			'Wait a little while for the contact bouncing to die
    
    WaitForRelease:
      If GPIO = 0 THEN GOTO WaitForRelease  'Loop here until button is relased
    
      COUNT GPIO.5, 1000, B_P_C             'Count number of presses for during one second
    
      IF B_P_C = 0 THEN GOTO FirstLoop      'Remember, we had to press the button once to get here.
      If B_P_C = 1 THEN GOTO SecondLoop
      If B_P_C = 2 THEN GOTO ThirdLoop      'First one press, then two more as counted by the COUNT-command.
    
    Goto WaitForButton                      'Start over if number of presses is more than 3
    
    FirstLoop:
    'Your code here
    Goto WaitForButton
    
    SecondLoop
    'Your code here
    Goto WaitForButton
    
    ThirdLoop:
    'Your code here
    Goto WaitForButton
    
    END
    Now, wire it up, compile the code, program the chip and GIVE IT A TRY! ;-) If there's still "basic" stuff that you don't understand then you need to back up and get that sorted first or you will just be creating more problems for yourself. Perhaps we jumped to the LOOKUP and COUNT commands etc a little too soon(?).

    /Henrik.

  5. #5
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Henrik first of all a big thank you for giving your time to help me along (and everyone else too of course).
    If there's still "basic" stuff that you don't understand then you need to back up and get that sorted first or you will just be creating more problems for yourself. Perhaps we jumped to the LOOKUP and COUNT commands etc a little too soon(?).
    I agree, I do need to back up and go over some of the basics we've covered, like you say running before you can walk with programming will only compound problems later on.

    I think I need to write lots of short programs using the basics and do enough of them to really drive it home.

    That said, I do understand the basic principle of the COUNT command and it's timing component also with the LOOKUP command.

    When you think that trying to use C and assembler I hadn't even managed to switch an LED on! I've come a long since joining this forum and using PB in the last few weeks thanks to you all, there's absolutely no doubt that this in the language to use!

    So no, time to build this circuit (I need to make something work) and I'm sure I'll still have plenty of questions for you about the basics still, so you're not of the hook quite yet....;-)

    David

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    So no, time to build this circuit (I need to make something work) and I'm sure I'll still have plenty of questions for you about the basics still, so you're not of the hook quite yet....;-)
    No problems, we're all here to help.

  7. #7
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Hi everyone.

    I haven't posted for a wee while but have been busy reading and building my first two circuits.

    The first is a 12F683 driving four LED's in a binary pattern 0-9 as per the thread (I've also added a nice little Night_Rider effect). I must say, although simple in what I've achieved, when those four LED's run up that binary pattern it was a real thrill, amazing.

    The second circuit marrying the binary counting PIC to the BCD decoder driver then seven segment display is about half way built ( I'm quietly confident about this one fingers x'd).

    Once again, thanks for all your help on here. I really wouldn't have got this far without it.

    I'll be back when the second circuit is completed (early part of next week).

    Hope you're all keeping well.

    David

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