1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

characteristics and apps: PIC16F870

Discussion in 'Microcontrollers' started by sardineta, Oct 1, 2004.

  1. sardineta

    sardineta New Member

    Joined:
    Sep 27, 2004
    Messages:
    131
    Likes:
    0
    Location:
    Cuernavaca Morelos
    I am plannint to turn on 3 leds of 2.1v@15mA by using 3 pins from any port of the micro (AB or C)

    Does any pin from the pic16F870 can support that leds.

    I will use a resistor of 330ohm in series with the output of the pin and in serie with the led, the led will end at GND.

    the manual says source sink 25mA, I think it can support my leds, but one or all leds?

    what does high sink mean?

    Does anyone know a tutorial where I can see EXAMPLES of how to initialize timers and interrupts and how to use them. I have already read tutorials but i need examples.
     
  2. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,205
    Likes:
    640
    Location:
    Derbyshire, UK
    ONLINE
    The PIC can feed LED's no problem, check my PIC tutorials where I have examples.

    The hardware extras sections also explains 'sink' and 'source', with the LED to GND the PIC is working in 'source' mode - with current coming out of the PIC to the LED.

    One of the tutorials also uses a timer and interrupts to multiplex a double seven segment LED display.
     
  3. sardineta

    sardineta New Member

    Joined:
    Sep 27, 2004
    Messages:
    131
    Likes:
    0
    Location:
    Cuernavaca Morelos
    Nigel

    the pull-ups resistors, what advatages can gave me?
    because they are automatically disable when the port is configured as output, but when the port is configured as input? I know that it is software configurable.

    The open drain collector, means that i should put an external resistor, what value is recommended?

    if I use this open drain collector pin does the input signal I read is inverted or is as it is; 5v = logic 1, 0v = logic 0

    thanks
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,205
    Likes:
    640
    Location:
    Derbyshire, UK
    ONLINE

    It allows you to use switches to ground, without adding an external pull-up resistor.

    It depends entirely what you want to use it for, as far as I'm aware it has the same 25mA maximum current as the rest of the I/O pins - so anything over 200 ohms would be OK.

    It's still the same.
     
  6. sardineta

    sardineta New Member

    Joined:
    Sep 27, 2004
    Messages:
    131
    Likes:
    0
    Location:
    Cuernavaca Morelos
    impedance

    What is the inpedance of any pin port when they are configured as inputs?
     
  7. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,205
    Likes:
    640
    Location:
    Derbyshire, UK
    ONLINE
    Re: impedance

    Have a look at the datasheet, it may well tell you, but it's a CMOS logic input and is pretty high - I've never really seen any reason to try and find out?.
     
  8. sardineta

    sardineta New Member

    Joined:
    Sep 27, 2004
    Messages:
    131
    Likes:
    0
    Location:
    Cuernavaca Morelos
    I did an "AND GATE" with two diodes 1N4148, I will connect two push buttons that when any of two is closed will produce an 0 logic, al least.

    so this two signals will control the MCLR#, if the two push buttons are normally open as they are then I will have 5 volts, so the reset will be desactivated, if some of the are pressed then the reset is generated.

    Hope this is a high impedance, more that 1 Megaohm, because if not, the voltage will drop and I'll never will see any accion

    thank you, Nigel
     

    Attached Files:

    • and.jpg
      and.jpg
      File size:
      12.2 KB
      Views:
      1,545
  9. Exo

    Exo Active Member

    Joined:
    Sep 18, 2003
    Messages:
    1,953
    Likes:
    1
    Location:
    Belgium
    You don't need the diodes, Just use 1 pullup resistor on mclr (10K or something), and connect both switches between mclr and ground.
    Pressing eighter one will pull mclr low.
     
  10. sardineta

    sardineta New Member

    Joined:
    Sep 27, 2004
    Messages:
    131
    Likes:
    0
    Location:
    Cuernavaca Morelos
    Great Idea

    I do not believe it, it is a great idea, I was thinking on something robust, because one push button is for a local reset near the uC, and the other one is for a push button is for a remote reset, it will be at a distance of 30 meter.

    what do you think about glitches
     
  11. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,205
    Likes:
    640
    Location:
    Derbyshire, UK
    ONLINE
    You should certainly put a capacitor from MCLR to GND, I'm rather dubious about having a 30 meter long wire on a reset pin!. An obvious answer to cure any potential problems is to use a relay for the remote switch - good old crude stuff is often more robust!.
     
  12. sardineta

    sardineta New Member

    Joined:
    Sep 27, 2004
    Messages:
    131
    Likes:
    0
    Location:
    Cuernavaca Morelos
    ok, that changes all, the second SW (S2), will be controlled by a relay, I will look for one, if I have one DC relay, it just is fed to for example +5v to gnd, isn' it?.

    another question

    Is it possible to read and write of the same port at the same time, I mean if I put a 0 or a 1 in PTOB.1 at the same time I can read PTOB.8?
     
  13. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey
    i believe that writing to the port , actually reads the port then writes to port.
    i read that somewhere..

    the pic does a read before write , on every write ..
    hope this helps
     
  14. sardineta

    sardineta New Member

    Joined:
    Sep 27, 2004
    Messages:
    131
    Likes:
    0
    Location:
    Cuernavaca Morelos
    thanks I hope what you say be true, because if not it will be painful
    (i think because many bcf, bsf to write just one bit, while btfsc and btfss will read just one bit, however this instruccions force me to jump).



    The PIC 16F870 has two Vss, I use one for the oscillator, and the other for the circuits or it really does not matther.?

     
  15. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,205
    Likes:
    640
    Location:
    Derbyshire, UK
    ONLINE
    You can't read and write with the same instruction, you can either read OR write a single bit (witht the commands you mentioned above), or you can read OR write the complete port.

    A lot depends what you are trying to do.

    They just both need connecting to ground, there's no particular distinction between the pins - but you most ground BOTH of them.
     
  16. sardineta

    sardineta New Member

    Joined:
    Sep 27, 2004
    Messages:
    131
    Likes:
    0
    Location:
    Cuernavaca Morelos
    Thanks a lot, The tutorials you have in the site are pretty good,
    do you have any example of timers?

    I am using the 16F870

    Does TIMER0 can be reprogrammed by the user?

    I have a dip switch of 4 positions, 3 of them will be used to define by hardware the correspnding TIME DELAY
    20 ms................111
    100 ms..............110
    300 ms..............101
    200 ms..............100
    1000 ms............011

    the other 3 possible positions will not be taken into account.

    I'll use it to start a time delay when an event is presented at RB0/INT
    and if I have 111, then I know that I will wait just 20ms and if the event persists then I have to stop the system.

    And if before an event occurred and have passed 30 minutes, then I will clean my registers where events are counted.

    How it can be possible? I still can't imagine!,
    does timer0 and timer1 and even timer2 can work simultaneusly without delaying the other process of the microcontroler, as delays do
     
  17. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey
    what you are asking , i think , is how do you make decisions with a pic..
    you do this by using the BTFSC- Bit Test F Skip if Clear instruction.
    and the BTFSS - Bit Test F Skip if Set instruction..
     
  18. JohnBrown

    JohnBrown New Member

    Joined:
    Apr 26, 2004
    Messages:
    141
    Likes:
    0
    Location:
    Surrey, England
    Nigel Goodwin wrote:
    Without wanting to muddy the waters too much, I think you'll find that BSF and BCF not to mention a bunch of others, are all read-modify-write instructions. There have been many times when I have wished that BSF wasn't, but that's how I know that it is!
     
  19. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey
    you use the delay as a subroutine..a block of code that is "Called" when needed.
    when an event is presented to RB0/INT you would test the DIP Switch.
    then jump to a subroutine depending the position of the switches.
     
  20. sardineta

    sardineta New Member

    Joined:
    Sep 27, 2004
    Messages:
    131
    Likes:
    0
    Location:
    Cuernavaca Morelos
    Ok guys, I got it.

    but delays are time consuming, the uC can't do anything else, just the delay, my question is, can I use timer0, timer1, and ADC run at the same time?.

    for example if I got a interrupt form RB0, then timer0 runs, when the delay time is running I want to sample an analog signal from AN0. When the timer0 has reached n times the value i need (counterA), then timer0 will run still, with another counter (counterB) I will tried to reach a time, lets say 3 min, if no other even occur, if so this last counter will be cleared. and so on

    that's why i want to know if timers, adc can work simultaneusly, delays, stay at the rutine up to the end
     
  21. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,205
    Likes:
    640
    Location:
    Derbyshire, UK
    ONLINE
    There are many things that can appear to run simultaneously (even if many of them actually don't), it's all a question of programming it accordingly.

    But there's no magic 'this will work for everything', you have to program each case on it's merits - probably a mixture of polling and interrupts, depending what you are wanting to do.

    Try asking about EXACTLY what you want to do!.
     

Share This Page