Problems with 12F675


Closed Thread
Results 1 to 40 of 67

Hybrid View

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

    Default Problems with 12F675

    Hi to all !
    I am still at the beginning of understanding the MCU's...After finalizing the project with Nokia 3310 display (thermometer & clock, see in this forum) I try to make another project ; one button for electric windows of my car.
    If short pulse for up, the window roll-up till detecting over-charging of motor ; if short pulse for down, rolling-down till over-charge...
    I use code from this forum ; I try the schematic in ISIS, but nothing happening !
    I think I do something wrong...Can somebody help me, please ?! Thanks in advance for every suggestion !
    btw : adval >=256 ; that means 4.00 Volts ?
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by fratello; - 9th July 2009 at 21:48. Reason: How calculating adval ?

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


    Did you find this post helpful? Yes | No

    Default

    Try ...
    Code:
      CHECK:
      ADCIN 3, adval
    The 675 doesn't have an AN4.
    DT

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

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

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

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

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

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