Problems with 12F675


Closed Thread
Results 1 to 40 of 67

Hybrid View

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

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


    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.

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

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

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


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

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

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

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


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

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

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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by fratello View Post
    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..
    Some problem !!!!

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


    Did you find this post helpful? Yes | No

    Default

    I change the resistors from transistors base with 2k2 instead 4k7; nothing !!!
    I change the transistors (BC337) with others (2SC1815; 2SC9014) but the results are all the time the same : after couple of pressing on but1 OR but2 (doesn't matter !) but2 (and rel2) works fine but but1 (rel1-of course) became inopperating !
    Attached Images Attached Images  
    Last edited by fratello; - 8th August 2009 at 14:27. Reason: ...picture of two modules

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


    Did you find this post helpful? Yes | No

    Default

    Hi Fratello,
    Ok, in the crude drawing I posted, R3 is selected to limit the current going through the relay coil. r1 is selected to limit current going into the transistor's base, and R2 is the trick. R2 needs to be smaller than R3, but not so low a value so as to inhibit the transistors operation. R2 will increase the ON current, but should help drive the transistor to "cut off".
    in this link:http://engr.astate.edu/jdg/Electroni...orBiasing.html
    Scroll down to Figure 5.
    RC is your relay coil represented as a resistor
    R1 is the resistor from the pic port, I know it is shown as connected to Vcc, but when your port goes high that is exactly what you have
    R2 is the "pulldown resistor, causing cutoff
    RE is the current limiting resistor for the load.
    Attached Images Attached Images  
    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.

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


    Did you find this post helpful? Yes | No

    Default

    The problem are sure somewhere in the code ! The same code, how I say earlier, work if @SLEEP (and just this command !!!) is disabled !!!
    Like in the previous code, which work - for real !- just after adding little pause in different places, I think this code is good, but need...something, I don't know what ! I spend all my day trying different variant of code...with pause from 20 to 100, but useless...I don't lose my hope ! Cheers !

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