Reading if Pin is High or Low?


Closed Thread
Results 1 to 30 of 30

Hybrid View

  1. #1
    Spindle's Avatar
    Spindle Guest


    Did you find this post helpful? Yes | No

    Question

    Ok the only problem is now if I switch it one way and then switch it to the middle the motor still goes because I guess the command is still being sent to the motor driving circuit. There is however a _break pin you can control. See attached image. Other than how its wired from the diagram mister_e posted the ground that comes off my chip goes to the switch and then to PIN 12. This drives it low and disables the H-Bridge on circuit. The problem when the switch is turned left or right for forward and reverse movement nothing happens because _break is still being driven low. I can't think how I can make it high when the switch is left or right. Maybe instead of connecting the pin to the ground, connect it to another portb pin and when its switch left make that pin high but i don't think to 5 volt supplies will work on a switch :P again I am no electrical engineer but am trying my hardest. Any help is apreciated. Please check out the picture I basically want to do that with the break switch but only when the SPDT switch is in the middle. When its to the left and right have _break go back high.
    Attached Images Attached Images  

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    can you provide the whole datasheet or a link of this specific motor controller???
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Spindle's Avatar
    Spindle Guest


    Did you find this post helpful? Yes | No

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=390&stc=1">
    Well i guess you could fix about everything by reading the actual motor position and tell him to go to the readed position.

    well to make it more clear... here's a snip of the idea
    Code:
    MAIN:
        IF (UP = 0) AND (DOWN=1) THEN
           serout FM, T9600 ,["W01 01 200", CR, LF] 'Write velocity limit value 
           serout FM,T9600,["P01 270000", CR, LF] 'Send MOVETO_ABSOLUTE command
           ENDIF
    
        IF (DOWN = 0) AND (UP = 1) THEN
           serout FM, T9600 ,["W01 01 200", CR, LF] 'Write velocity limit value 
           serout FM,T9600,["P01 0", CR, LF] 'Send MOVETO_ABSOLUTE command
           ENDIF
    
        if (DOWN = 1) AND (UP = 1) then 
           ' SERIN motor position
           ' SEROUT motor position to make him stop
           endif
        
        goto MAIN
        End
    it's an idea. Let us know!
    Attached Images Attached Images  
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    OR... use a variable and increment/decrement it on each IF THEN statement... the only thing... i don't know how the movement will be produced... probably it will not going to be purely smooth.

    try
    Code:
    PositionHB var byte
    PositionLB var word
    T9600      con 84   ' 9600 bauds
    
    MAIN:
        IF (UP = 0) AND (DOWN=1) THEN
           serout2 FM, T9600 ,["W01 01 200", CR, LF] 'Write velocity limit value 
           if positionlb < 9999 then
              if positionhb != 27 then 
                 positionlb = positionlb+1
                 endif
              else
                  positionlb = 0
                  if positionhb < 27 then
                     positionhb = positionhb+1
                     endif
              endif
    
           serout2 FM,T9600,["P01 ",dec2 positionhb,dec4 positionlb,_
                             CR, LF] 'Send MOVETO_ABSOLUTE command
           ENDIF
    
        IF (DOWN = 0) AND (UP = 1) THEN
           serout2 FM, T9600 ,["W01 01 200", CR, LF] 'Write velocity limit value 
           if positionlb then
              positionlb = positionlb - 1
              else
                  positionlb = 9999
                  if positionhb then
                     positionhb = positionhb-1
                     endif
              endif
    
           serout2 FM,T9600,["P01 ",dec2 positionhb,dec4 positionlb,_
                             CR, LF] 'Send MOVETO_ABSOLUTE command
           ENDIF
    
        goto MAIN
        End
    there's probably something i missed in the math condition but, this have to work... well i guess.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Spindle's Avatar
    Spindle Guest


    Did you find this post helpful? Yes | No

    Default

    thanks mister_e I am gonna try your first thing, this is for a motorized shade application so the next step is to have the position constantly store the absolute position in the PICs eeprom incase the main power is cut it won't be confused when power is applied again. Thats aways off, first thing is first, I shall try your solution!

  7. #7
    Spindle's Avatar
    Spindle Guest


    Did you find this post helpful? Yes | No

    Default

    I tried your first solution and no go. When you flip the switch one way it still goes forward and when you flip the switch the other way it still goes reverse. But if you were to flip it from left to center it would still spin and NOT shut off. Same if you were to flip it from right to center. It would still move (the motor) until it gets to that absolute position. Some how I have to ustilize that _break pin because brining it low disables the H-Bridge. I have to do that somehow where if the switch is to the left or right its not pulled low. Mister E. It is wired up like your diagram in your previous posts.

Similar Threads

  1. SERIN MIDI out of Synch?
    By jncortes in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 9th June 2009, 20:08
  2. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 15:23
  3. Pic16f84 and RC5 kode
    By terminator in forum Bluetooth
    Replies: 5
    Last Post: - 18th June 2007, 21:40
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. sample code for M25P32
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th January 2007, 02:37

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