12F675 and interrupt


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2007
    Posts
    11

    Default 12F675 and interrupt

    At first, sorry for borring you with my dumb ass question. Totally newbie trying to do a simple thing and canīt figure it out.

    When a 12f675 pin goes low, another pin goes high (to turn on a lamp). Done.
    When the same pin goes high (by the internall pull-up resistor) the pin with a lamp delay for 5 seconds and fade out (with pwm) to zero. Done.

    But thatīs drive me crazy:

    Iīve need some kind of stuff (code of course) that when:

    If a third ping goes high and if the first pin changes to low or if lamp is in delay, delay was cancelled (but yet fade off)

    Try to do with picbasic interrupt, Darrelīs interrupt and nothing. Can anyone show me some directions, code samples, anything :-)

    Thanks and sorry for the bad English.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by perides View Post
    Try to do with picbasic interrupt, Darrelīs interrupt and nothing. Can anyone show me some directions, code samples, anything :-)
    Let's see your code that doesn't work...

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default

    Hi, Pericles

    "If a third ping goes high and if the first pin changes to low or if lamp is in delay, delay was cancelled (but yet fade off)"
    The simple way ...

    instead of " PAUSE 5000" for the delay ...

    just use

    Code:
    ...
    ' Conditionnal DELAY - tests "Pincancel" pin every 10 ms
    
    FOR I = 1 to 500
     IF Pincancel = 1 THEN jumpover
    PAUSE 10
    NEXT I
    
    jumpover :
    ' Fading sequence
    ...
    That's all !

    Interrupts ... Interrupts ??? What's that for ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Jul 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Thank you all.

    I followed your directions Acetronics but and coded above. Maybe it work, maybe they need some fixes.

    Simulating (no development board in class yet) in proteus, an strange behavior occurs on GPIO.0 they always stays up, even Iīve (I think at least) disabled pullup for them. Other pins appears ok.

    What Iīve missed??

    BTW, Perides, not Pericles. But no problem, common misspelling. :-)


    Code:
    ' Pinout                                                        *
    ' 1 vdd                                             vss 8       *
    ' 2 gp5/t1cki/osc1/clkin           gp0/an0/cin+/icspdat 7       *
    ' 3 gp4/an3/t1g/osc2/clkout   gp1/an1/cin-/vref/icspclk 6       *
    ' 4 gp3/mclr/vpp                gp2/an2/tockin/int/cout 5       *
    '                                                               *
    '****************************************************************
    @ device pic12F675, WDT_OFF, PWRT_ON, MCLR_OFF, INTRC_OSC_NOCLKOUT
    define osc 4
    
    CMCON = 7 'comparator off
    ANSEL = 0 'all digital 
    'VRCON = 0 'comparator off
    
    TRISIO= %000011 '1=in 0=out 
    
    'Enable PULL-UPS
    OPTION_REG.7 = 0 'enable pullu-ps (0 enable/1 disable) 
    WPU = %000010 '1=on/0=off each pullup - enable pull-up only TK
    
    
    L15 var GPIO.0  'line 15
    TK  VAR GPIO.1  'door sensor 
    LAMP VAR GPIO.2 'bulb
    myPWM VAR word
    
    main:
       If TK = 0 Then LAMP = 1 'if TK goes down so LAMP goes UP
            
       IF TK = 1 and LAMP = 1 then 'if TK goes down and LAMP is yet on
          IF L15 = 1 THEN 'and we have canceled delay
             goto justfade 'so go to fade lamp
           else
             GOTO delay 'and if delay was not canceled go to delay+fade
           endif
       ENDIF
    GoTo main
    
    delay:
        FOR myPWM = 1 to 500 '500 loops for 5 second of 10ms delay 
            if L15 = 1 then justfade 'if L15 goes up so end delay
            pause 10 'wait 10ms
        next myPWM
    
    justfade:
        for mypwm = 255 to 1 step -1
            PWM LAMP, myPWM, 255 'pwm bulp
            if TK = 0 then GOTO main 'if TK goes down
        NEXT myPWM
        goto main
    Last edited by perides; - 23rd September 2008 at 15:23. Reason: Added BTW line :-)

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Sorry, but simulator behaviour is something making me laugh too much ...

    my last program didn't want to run on MPSIM ... but has been working more than fine for two weeks now ... ( Was a periodic signal generator, interrupt driven ...)

    sooo, I can't help you further in the virtual world ...

    Alain

    BTW ... Periclčs was for joke ...
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Jul 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Hi Alain

    I agree with you about sims.
    The code appears to be in the right way at least?

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    I never use pullups ...

    you should try to add external resistors ... even on the sim' ...

    you also should avoid PWM command for such uses ... this outputs an awful garbage ( just usable with a RC filter to make a basic D/A converter. )

    as you have written the program ...

    it is easy to do it like that :

    Code:
     for mypwm = 1000 to 0 step -1
            High LAMP
            PAUSEUS myPWM,
            LOW Lamp
            PAUSEUS (1000 -myPWM)
    Next myPWM
    note PAUSEUS has a minimum duration ... but it is not a problem here !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    The code seems to be ok;
    To make it even easier to see, drop the red part.

    Code:
       IF TK = 1 and LAMP = 1 then 'if TK goes down and LAMP is yet on
          IF L15 = 1 THEN 'and we have canceled delay
             goto justfade 'so go to fade lamp
           else
             GOTO delay 'and if delay was not canceled go to delay+fade
           endif
       ENDIF
    
    and, just use this:
    
       IF TK = 1 and LAMP = 1 then delay


    Also, your PWM routine happens so fast that your eyes will not catch the fade effect.
    Have a timer loop, say 5ms, in your pwm loop, like "while : wend" and put your pwm pulse inside this "while : wend". Thus, you have a smooth fade effect.

    None of these modifications will make your GPIO pin work though.
    Just some ideas to make your code better.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

Similar Threads

  1. 12F675 A/D and GPIO sleep interrupt
    By macinug in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th September 2008, 14:39
  2. Interrupt usage
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 20th April 2008, 16:20
  3. ON INTERRUPT not working
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th April 2008, 13:41
  4. Instant Interupts with a 12f675
    By wlundonly in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 26th January 2008, 01:52
  5. inputs on 12F675 (or for that matter any PIC)
    By muddy0409 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th April 2007, 19:43

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