Problems with 12F675


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 67
  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578

    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 22: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
    578


    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
    578


    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
    578


    Did you find this post helpful? Yes | No

    Default

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

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


    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

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

  10. #10
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default

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

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


    Did you find this post helpful? Yes | No

    Default

    In your LAST version, you missed the LOW statement.
    Code:
    if but1=1 and rel2=0  then
             high rel1 
             pause 20
                              
             while but1=1
             call check
             wend
             pause 20
                                           
             while but1 = 0
             call check
             if rel1=0 then
                GOTO Btn1PressDone
    ;         pause 10
             endif
             wend
             LOW rel1
    
             while but1=1
             wend
             pause 20
    endif
    Btn1PressDone:
    DT

  12. #12
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default

    Thank You so much for help !
    I think this is my worst project ... I damage two PIC, now I have just one, and this project don't work, even with so much help...I write so many lines of code but nothing works right...
    This is the last version. Bugs:
    -if press but2, ON/OFF rel2 works fine, but if I press but1 after but2, then rel2 goes OFF and nothing works more, need to disconect power
    -if press but1, ON works, without OFF ; after OFF because of 'check' nothing works more, need to disconect power.
    This is one nightmare !!!
    Hope I don't became verry, verry boring...and I am really sorry about my english...
    Attached Files Attached Files

  13. #13
    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 think this is my worst project
    No arguments here.

    I guess it's the language barrier.

    I've built the circuit you described, and am using the following program ...
    As far as I can tell, it does exactly what you want it to do.
    Code:
    @ DEVICE PIC12F675, intrc_osc_noclkout, wdt_OFF, pwrt_on, mclr_off, bod_off
    
    DEFINE OSC  4
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    
    CMCON = 7
    OPTION_REG  = %10000110
    TRISIO  = %00011110
    ANSEL = %00011000
    ADCON0 = %10001101
    
    adval var Word
    vt var word
    but1 var gpio.3
    but2 var gpio.2
    rel1  var gpio.5
    rel2  var gpio.0
    
    
    main:
    rel1=0
    rel2=0
    
    btn1:
    
    if but1=1 and rel2=0  then
             high rel1 
             pause 20
                              
             while but1=1
             call check
             wend
             pause 20
                                           
             while but1 = 0
             call check
             if rel1=0 then
                GOTO Btn1PressDone
    ;         pause 10
             endif
             wend
             LOW rel1
    
             while but1=1
             wend
             pause 20
    endif
    Btn1PressDone:
    
    
    btn2:
    if but2=1 and rel1=0  then
             high rel2 
             pause 20
                     
             while but2=1
             call check
             wend
             pause 20                          
            
             while but2 = 0
             call check
             if rel2 = 0 then
               GOTO Btn2PressDone
    ;         pause 10
             endif
             wend
             low rel2  
             
             while but2=1
             wend
             pause 20
    endif
    Btn2PressDone:
       
    GOTO MAIN
    
    check:
    adcin 3, adval
     vt=adval * 5000
     vt=div32 1023
    
    if vt > 1250 then
    	gpio.0=0
    	gpio.5=0
    endif
    return
    
    end
    DT

  14. #14
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default

    Thanks for such a fast reply!
    Yes, in ISIS works verry, very fine ! But in real world ( ) the bugs are present !!!! I really don't know what something else I can do...

  15. #15
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default Yes !!!

    This is it !
    Now works how I intend ! Thank You verry, verry much ! The on/off button works fine, and the check procedure too .I hope I write correct this "check procedure" for checking 5 times if is - indeed - overload (?!)
    One last problem : if press but1 and rel1 is high, how can made rel1 low, with but1 - press again, of course - OR BUT2 - press once... ?!? (and some things with but2/rel2).
    I try to write something, but rel1 go low AND rel2 go high...and this is unacceptable...Thanks again for attention and especially to Mr.Darrel for kindness and patience...
    Attached Files Attached Files
    Last edited by fratello; - 23rd July 2009 at 22:56. Reason: problems with language :(

  16. #16
    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
    One last problem : if press but1 and rel1 is high, how can made rel1 low, with but1 - press again, of course - OR BUT2 - press once... ?!? (and some things with but2/rel2).
    I don't understand that.
    Relay1 and Relay2 can never be high at the same time.

    That's because of these statements...
    Code:
    if but1=1 and rel2=0  then
    If Relay2 is on, it won't accept a press of Button1.

    Or maybe I missed the point of the question.
    <br>
    DT

  17. #17
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default

    But1 make rel1 high at first push and low at second push.
    But2 make rel2 high at first push and low at second push.
    It is possible this :
    -but1 make rel1 high at first push and low when push second time but1 OR push but2 ?
    -but2 make rel2 high at first push and low when push second time but2 OR push but1 ?
    So, rel1 ON with but1 , and OFF with but1 OR but2 ; rel2 ON with but2, and OFF with but2 OR but1. Hope now You understand me;I am really verry sorry for my poor english...
    Thank You !


    ....me again. This is my working variant !
    In check: procedure I write this :
    if rel1 = 1 and but2 = 1 then
    low rel1
    pause 500
    goto Btn1PressDone:
    endif

    if rel2 = 1 and but1 = 1 then
    low rel2
    pause 500
    goto Btn2PressDone:
    endif
    In ISIS don't work, but in fact yes ! I don't understand why, but...Maybe You have another variant, much better; it's a good way to learn more. Still don't know if rel (1 or 2) stop if overload detected, only AFTER checking this overload for 5 times...
    Last edited by fratello; - 24th July 2009 at 08:14. Reason: ...not so young but restless ... ;)

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


    Did you find this post helpful? Yes | No

    Default

    OK, I see what you mean now.

    Try this ...
    Code:
    btn1:                   'actionare buton up
    
    if but1=1 and rel2=0  then
             high rel1
                                     
             pause 20
                              
             while but1=1 
             call check
             wend
             pause 20
                                           
             while but1 = 0 AND but2=0      
             call check
                      if rel1=0  then
                      GOTO Btn1PressDone
                      endif
             wend
             LOW rel1
    
             while but1=1 OR but2=1
             wend
             pause 20     
    
    endif
    Btn1PressDone:
    And yes, the check: routine seems to work "only after 5 times".
    DT

  19. #19
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default

    I am speechless...THANK YOU VERRY MUCH ! Works like a charm ! Great job, You are verry, verry good in this...
    Great forum, I am proud for visiting him. All the best for everyone, wherever you are !

  20. #20
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default

    I have tested this module on my car ; works verry fine, like I expect.Since this will be use on car, I think this is one good ideea to minimize the consumption.So I try to write something...Please take one advice...Thanks !
    Attached Files Attached Files

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


    Did you find this post helpful? Yes | No

    Default

    I think it might be better to ...
    Code:
    main:
        rel1=0
        rel2=0
    @   sleep
        pause 100
    It looks like you have correctly set-up the pic to wake from sleep on PORT change (either switch).

    So then it wakes up ... drives the motor relays as necessary ... and only after the motor is finished, and no buttons are pressed, go back to sleep.

    The two NOP's are only required if it will be jumping to an Interrupt vector on wake up.
    Yours is just continuing where it left off.

    Hmmm, sounds like a powered antenna driver. ??
    <br>
    DT

  22. #22
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default

    Thanks for reply ! I KNOW that YOU are right. ...Now my car has "intelligent" windows !
    ...I think to 'implement' the detection of 'long press button/short press button', but after one short holidays...All the best !

  23. #23
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default

    I'm back ! ...with another challenge :
    - if press short but1 (or but2) the schematic works like before (ON/OFF rel, at every press of but1/but2 or overload detection) ;
    - but...if press long (over 1 sec) but1 (or but2) the relay must be ON as long as the but is press; once the but is release, the relay must go OFF.
    I try to implement some code from Melanie's advices (Thanks !) founded on this forum, but the result are not good...Relay don't go ON not at all ...
    I see this is the way witch work the electric windows on other cars ( with two different type of press: long & short) ; maybe, with - a lot of - help, I make my car (b.t.w. - Logan by Renault !) with really intelligent windows ! Thanks in advance for any advice !
    Attached Files Attached Files

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


    Did you find this post helpful? Yes | No

    Default

    Challenge? ... What challenge?

    Started with a previous version ...
    Code:
    '****************************************************************
    '*  Name    : THE_BUTON_sleep.BAS                         *
    '****************************************************************
    @ DEVICE PIC12F675, intrc_osc_noclkout, wdt_OFF, pwrt_on, mclr_off, bod_off
    
    DEFINE OSC  4
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    
    CMCON = 7
    OPTION_REG  = %10000110
    TRISIO  = %00011110
    ANSEL = %00011000
    ADCON0 = %10001101
    
    GIE var intcon.7 ' global interrupt enable 1=on ; 0=off
    gpie var intcon.3 'port change interrupt enable 1=0n ; 0=off
    gpif var intcon.0 'port change interrupt flag bit
    
    adval var Word
    vt var word
    u  var byte
    cnt var byte
    but1 var gpio.3
    but2 var gpio.2
    rel1  var gpio.5
    rel2  var gpio.0
    
    Timer1    VAR WORD EXT :@Timer1 = TMR1L
    TMR1ON    VAR T1CON.0
    TMR1IF    VAR PIR1.0
    T1Count   VAR BYTE
    LongPress VAR BIT
    T1CON = %00110100
    
    u=0
    cnt=0
    GIE=0
    GPIE=1
    IOC.2=1   ' int-on-change for GPIO.2 enabled
    IOC.3=1   ' int-on-change for GPIO.3 enabled
    
    but1=0
    but2=0
    rel1=0
    rel2=0
    
    main:
      rel1=0
      rel2=0
    @ sleep
      pause 100
      Timer1    = 3037
      T1Count   = 0
      LongPress = 0
      
      btn1:                   'actionare buton up
      
      if but1=1 and rel2=0  then
               high rel1
               TMR1ON = 1 
               pause 20
                                
               while but1=1
               call check
               wend
               IF LongPress THEN Stop_UP
               T1Count = 0        
               pause 20
                                             
               while but1 = 0 and but2 = 0
               call check
               if rel1=0 then
                  GOTO Btn1PressDone
               endif
               wend
        Stop_UP:
               LOW rel1
      
               while but1=1  OR but2 = 1
               wend
               pause 100
      endif
      GPIF=0  'Clear ort change interrupt flag
      
      Btn1PressDone:
      
      
      btn2:               ' actionare buton down
      if but2=1 and rel1=0  then
               high rel2 
               TMR1ON = 1 
               pause 20
                       
               while but2=1
               call check
               wend
               IF LongPress THEN Stop_Down        
               pause 20                          
              
               while but2 = 0  and but1 = 0
               call check
               if rel2 = 0 then
                 GOTO Btn2PressDone
               endif
               wend
        Stop_Down:
               low rel2  
      
               while but2=1 or but1=1
               wend
               pause 100
      endif
      GPIF=0  'Clear ort change interrupt flag
      Btn2PressDone:
       
    GOTO MAIN
    
    check:          ' verificare pentru supracurent
      adcin 3, adval
       vt=adval * 5000
       vt=div32 1023
      
      for cnt = 1 to 5
              if vt > 270 then      
                  u=u+1
                          if u > 5 then
      	                gpio.0=0
                          gpio.5=0
                          endif
                  pause 50
                  goto check            
              else
                  u=0
              endif
      next cnt
      
      IF TMR1IF then
          TMR1IF  = 0
          Timer1  = 3037
          T1Count = T1Count + 1
          if T1Count = 2 then 
            TMR1ON = 0
            T1Count = 0
            LongPress = 1
          endif
      ENDIF
    
    return
    
    
    end             ' of program
    I'll have to charge you for the next one though.
    <br>
    DT

  25. #25
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default

    Mr.Darrel, You are great ! Thank You so much for support; without You, I never ended this project. I wish You all the best !
    PS : I don't understand Your last proposition (because of "the language barrier") but I hope not be crossed with me ! The challenge is for ME ! Hope to learn how much it's possible from You and this forum ! Of course You don't need to compete with nobody ! Greetings from Romania !!!
    Last edited by fratello; - 2nd August 2009 at 08:57.

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


    Did you find this post helpful? Yes | No

    Default

    Sorry, my humor is hard to understand even if you speak english.
    Nothing bad intended.

    I'm glad you got your power windows working the way you wanted.

    Cheers!
    DT

  27. #27
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I'll have to charge you for the next one though.
    <br>
    You still accepting EBeer ?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  28. #28
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default ...still not work...

    OOps ! I have a big problem : but1 don't work proper ! I double/triple check all ; I change the button, but nothing... After a few press on but1 or EVEN on but2, but1 became inopperating ! If press but2, rel2 go high and but1 stop him, but don't make rel1 high ! Or, if rel2 go low because of overload, but1 don't work not at all ! Must disconnect power source for 're-starting' him...
    But2 works verry fine, but but1 don't !!! I really don't understand ! I check everything for so many times, I change even PIC...Please, help...again...

  29. #29
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi fratello,
    2 changes for you to try.
    1.turn WDT timer on in your config.
    2.You have used: Call check in several places, change them to
    GoSub check
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default

    Check the T1CON assignment.
    Make sure it has 8-digits.
    Code:
    T1CON = %00110100
    If it's not 8 digits, or if the digits are different, along with disabling the rel1 output on GP5, it may also make it difficult to re-program the chip.
    <br>
    DT

  31. #31
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default

    Thanks for reply ! The code posted by Mr.Darrel works fine with this two modifications :
    ' @ Sleep
    ' GPIF=0 'Clear port change interrupt flag
    Here are something wrong...and, of course, it's only my fault...

  32. #32
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Great !
    Now I have a related question for Darrel . . .
    Sleep vs @ sleep
    PBP vs ASM ?
    I tried both on John's T flusher code and only @sleep would work
    Am I correct, sleep works with some time designation I. E. Sleep 60 , and @ SLEEP works with interrupts ?
    Last edited by Archangel; - 4th August 2009 at 05:19.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default

    SLEEP vs. @ SLEEP vs. NAP

    PBP's SLEEP command is designed to work with the Watch Dog Timer.
    It sets the WDT prescaler to an appropriate divisor then internally does an @ SLEEP.
    When it wakes-up it decrements a counter and if that counter is still greater than zero, it goes back to sleep.

    The processor may have to go through several hundred or even thousands of sleep/wake cycles before execution of the program will resume. It all depends on the specified period.

    If the WDT is disabled and you are relying on port change interrupts to wake the PIC it will take just as many of those interrupts before the program resumes execution.

    If you are using ASM Interrupts, the ISR will be called on each wake-up. This also may happen several hundred times before the rest of the program can see what happened in the interrupt.

    If you are using ON INTERRUPT, no interrupts will be serviced until after the complete SLEEP command has finished.<hr>
    @ SLEEP in assembly language, simply puts the processor to sleep for 1 sleep/wake cycle. Program execution will resume immediately on the first wake-up. Or if interrupts are enabled, it will jump to the ISR first, then resume were it left off. Although if interrupts are enabled, you <strike>must have 2 NOP's</strike> should have 1 NOP after the @ SLEEP statement to allow the pipeline to load the ISR's first instruction.<hr>
    PBP's NAP command operates much like @ SLEEP, except it changes the WDT prescaler according to the specified period (12F-16F only) before executing an @ SLEEP internally.

    It only waits one sleep/wake cycle.

    hth,
    DT

  34. #34
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    @ SLEEP in assembly language, simply puts the processor to sleep for 1 sleep/wake cycle. Program execution will resume immediately on the first wake-up. Or if interrupts are enabled, it will jump to the ISR first, then resume were it left off. Although if interrupts are enabled, you must have 2 NOP's after the @ SLEEP statement to allow the pipeline to load the ISR's first instruction.
    Thank You Darrel,
    1 sleep / wake cycle ? still not causing sparks across my synapses, Is that OSC/4, Arbitrary countdown of WDT, something conjured using black cat bones and herbs? AND IF WDT is not enabled, will it sleep forever waiting for an interrupt? And if so will that interrupt wake it up?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    1 sleep / wake cycle ? still not causing sparks across my synapses, Is that OSC/4, Arbitrary countdown of WDT, something conjured using black cat bones and herbs? ...
    1 sleep/wake cycle is the process of putting the PIC to sleep, and having it wake-up from one of many reasons.

    If that reason is due to the WDT, it may be more like "Black DOG bones".
    The WDT isn't very accurate in most PIC's. And it varies from one Family to another. But essentially it's the base period of the WDT, multiplied by the Prescaler.

    AND IF WDT is not enabled, will it sleep forever waiting for an interrupt? And if so will that interrupt wake it up?
    Yup! She'll pull a "Sleeping Beauty" until a Prince comes along for a kiss.

    Available Princely possibilities are ...
    From the Midrange Reference.



    Also, Bruce pointed out that the datasheets recommend 1 NOP after @ SLEEP instead of 2.

    Not sure why I thought it was two.
    <br>
    DT

  36. #36
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    <h1> THANK YOU ! </h1>
    That is what I needed confirmation on.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  37. #37
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default

    Yes, it's work now !
    @ DEVICE PIC12F675, intrc_osc_noclkout, wdt_ON, pwrt_on, mclr_off, bod_off
    ...
    @ Sleep
    ...
    GPIF=0
    ...
    Thanks again to all for help ! @ Cheers !

  38. #38
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default

    Works...but don't sleep ! I measure the current and it is all the time about 3.5 mA. Based on "PICadilly 12F675", writen by Ian Burn, I try to re-re-redefine the code. But...even I made like in book, the current consumption it's 3.5 mA !
    " @ DEVICE PIC12F675, intrc_osc_noclkout, wdt_OFF, pwrt_on, mclr_off, bod_off
    ....
    IOCB= %00001100
    INTCON.3=1
    OPTIONS_REG.6=1
    ....
    main:
    ...
    INTCON.0=0
    Pause 100
    @SLEEP
    Pause100
    ... "
    I don't understand why do not work ! I remove the PIC from schematic, and the current consumption is about 2.5 mA; so, the 12F675 consume about 1 mA, all the time and never go to sleep with "less than 1 microamp" !

  39. #39
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi fratello,
    Well you have taken this thread every which away, instead of making new threads for different projects, so we do not really know which schematic and code you are asking about, so only "General" statements can be applied here. First, you are chasing 1 ma out of 3.5 ma, is there any way to kill the 2.5 since it is the bigger portion? Secondly, I do not think you will ever see 1&micro;A, maybe wrong just my opinion. Just before @ SLEEP, I would try tristating the GPIO by TRISIO = 255, disable WPU and in your configs, shut off WDT, and disable MCLRE, you might switch to LP_OSC, to further reduce power. Read this thread, different chip but useful maybe:
    http://www.picbasic.co.uk/forum/showthread.php?t=11325
    Last edited by Archangel; - 7th August 2009 at 18:18.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  40. #40
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default

    Thanks for reply ! I use the schematic from post #1 and the code continuous improved in this thread. I made this changes on the last code posted by Mr.Darell. I say that I use this schematic on automobile ; I think every way to reduce the consumption it's necessary...or maybe the battery of my car give enough current, even I don't start the engine for a long period...It is not a verry big problem, but I want to understand the "mechanism" of the sleep procedure, and I am dissatisfied because, even I try all the variants, the obvious results are not present ! Just I try to make this project almost perfect and I really appreciate the support of all. Sorry if I disturb somebody...or if I became boring...

Similar Threads

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

Members who have read this thread : 1

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