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

    I will suggest you pick up a cheap bread board or two and a hand full of LEDs, resistors, caps etc. The demo boards are nice I guess, but you can not do a whole lot with them other than what they were designed to do.

    As far as the coil winding project goes. A switch on a cam or some other part will work. Every revolution the switch is "bumped" from low to high. Every time the switch is bumped a variable is incremented.

    If it is not running real fast interrupts will not be needed.
    Code:
    LOOP:
    IF SWITCH = 1 THEN
    WRAP = WRAP + 1
    GOTO LOOP
    That is the basics. Add a serial or LCD to display the value. Add
    IF WRAP = X THEN GOTO STOP ???

    Let us know...
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    I will suggest you pick up a cheap bread board or two and a hand full of LEDs, resistors, caps etc. The demo boards are nice I guess, but you can not do a whole lot with them other than what they were designed to do.

    As far as the coil winding project goes. A switch on a cam or some other part will work. Every revolution the switch is "bumped" from low to high. Every time the switch is bumped a variable is incremented.

    If it is not running real fast interrupts will not be needed.
    Code:
    LOOP:
    IF SWITCH = 1 THEN
    WRAP = WRAP + 1
    GOTO LOOP
    That is the basics. Add a serial or LCD to display the value. Add
    IF WRAP = X THEN GOTO STOP ???

    Let us know...
    Whilst I was sold on the concept of the ease of use of the Microchip low pin count board, (esp to get me some simple quick & dirty IO) I'm now very rapidly seeing the shortcomings!

    As it goes I have, breadboard & plenty of components...I'll be using all that in earnest, once I've nailed the basics here (no pun intended).

    Re the coil winder. I'm using an old DC cooling fan with a drill chuck hot glued to its centre ( http://img25.imageshack.us/img25/2717/workshopjd8.jpg - ugly but fulfills a need!)....this drill chuck will hold the 'solenoid core' while to copper wire is wound onto it. On this fan will be 7 or so magnets, each in turn closing a magnetic reed switch as the motor turns (I'd imagine the maximum speed the fan will be turning at for this project will be about 200RPM I've made a simple PWM circuit to control the speed of the fan).

    Where the PIC comes into the equation, is that it will count the pulses from the fan motor. For every 'X' pulses it receives from fan motor's reed switch, the PIC will send one short pulse onwards to a UCN5804 stepper motor IC. It's essentially a pulse counter/divider ...for ever x pulses received, output one pulse.

    The UCN5804 feeds a small stepper motor - on its shaft is a bit of threaded nylon rod - it's over this threaded rod that the copper wire feeds onto the solenoid core (this youtube video illustrates what I'm trying to achieve well - (from about 27 seconds in).

    The whole point of this is to have my wire neatly wound onto the solenoid. Since I know the diameter of the copper wire (0.15mm), & I know the pitch of the nylon rod's thread feeding the wire (1mm), it's just a fairly simple calculation. therefore for every turn of the main DC fan, I need the stepper motor threaded rod traverse the wire 0.15mm. It's a 7.5deg stepper, therefore each step of the 1mm pitch threaded rod will traverse the copper wire 0.0208mm, therefore to move the wire 0.15mm, some 7.2 steps needed are to the stepper for every turn of the main fan (since there's no such thing as 0.2 of a pulse I'll be rounding it down to 7!)

    To nail this project I need to...

    1. Sort out all the idiosyncracies of getting my PIC programming enviroment set up for the PIC16F690 - check! (thanks to here!)
    2. Lean how to set a PIC output pin high - check!
    3. Learn how to check a PIC input pin (to see if a switch has closed) - check!
    4. Learn how to setup a few 'count' variables, get them incrementing (& check 'em)....acting whenever the counts have been met - still to do!
    5. Learn how to output a pulse - still to do.

    I'll also need to figure out some form of debounce (I may end up using a monostable chip to do this)

    Thanks for your suggestion on how to approach this...I'll have a play with your lines to see if I can get the switch on my low pin count board to act as the reed switch & one of the LEDs as the stepper chip feed....ie after 7 presses of the board's button, make an LED turn on.
    Last edited by HankMcSpank; - 15th March 2009 at 13:51.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    do the debounce in software. (short pause) or if it's off to do something else once triggered, you may not even need debounce..

    you can search for debounce examples from here http://www.picbasic.co.uk/forum/showthread.php?t=4751

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Ok, a bit more reading .... it seems the button command will be perfect for needs.

    My initial problem is that it only acts on PORTB pins (& the Pickit 2 board has its switch wired to RA3). therefore I've rigged up a pull up resistor onto pin RB7 & a small switch which goes to ground (therefore puts 0V onto RB7 when this new switch pressed). However RB7 is being held low all the time.

    I'm figuring this must be something to do with the .inc file again (I've rechecked my wiring - it's fine ...10k resistor between RB7 & the 5V rail....and a normally open switch going from RB7 to ground). I chose RB7 for my new switch as it seemed to have the least happening! On the datasheet it's listed as RB7/TX/CK ...how can I be sure it's being used as an input pin only (& not being overridden by one ithe pins other purposes)

    Does anyone have any ideas why my RB7 might be permanently low.

    Here's the small bit of code I'm using...

    @MyConfig = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON
    @MyConfig = MyConfig & _MCLRE_OFF & _BOR_OFF
    @ __config MyConfig

    DEFINE OSC 4
    ANSEL=0 ' all digital
    ANSELH=0 ' analog module disabled
    CM1CON0=0 ' dunno what this line does!
    CM2CON0=0 ' nor this one!
    TRISA=%11111111 ; set all Port A pins as inputs
    TRISB=%11111111 ; set all Port B pins as inputs
    TRISC=%00000000 ; set all Port C pins as outputs

    B0 VAR BYTE ;creates a variable as needed for the button command below
    B0 = 0 ; give it a value of zero (as per the command's reference)

    LED1 var PortC.0 ' ; assign a more usable name to the first LED port

    start:
    LOW LED1 ; turn the first LED off

    BUTTON 7, 0, 255, 0, B0, 1, Loop ; monitor the switch on RB7 for 0V,
    ;if this condition is net, then go to next

    next:
    high LED1 ; turn the first LED on
    PAUSE 1000 ; wait one second
    goto start ;start over
    End
    Last edited by HankMcSpank; - 16th March 2009 at 00:39.

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

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

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

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

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