The worst programmer ever to grace this forum - ME!


Closed Thread
Results 1 to 40 of 50

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    BUTTON 7, 0, 255, 0, B0, 1, Loop
    ???????
    Try
    BUTTON PORTB.7, 0, 255, 0, B0, 1, Loop

    Or better yet
    Code:
    IF PORTB.7 = 0 THEN GOTO NEXT
    OOPS!!!!!!
    That will not work...NEXT is a reserved word. Will have to think of something else to call that label.. FRED??
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default 'F690 Registers and BUTTON Code

    HankMcSpank,

    I think the 'F690 is going to be my next favorite PIC. It has SO MUCH STUFF on it!
    In other words, not a beginner PIC ( like the 16F628, F648, F87, F84(old and gray) )
    There are ALOT of registers to learn how to use on this chip.

    NOTE: something that used to trip me up when reading data sheets:
    when you "SET" a value you change it to "1"
    when you "CLEAR" a value you change it to "0"
    so that if someone says "set the flag", it means to ONE, (1), HIGH
    I only bring this up because you are new. The M-chip data sheets use this nomenclature all the time.

    Also NOTE: The 16F690 Datasheet is your new best friend. All 306 pages, WOW. You might want to print out the pages with
    the register descriptions for each "feature" so you know what CM1CON0, etc means. Adobe pages 34-37 are best. Also,
    under the feature headings are listed all relevant registers that need to be set/cleared, usually near the end.

    You might need to set ( or CLEAR) the following registers as well (some required in other PICs):

    'Registers:
    ANSEL = %00000000 ' clears the individual bits that select analog inputs (low register)
    ANSELH = %00000000 ' clears the individual bits that select analog inputs (high register)
    VRCON = %00000000 ' turns the Vref Module OFF by CLEARING bit7, 6, 4

    'I use the binary format so I can easily set them later. I know it seems redundant when they are all 0's, but later....

    'Bits Only:
    CM1CON0.7 = 0 ' turns Comparator1 OFF by CLEARING bit7
    CM2CON0.7 = 0 ' turns Comparator2 OFF by CLEARING bit7
    ADCON0.0 = 0 ' turns the AD Converter OFF by CLEARING bit0
    INTCON.0 = 0 ' clears the RABIF Flag (to 0), COULD be 1 on reset (unique to F690)
    RCSTA.7 = 0 ' clears the SPEN bit ( SETTING SPEN DISABLES RB7 AS GENERAL PURPOSE! )
    'note that there is an Errata Datasheet that mentions issues with SPEN, but only when using the Serial Hardware

    'you might HAVE TO do this after clearing ANSEL/ANSELH
    PORTA = %00000000 ' Clear the port register latches
    PORTB = %00000000
    PORTC = %00000000

    TRISA = %11111111 ' Set or Clear the data direction registers
    TRISB = %11111111
    TRISC = %00000000

    'FOR EXAMPLE: On the F628 and friends, you only need:
    'CM1CON = 7 ' turns the comparators OFF by SETTING bits 0,1,2
    'and the Port/Tris settings

    'OK, now on to your code...
    'The Button Command:
    BUTTON 7, 0, 255, 0, B0, 1, Loop
    '"7" is not a pin name.
    'For buttons and LEDs, I use names like btnStart or btnUp, LEDFault, LEDStatus.
    'But sometime I use PHYSICAL pin numbers on new chips that I'm learning. So try :

    RB7pin10 VAR PortB.7

    'I wouldn't use the term B0 as a variable, it is used so many other places (mainly STAMP) to denote PortB.0. Try:

    Temp VAR BYTE

    'Also, for the Jump To label you use "Loop", but I don't see it in your listing. Maybe you meant "Next", but you can't use that name.
    'So Now:

    Start:
    LED1 = 0

    Button RB7pin10, 0, 255, 0, Temp, 1, Blink

    GOTO Start

    Blink:
    LED1 = 1
    Pause 1000
    GOTO Start
    End

    'I'm not at work so I can't test this until tomorrow.

  3. #3
    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!)

  4. #4
    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.

  5. #5
    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

  6. #6
    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 19:30.

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

  8. #8
    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)

Similar Threads

  1. Melabs U2 Programmer Command Line Options
    By Robert Wells in forum General
    Replies: 5
    Last Post: - 3rd July 2009, 03:11
  2. problems with USB programmer
    By malc-c in forum General
    Replies: 7
    Last Post: - 10th May 2007, 21:14
  3. USB programmer problems
    By uiucee2003 in forum USB
    Replies: 2
    Last Post: - 16th August 2006, 00:47
  4. General Programmer Questions
    By mslaney in forum General
    Replies: 1
    Last Post: - 17th December 2004, 19: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