• AVR Freaks

Hot!PIC16F877A TIMER1 INTERRUPT

Author
carlos.e.carvalho
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2006/10/06 04:14:28
  • Location: Brasil
  • Status: offline
2020/05/25 12:23:08 (permalink)
0

PIC16F877A TIMER1 INTERRUPT

Hello my friends !
 
I've wrote this simple code in C language, but it just doesn't work!
I am trying to use timer1 interrupt to blink Led1.  I put Led2 there just to see if my code was at least running and Led2 bliks fine!
Can someone help me with that ?  I believe it is a simple thing that I am doing wrong, but I couldn't figure that out !
Thanks !

Grameyer Equipamentos Eletrônicos
#1

7 Replies Related Threads

    ric
    Super Member
    • Total Posts : 27637
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC16F877A TIMER1 INTERRUPT 2020/05/25 13:33:28 (permalink)
    +1 (1)
    Have you tried swapping Led1 and Led2 in software, just to make sure they are both wired up right?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    PStechPaul
    Super Member
    • Total Posts : 2725
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: online
    Re: PIC16F877A TIMER1 INTERRUPT 2020/05/25 16:37:59 (permalink)
    0
    Can you check pin 38 (RD0) with a multimeter or scope? I don't see an obvious errors. You don't need the return instruction in the void main() function, but it's not causing any problem.

     
    #3
    dan1138
    Super Member
    • Total Posts : 3625
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: PIC16F877A TIMER1 INTERRUPT 2020/05/25 18:09:32 (permalink)
    +1 (1)
    At a guess this statement:
    Led1 = !Led1;   // complement the value for blinking the LED

    Could be a problem.
     
    This one could perhaps work better:
    Led1 ^= 1;   // complement the value for blinking the LED

    #4
    ric
    Super Member
    • Total Posts : 27637
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC16F877A TIMER1 INTERRUPT 2020/05/25 22:03:05 (permalink)
    0
    dan1138
    At a guess this statement:
    Led1 = !Led1;   // complement the value for blinking the LED

    Could be a problem.

    It generates a lot of code in non-PRO compilers, but it should still work for that pin (and not molest other pins in the same port unless they are in analog mode)
    n.b. if the same was attempted in the main loop, it COULD cause problems, as the generated code keeps a copy of the PORTD register in scratch for several instructions...
     

     This one could perhaps work better:
    Led1 ^= 1;   // complement the value for blinking the LED

    Yes, it generates shorter code (still needs PRO mode to generate most efficient version).
    Is worth trying, but I don't think is the fundamental problem.
     
    It's also worth trying NOT toggling the other LED in the main loop, although that shouldn't be the problem.
     
     
     
    post edited by ric - 2020/05/25 22:07:29

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    1and0
    Access is Denied
    • Total Posts : 10905
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC16F877A TIMER1 INTERRUPT 2020/05/25 23:20:11 (permalink)
    0
    Try connecting the LEDs to different pins and even different ports.
     
    #6
    carlos.e.carvalho
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2006/10/06 04:14:28
    • Location: Brasil
    • Status: offline
    Re: PIC16F877A TIMER1 INTERRUPT 2020/05/26 11:16:53 (permalink)
    0
    Thank you so much for all your suggestions !
    I've found out what the problem is.  I am mounting this circuit on a bread-board, programming with a lap-top and powering the circuit through PICKit3. When I disconnect the lap-top from the main power outlet, my circuit comes to life !  
    I believe that the power line here is putting some EMI on my circuit or something like that...
    Anyway, my code is working ! Just have to make my hardware more resistant.
    Thanks for the code tips too!  I'll implement then !
     

    Grameyer Equipamentos Eletrônicos
    #7
    PStechPaul
    Super Member
    • Total Posts : 2725
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: online
    Re: PIC16F877A TIMER1 INTERRUPT 2020/05/26 11:39:17 (permalink)
    0
    Power supply bypassing capacitors and noise filtering are very important. Sometimes you need to use series inductors and shielding, as well as careful consideration of PCB or protoboard layout. You may also need to provide an earth ground to reduce the antenna and capacitive coupling effect of isolated connections to AC power. It does not need to be a solid ground connection. Sometimes a 10k resistor, with maybe a 47 nF capacitor across it, will suffice.

     
    #8
    Jump to:
    © 2020 APG vNext Commercial Version 4.5