Old analog guy needs help with PIC16F57


Closed Thread
Results 1 to 32 of 32
  1. #1
    Join Date
    Jan 2009
    Posts
    22

    Question Old analog guy needs help with PIC16F57

    So I'm venturing away from the PIC16F168A and it's internal oscillator for the first time ever. I need to drive an old BIT display with +5v and -5v. I bought the PIC16F57 because it has enough I/Os to do the job. So I go into the data sheet and after reading it over and over (8 hours worth!), I'm thoroughly confused about the resonator setup. I bought some Murata CSTLS20M0X53-B0 20 MHZ resonators, but now I'm not sure if I can use them. If I can use them, how is the resonator connected to the IC correctly?

    Now for the code ... if I could get an example of a simple code to toggle a port from low to high a few times a second, I can figure out the rest. Any help at all is greatly appreciated!

    ~ Dave

  2. #2
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Angry Still struggling ...

    I tried programming the following code onto two different brand new ICs.

    Code:
    loop:
    
    high portb.4    ' turn the LED on
    pause 500       ' wait 500ms
    low portb.4     ' turn the LED off
    pause 500       ' wait 500ms
    goto loop       ' repeat
    I'm getting a popup that says "Device not blank. Program anyway?" and when I click yes, I get the error "Code programming error at 0000."

    The program is compiled for the PIC16F57 and I made sure that I selected the correct IC in the programmer. I'm bummed.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Looks like a device programmer issue. Usually this error is caused by a too low VPP voltage on MCLR, and/or poor power supply filtering.

    Which programmer are you using? If it's a JDM based + you're using a USB to Serial adapter, then yes, you run into usual problems.

    You can try to erase the device, then reprogram it...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    I think I already have seen something like that on the Forum ...

    So ...

    1) Which is the programmer ???

    2) Is it "up to date" for soft version ???

    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 " !!!
    *****************************************

  5. #5
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    OK, I think I've found the problem. The voltage pins are in odd places on this IC, so I may have to do in-circuit programming; something else that I've never done. I'm going to figure out how to do that next and I'll get back with any results.

    Here's the code that I'll be using for a test:

    Code:
    @ device  pic16F57, hs_osc, wdt_off, protect_off
    
    main:       
    
    high portA.0
    pause 500
    low portA.0
    pause 500
    goto main
    I'm using the old serial programmer and my first problem was not having the cable plugged into the correct header and the IC pin 1 was in the wrong place. Even now with the cable plugged into the correct header and the IC in the ZIF socket correctly, I'm getting a code programming error at 0000.
    Last edited by yankee; - 23rd February 2009 at 16:22. Reason: A better reply.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    The 16F57 is laid out really funky with Vdd on pin #2, Vss on pin #4, Vpp, pgmdata, pgmclock, etc all in odd places, so there's probably not any ZIF adapter compatible with this one.

    Wire it for in-circuit like shown here: http://melabs.com/support/icsp.htm
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Thanks again Bruce!

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


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by Bruce View Post
    The 16F57 is laid out really funky with Vdd on pin #2, Vss on pin #4, Vpp, pgmdata, pgmclock, etc all in odd places, so there's probably not any ZIF adapter compatible with this one.

    Wire it for in-circuit like shown here: http://melabs.com/support/icsp.htm
    Hi Bruce ...

    Microchip AC 162049 Universal adapter CAN do it ...

    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 " !!!
    *****************************************

  9. #9
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Alain,

    Yep. That would do it, but it might be easier and a lot cheaper to just wire his PIC for in-circuit directly to his MeLabs serial programmer..;o}
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  10. #10
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default Resonator

    OK, I made up an adapter cable and programmed the IC. I can't get it to run and I suspect the resonator or the way that I have the resonator setup. I read the data sheet and I'm thoroughly confused. I'm using Murata CSTLS20M0X53-B0 20 MHZ resonators. Is this an OK resonator and if so, how should it be connected?

    ~ Dave

  11. #11
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    3-pin resonators normally have built-in caps. The center pin goes to ground. The remaining two pins go to the PIC external osc pins. For 20MHz you'll want HS_OSC.

    It's a lot easier for folks here to help if you show all your code & config settings.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  12. #12
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Sorry ... here's the code:

    Code:
    @ device  pic16F57, hs_osc, wdt_off, protect_off
    
    main:
    
    high porta.0
    high porta.1
    high porta.2
    high porta.3
    high porta.4
    high porta.6
    high porta.7
    high portb.0
    high portb.1
    high portb.2
    high portb.3
    high portb.4
    high portb.5
    high portb.6
    high portb.7
    
    pause 2000
    
    low porta.0
    low porta.1
    low porta.2
    low porta.3
    low porta.4
    low porta.6
    low porta.7
    low portb.0
    low portb.1
    low portb.2
    low portb.3
    low portb.4
    low portb.5
    low portb.6
    low portb.7
    
    pause 2000
    
    goto main

  13. #13
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Warning warning :-)

    It is not really recommended to modify bits like that quickly after each other. There is something called READ-MODIFY-WRITE problem and that could be what you are having. I also notice that you have not set the TRIS register for the port (telling the port to be input or putput) but that should be taken care with high and low but I rather do it myself.

    Try to blink with just one LED och with the entire PORT i.e

    main:
    TRISB=0
    here:
    PORTB=0
    Pause 2000
    PORTB=255
    pause 2000
    goto here

    end

    Save the A port for later since it is usually the port that has most Analog stuff that can also be causing problems.


    And most important: Don't give up!! It is quite normal to have some problems getting started.
    Last edited by Jumper; - 28th February 2009 at 05:52.

  14. #14
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    What Jumper said + you'll want to place DEFINE OSC 20 in the top section when using
    a 20MHz resonator. PBP assumes a 4MHz oscillator if you leave the define out.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  15. #15
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Still nothing.

    Is a Murata CSTLS20M0X53-B0 20 MHZ resonator suitable for this IC?

    I have the two outside leads connected to OSC1 and OSC2. The center pin is connected to ground.

    I checked continuity and everything appears to be OK. I also checked the LED and it functions OK.

    Here's the code that I tried:

    Code:
    @ device  pic16F57, hs_osc, wdt_off, protect_off
    
    DEFINE OSC 20
    
    main:
    TRISB=0
    here:
    PORTB=0
    Pause 2000
    PORTB=255
    pause 2000
    goto here
    
    end

  16. #16
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Specs on the resonator look fine so it should work.

    I programmed one in-circuit this weekend with a PICKit2 and MeLabs USB programmer.
    Both worked fine.

    Do you have an external pull-up on /MCLR?

    Have you tried reading it back with your programmer to verify config settings?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  17. #17
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Reading back produces this in the code tab:

    Code:
    0000- 006c 002b 0cff 01eb 0703 01ec 0703 0a1f 
    0008- 0c03 002a 0ce7 090e 0a02 006a 0029 0cfc 
    0010- 01e9 026a 0703 0a1a 0cff 0000 01e9 0603 
    0018- 0a15 01e9 0004 03ea 0a14 0800 0003 04c4 
    0020- 04a4 0004 0800 0064 0683 0a31 0663 0a31 
    0028- 0213 0002 0217 0005 0218 0006 0219 0007 
    0030- 0800 0cff 0033 0037 0038 0039 0c1a 0036 
    0038- 0078 0040 0006 0066 0c07 002c 0cd0 0063 
    0040- 0901 0cff 0026 0c07 002c 0cd0 0063 0901 
    0048- 0063 0a3b 0063 091e 0063 0a4a 0fff 0fff
    Everything else is "0fff."

    The configuration tab produces:

    Code:
    0000- 0ffa
    I did not have MCLR pulled up, so I tried a 10k resistor. Still nothing.

  18. #18
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    I also tried a 4.7k and still nothing.

  19. #19
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Are you disconnecting the programmer after programming, and running the PIC on its own power supply?

    You should also have a separate power supply for the PIC during ICSP. I.E. not trying to power it directly from the programmer.

    If you are, then try this.

    1. Program the part with your original .hex file.
    2. Read it back with your programmer, and save the .hex file with another name.
    3. Now open the new .hex file you just saved, and click the C box on the right.

    Does it show the correct config settings?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  20. #20
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    I'm not using ICSP. I made up an adapter cable to go directly from the programmer to the IC on a bread board.

    I'm then disconnecting the program cable and testing the IC with an external power supply.

  21. #21
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Have you tried the read-back yet?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  22. #22
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Yes, same exact results as above.

  23. #23
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Strange. I would try another resonator or crystal.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  24. #24
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    What code did you use?

  25. #25
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Code:
    @ device  pic16F57, hs_osc, wdt_off, protect_off
    
    DEFINE OSC 20
    
    Time VAR BYTE
    
    TRISB = 0  ' all outputs
    Time = 10
    
    Main:
        PORTB = 0
        PAUSE Time
        PORTB = 255
        PAUSE Time
        Time=Time+10
        IF Time >= 250 THEN Time = 10
        GOTO Main
        
        END
    Source and .hex attached.

    Note: You can't disable /MCLR on this one, so make sure you have the external pull-up.
    Attached Files Attached Files
    Last edited by Bruce; - 2nd March 2009 at 16:14. Reason: /MCLR pull-up
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  26. #26
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    OK, when I open your code with the programmer the configuration reads:

    Code:
    0000- 000a
    After I install it on the IC, then read it, this is what I get:

    Code:
    0000- 0ffa
    I have no idea if this means anything or not.

  27. #27
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Interesting. I opened the same .hex file, and it looks llike the attached.

    hs osc, wdt off, protect off.

    Sounds like something odd going on with your programmer, or you're not
    selecting the correct PIC?
    Attached Images Attached Images  
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  28. #28
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    OK, now I'm really confused. My snappy is attached and compared to yours.
    Attached Images Attached Images  

  29. #29
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    What other options do you have enabled/disabled? See attached.
    Attached Images Attached Images  
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  30. #30
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    I compared yours to mine and the only thing that I didn't have checked was "reread file before programming." I made mine match yours, tried again and still nothing. I did a read and the configuration on the IC is still 0000- 0ffa.

    When you do a read, what do you get on your configuration?

  31. #31
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    When you do a read, what do you get on your configuration?
    0ffa, which is correct.

    Have you tried another resonator or crystal?

    You might also try XT OSC - just in case you're over-driving the one you have.

    I use resonators for pretty much everything, and have never had a single problem
    with one, but I've never used the type you're using.

    Trying a different resonator or crystal could save you a lot of work.

    And if you're using a bread board it wouldn't hurt to meter every single connection.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  32. #32
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Different resonators brought the IC to life.

    ~ Dave

Similar Threads

  1. pic18f analog comparator problem
    By david.silaghi in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th May 2009, 09:38
  2. 16F88 Analog In
    By Mugelpower in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 25th March 2008, 08:30
  3. Selection of analog ports
    By enauman in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th December 2006, 03:56
  4. Many Analog Inputs
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 10th July 2006, 08:15
  5. analog inputs on 16F716
    By schwinn_rider in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th October 2005, 04:07

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