Problems with 12F675


Closed Thread
Results 1 to 40 of 67

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Another problem...

    I made this schematic.
    I write this code.
    I want this :
    - if I push button on gpio.3, gpio.5 goes high UNTILL voltage at AN3 goes OVER 550 mV or I push again the button ;
    - idem for gpio.2 -> gpio.0.
    My problems are :
    - AN1 must be on Vdd ?
    - the calculation of vt (voltage at AN3) is correct ? ( I use 10 bit resolution, so 5000/1024= 4,88 -> con1 = 4 & con2 = 88). Can someone to explain me more accurate ? Maybe I must use 12 V for calculation ?!
    Thanks in advance for every reply !
    Attached Images Attached Images  
    Attached Files Attached Files

  2. #2
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    I use the information from here : http://www.picbasic.co.uk/forum/show...8&postcount=12
    So, I need to detect the voltage from 0,48 V to 0,56 V ( load of 120 to 140W , using R1= 0,05 Ohmi) ; if voltage increase over 0.56 V, gpio.5 MUST go to 0 !
    Thanks for attention...

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by fratello View Post
    I want this :
    - if I push button on gpio.3, gpio.5 goes high UNTILL voltage at AN3 goes OVER 550 mV or I push again the button ;
    As it's written ... when a button is pressed, it checks the voltage ONE time then waits for the button to be released. That's all.
    Not even close to what you "wanted".

    The "Check's" need to be in a loop, or a couple loops since you want to look for a second button press.

    Something like this might work ...
    Code:
      if GPIO.3=1 AND GPIO.0 = 0 then 
        HIGH GPIO.5
        pause 20             ; debounce
             
        while GPIO.3 = 1 
          CALL CHECK         ; check while waiting for button release
        WEND
        pause 20
    
        WHILE GPIO.3 = 0
          CALL CHECK         ; continue checking input
          if GPIO.5 = 0 THEN ; IF LED was turned OFF in CHECK routine
            GP3PressDone     ;   we're done
          endif
        WEND                 ; stop if button is pressed again
        LOW  GPIO.5 
    
        while GPIO.3 = 1     ; wait for button release
        WEND
        pause 20
    
      endif
    
    GP3PressDone:
    Then do the same thing for the GP2 button.

    I was bouncing back and forth from the code to the schematic, having a hard time figuring out what you were trying to do. With so many GPIO's spread throughout the program it's really, really hard.

    It would be a lot easier to debug your programs if you used Aliases.
    Instead of GPIO.0 etc ... give meaningful Names to each Pin ...
    Code:
    LED1   VAR GPIO.5
    LED2   VAR GPIO.0
    BUTN1  VAR GPIO.3
    BUTN2  VAR GPIO.2
    Then it would look like this, which is much easier to follow ...
    Comments help too.
    Code:
      if BUTN1 = 1 AND LED2 = 0 then 
        HIGH LED1
        pause 20             ; debounce
             
        while BUTN1 = 1 
          CALL CHECK         ; check while waiting for button release
        WEND
        pause 20
    
        WHILE BUTN1 = 0
          CALL CHECK         ; continue checking input
          if LED1 = 0 THEN   ; IF LED was turned OFF in CHECK routine
            GP3PressDone     ;   we're done
          endif
        WEND                 ; stop if button is pressed again
        LOW  LED1
         
        while BUTN1 = 1      ; wait for button release
        WEND
        pause 20
    
      endif
    
    GP3PressDone:
    You would have received an answer a lot quicker that way too.
    <br>
    DT

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Also, for the Voltage conversion ...

    The way you are doing it will overflow the variables and isn't very accurate.

    A better way would be to use DIV32 ...
    Code:
    CHECK :
      ADCIN 3, ADVAL
      VT = ADVAL * 5000  ; 5V with 3 decimals
      VT = DIV32 1023    ; / maximum A/D reading
    
      IF VT > 550 THEN
        GPIO.5 = 0
        GPIO.0 = 0
      ENDIF
    RETURN
    hth,
    DT

  5. #5
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    THANK YOU !!!!
    I will try the soft and I will keep You inform.

  6. #6
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    I write this code. It's something wrong :
    - if I press but1 and rel1 goes low because of 'check' (over-load detected), but2 don't work not at all (must disconect power), and rel1 goes high only after two press of but1 ;
    - if I press but2 and rel2 goes high, if I press but1 rel2 goes low ;
    - if I press but2 and rel2 goes low because of 'check' (over-load detected), but1 don't work not at all (must disconnect power), and rel 2 goes high only after two press of but2.
    Can help me ? Thanks in advance.
    btw: The 'check' subroutine works fine !
    Attached Files Attached Files

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    OOPS, my fault

    In post #5 the line
    Code:
            GP3PressDone     ;   we're done
    Should have been
    Code:
            GOTO GP3PressDone ;   we're done
    That's how it get's out of the loop under those conditions.

    Sorry,
    DT

  8. #8
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    ...still not work proper...same bugs

Similar Threads

  1. 12F683 vs 12F675.
    By sccoupe in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th July 2009, 04:58
  2. LANC code 12F675
    By MikeDD in forum General
    Replies: 4
    Last Post: - 9th May 2008, 05:44
  3. 12F675 cant serout to PC
    By ruijc in forum General
    Replies: 9
    Last Post: - 3rd December 2007, 00:11
  4. USART problems
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 47
    Last Post: - 6th March 2005, 21:45
  5. Serial LCD on 12F675
    By anj in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 31st March 2004, 23:11

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