The worst programmer ever to grace this forum - ME!


Closed Thread
Results 1 to 40 of 50

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    BUTTON 7, 0, 255, 0, B0, 1, Loop
    ???????
    Try
    Well, the command & it's example syntax it was lifted from here (page 104)....


    http://books.google.co.uk/books?id=X...sult#PPA104,M1

    I figured that since the button command *only* wokds on PortB, that nominating ust the number 7 (as opposed to RB7) would be ok. certainly the example that link gives justiuses the number 7 too!

    Greg...many thanks for the lengthy reply - i'll give that a shot tonight (I'm at work right now too!)

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HankMcSpank View Post
    Well, the command & it's example syntax it was lifted from here (page 104)....


    http://books.google.co.uk/books?id=X...sult#PPA104,M1

    I figured that since the button command *only* wokds on PortB, that nominating ust the number 7 (as opposed to RB7) would be ok. certainly the example that link gives justiuses the number 7 too!
    Maybe you should read the manual that came with your copy of PBP. You will see that these book writers do not always know what they are talking about.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Mar 2009
    Location
    San Diego, CA USA
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    I'm not sure that the Button Command "only works on PortB". Every other command works on any pin except the hardware modules (HPWM, HSERIN, etc).

    Besides you can always use:

    If btnTest = 0 then Blink 'did I change the button name? oops

    Of course there is no debounce, but this is good for testing. Actually, your 1sec delay for the LED is a great debounce! nothing else is going to happen during that interval, nothing. You could also do this to BLINK as long as you hold the button down:

    Start:

    WHILE btnTest = 0
    LED1 = 1
    Pause 500
    LED1 = 0
    Pause 250
    WEND

    GOTO Start

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Greg,

    Just had a chance to try out your suggestions - it works! (iepin 10 is now high...at this stage, I can't be sure which one of those tips you gave was the one that nailed it, becuase I used them all!)

    Some excellent ideas you've given there too about my main program ...in fact, I reckon I've enough sufficient info get this little program sorted now.

    Many thanks to all who took the time to help me out....the internet working at its finest.



    mackrackit...it was very late, & I'd just quickly googled my problem (as I always do when I have a problem & as a beginner, a search engine often serves me better as I can phrase a question when I'm not totally sure of what I'm asking!)...Google led me to that online PICbasic book & I took it at face value!

    Lesson learned.
    Last edited by HankMcSpank; - 16th March 2009 at 18:30.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Places to get help. for PBP.

    Micro Chip web site for data sheets, other places may not have the current one.
    Melabs web site, can not beat the source for examples.
    rentron.com - Bruce's web site. Very good examples.
    This forum, Darrel has a google search in the FAQ section.

    When you are ready for advanced stuff go to Darrel's web site.

    Any place else and who knows...
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    I've just realised that my little program which counts the number of time a switch has been closed (a magnetic switch, which is closed as 10 successive magnets glued to the perimeter of a DC fan motor pass it by!)...isn't counting correctly - & I don't know why (though I suspect it';s either down to the debounce paramters or perhaps the length of time taken to 'do stuff' in between successive magnets).

    here's my simple code (stripped down for clarity)...

    RB7pin10 VAR PortB.7 ;explicity name the switch pin for button command.
    RA3pin4 VAR PortA.4 ;explicity name the switch pin for button command.
    Temp VAR BYTE ; this is used for debounce/delay of the fan switch)
    total_counter VAR WORD ; this will count the total pulses rx'ed from magnets.
    pitch_counter VAR BYTE ; this will utlimately derive the pitch thread (a divider)
    direction_counter VAR word ; this will changed traversal direction word for counts bigger than 255
    pulse VAR PortC.0 ; stepper feed pin 16 (to pin 11 on stepper IC)
    direction var PortC.1 ;direction level pin 15 (to pin 14 on Stepper IC)


    stepper_enable VAR PortC.3 ; Pin 7 this logic level 0 enables the stepper IC (stepper IC Pin 15)

    Start:

    total_counter = 0 ; make sure we start from zero
    direction_counter = 0 ; make sure we start from zero
    direction = 1 ;we want the feed stepper to move left/right first.
    low stepper_enable ;enable the stepper chip.

    Main:
    Button RB7pin10, 0, 255, 0, Temp, 1, magnetic_switch_closed ; monitor the magnetic switch
    goto Main ;if switch not closed, loop until it does close.

    magnetic_switch_closed: ;ok, so switch is now closed - let's count!
    total_counter = total_counter +1 'increment counter to track number of magnets passing switch.
    IF total_counter = 500 THEN
    goto finish ' if using 10 magnets, after 50 turns of the motor exit the program
    endif
    pulse_the_stepper:
    pulsout Pulse, 20 ; pulse the stepper on Port C.0 with 20us pulse.
    Goto main ;return to start & monitor for the switch being closed again

    finish:
    HIGH stepper_enable ;disable the stepper chip
    End




    So to my question....

    Is there a more scientific way to approach this?

    The motor starts off slow, & then increases under manual control up to a speed somewhere between 150RPM & 350RPM. So the rate of magnets passing the switch can be anywhere between 0 per second & 58 passes per second (350/60 = 5.8 turns per second...there are 10 magnets)

  7. #7
    Join Date
    Apr 2009
    Location
    Boise, Id
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    I see a couple of things that make me wonder, your "Temp" Var should be set to 0 at the beggining before you call "Button", if not "Button" won't work correctly.

    Also, you are looking for a switch being closed at rates up to 58 times per second. 1/58 = 17 ms, so ever 17 milli seconds a magnet will sail past your switch, closing it for a moment, then it will re-open. If your magnets cover 50% of the circumference that would give you a 50% duty cycle. So the switch would be closed for 17/2 = 8.5 ms and open for 8.5 ms. In reality, your switch is probably closed about 10 % of the time or 1.7 ms.

    In your code :

    Code:
    Button RB7pin10, 0, 255, 0, Temp, 1, magnetic_switch_closed
    You have delay set at 255, this will perform debounce, but no auto repeat.

    Default debounce is 10 ms, so the switch needs to be closed for 10 ms before you go to "switch_closed"

    You might try a delay of 0, this shuts off the debounce.

    Also you can change the debounce delay:

    DEFINE BUTTON_PAUSE 1 'set button debouce to 1 ms

    1 ms is still cutting it close.

    Or you can skip the button all together and just read the port, something like:

    Code:
    If RB7pin10 = 0 Then switch_closed
    You can read the state of the switch again in the "switch_closed" code, if it's still closed continue, if not jump back out. That performes a high speed debounce. You can also use PAUSEUS before you double check, so you can wait a couple of micro seconds then double check the switch is really closed.

    Just some idea's.

    Shane

Similar Threads

  1. Melabs U2 Programmer Command Line Options
    By Robert Wells in forum General
    Replies: 5
    Last Post: - 3rd July 2009, 02:11
  2. problems with USB programmer
    By malc-c in forum General
    Replies: 7
    Last Post: - 10th May 2007, 20:14
  3. USB programmer problems
    By uiucee2003 in forum USB
    Replies: 2
    Last Post: - 15th August 2006, 23:47
  4. General Programmer Questions
    By mslaney in forum General
    Replies: 1
    Last Post: - 17th December 2004, 18:16

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