problem programming pic microcontrollers

Discussion in 'Embedded Systems and Microcontrollers' started by gatoulisss, Jan 23, 2015.

  1. gatoulisss

    Thread Starter Member

    Jan 23, 2015
    34
    0
    hello,
    i have a problem with programming my pic microcontrollers...
    im writing a very simple code just to test them
    the programm is about to blink a led. in the simulation the programm running just fine also on the compiler no problems at all the programmer says that the programming ends succesfully but on the circuit nothing works.
    i have test the same program in 5 diferrent pic (3xpic16f84A, 1xpic16f88, 1xpic16f628A) microcontrollers and i have the same problem any help?

    i upload some fotos of the situation. DSC097651.jpg p1.jpg p2.jpg
     
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    Do you have an oscillator hooked up to the PIC? It won't run without one. See Oscillator Configurations (6.2 in the F84A databook) for info. For stand-alone use (without the PICKit) you'll also need a reset network (RC at least) on MCLR.

    On your circuit, you need to put the resistor in series with the LED as RA1 will source current when its set to a '1'.

    What you have WILL work on RA4 however since its open-drain. A side benefit is the on power up, the LED will be ON (RA4 is hi impedence). When the code runs, it initializes the port to '0' shunting the LED. The flash of LED ON then OFF during power up is a nice way to know that the processor is running and at least got to initIO()

    It would be helpful to post your code in CODE tags so that we can test it on our systems. For MikroC, also post what your project settings are (configuration fuzes etc), preferably in comments in the source code.
     
    Last edited: Jan 23, 2015
  3. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
    Do you have digital I/O enabled, IOW analogue off.
    Max.
     
    JohnInTX likes this.
  4. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    Good call. That wouldn't be an issue on the F84A in use but definitely required for the other two he mentioned.
     
  5. gatoulisss

    Thread Starter Member

    Jan 23, 2015
    34
    0
    yes i have the digital I/O enabled on pic16f88 but again nothing

    here is the code


    void main() {

    trisa1_bit=0;
    for(;; ){
    porta.f1=1;
    delay_ms(1000);
    porta.f1=0;
    delay_ms(1000);
    }
    }

    about the fuses i have watchdog off and internal oscillator checked
     
  6. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    You have to clear ANSEL in the code to make RA1 digital for the 16F88. Your previous post was for the 16F84A. These have different requirements to configure the IO.

    In addition to the the WDT and INTOSC fuses, if you don't pull up MCLR externally, be sure to disable MCLR with the fuzes and enable the PowerUp Timer (16F88)


    Something like this:
    Code (Text):
    1.  
    2. // This is for 16F88
    3. void main() {
    4.   ANSEL=0;  // all ports digital
    5.   PORTA=0;  // all portA = out 0
    6.   TRISA=0;
    7.   PORTB=0; // all portB = out 0
    8.   TRISB=0;
    9.  
    10.   for(;; ){
    11.   PORTA.F1=1;
    12.   Delay_ms(1000);
    13.   PORTA.F1=0;
    14.   Delay_ms(1000);
    15.   }
    16. }
    17.  
    BTW I changed the case of Delay_ms and PORTx. I run MikroC with case-sensitivity ON and highly recommend that you do so as well.
     
    Last edited: Jan 23, 2015
  7. gatoulisss

    Thread Starter Member

    Jan 23, 2015
    34
    0
    the above code is for the pic16f84a
    i need to find the main problem so i try to program the pic16f84a i just mention the other to so we are sure its not fault of microcontroller.
    when i am trying to compile via mplab i have this error
    PK3Err0033: 4 bytes expected, 0 bytes received

    Failed to properly connect to PICkit 3
    thanks
     
  8. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
    MPLAB is fussy about the sequence for connection to Pickit3, go by the recommendation notes.
    Do not connect pickit3 or power the circuit.
    Compile the code, set Pickit3 as programmer, then connect Pick3, then power the circuit.
    Any other way and it is hit and miss as to if you get the error or not.
    Max.
     
  9. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    The 16F84A does not have an internal oscillator so you'll have to provide one with a crystal, resonator, RC or external oscillator. Any references to INTOSC in your project setup are not for the 'F84A
     
  10. gatoulisss

    Thread Starter Member

    Jan 23, 2015
    34
    0
    so lets try with the pic16f88
    the only change in the code is that i use ansel=1; correct?
    but i continue having the same problem
     
  11. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    ANSEL=0 for all digital.
    Try the code I posted with the additional config settings i.e. MCLR disabled, power up timer ON.

    EDIT: You need to change the LED circuit as I indicated above. If you don't, the IO will not work properly for single bit changes. The schematic you posted is not what you have wired on the picture of the proto-board. You need PORT->resistor->LED->GND.
     
    Last edited: Jan 23, 2015
  12. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    991
    Instead of asking all of these questions lets start wit the basics.

    How do you know it is not running?

    What have you done to debug the code?
    Debug is your friend. It will show you if your code is not running or if it is running help you determine the problem

    Do you have a scope, logic probe? Anything you can use to measure the i/o pin? Make sure it is not your led that is the issue.

    Where are you configuration settings (fuses)? This will determine what OSC is used.

    You should set Latches and read Ports.
     
  13. gatoulisss

    Thread Starter Member

    Jan 23, 2015
    34
    0
    i use same code same bread board but different microcontroler, pc and compliler and it run just fine... the code is ok, something wrong with my computer or programmer(just bought it) or pics
     
  14. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    So.... specifically, if the exact same circuit as wired works in some configuration, what exactly is that configuration?

    Which PIC, which compiler/version and programmer work?

    Which PIC and compiler and programmer don't work?

    Are you saying that the same MicroC on a different computer is the problem or are you changing from XC8 to MicroC or something like that? Which programmer is working and which one isn't?

    Are you sure that you are building for RELEASE and not debug. If you are compiling in MikroC and programming with PK3, it has to be for RELEASE. I assume you are loading the .HEX file from MikroC into the stand-alone programmer app for PK3?

    The code I posted loads and simulates fine for a PIC16F88.
     
  15. MagicMatt

    Member

    Sep 30, 2013
    117
    14
    Just to go back to basics here... there's a verify button on the programming software. That will check that the chip has been programmed ok. If it verifies, the issue is not with the programming procedure or the programmer, but must be your actual circuit, or the program you have written, or both. Does it verify?
     
  16. gatoulisss

    Thread Starter Member

    Jan 23, 2015
    34
    0
    yes it verifying it succesfully


    im studying engineer on electronics and i use my university equipment... also my teacher couldnt find something wrong on my circuit... he said it must be something in microcontrollers wrong but because i ve tested 5 different maybe i have to do somethink first so i can make them work...
     
  17. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Please post your current data for this device.

    Post your schematic, a photo of the current setup, and your current code (including configuration bits for the PIC). In other words, don't mention other chips than the one you intend to use.

    The only reason your issue has persisted this long is because you have not been clear.

    You've mentioned you want to use the 16F88, yet all your images show 16F84A.
     
  18. gatoulisss

    Thread Starter Member

    Jan 23, 2015
    34
    0

    im uploading step by step pictures of what im doing... Photo 29-1-15 - 11 05 52 μ.μ..jpg Photo 29-1-15 - 11 06 18 μ.μ..jpg Photo 29-1-15 - 11 06 25 μ.μ..jpg Photo 29-1-15 - 11 06 32 μ.μ..jpg Photo 29-1-15 - 11 07 40 μ.μ..jpg Photo 29-1-15 - 11 09 49 μ.μ..jpg Photo 29-1-15 - 11 11 14 μ.μ..jpg Photo 29-1-15 - 11 14 54 μ.μ..jpg Photo 29-1-15 - 11 05 52 μ.μ..jpg Photo 29-1-15 - 11 06 18 μ.μ..jpg Photo 29-1-15 - 11 06 25 μ.μ..jpg Photo 29-1-15 - 11 06 32 μ.μ..jpg Photo 29-1-15 - 11 07 40 μ.μ..jpg Photo 29-1-15 - 11 09 49 μ.μ..jpg Photo 29-1-15 - 11 11 14 μ.μ..jpg Photo 29-1-15 - 11 14 54 μ.μ..jpg Photo 29-1-15 - 11 18 16 μ.μ..jpg Photo 30-1-15 - 12 15 32 π.μ..jpg
     
  19. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    Thanks for the comprehensive dumps.

    A few things:

    First, be sure the LED circuit is correct. In the latest photo of the breadboard, it looks like the resistor and LED leads are plugged into different rows - maybe the resistor lead is just bent... Check that then disconnect the blue wire from the PIC and connect it to +5V to make sure that the LED lights up.

    I would adjust your configuration bits as follows In the Project ->Edit Project window:
    Fail-Safe Clock monitor and Internal External Switchover are enabled. Disable them. CONFIG2 = 3FFCh

    Oscillator Selection: INTRC oscillator; CLKO function on RA6.. That way you can probe RA6 to see if the oscillator is running. If you don't have a scope, a DVM should read about 40% of Vdd if its running, Vdd or GND if it isn't.

    Power Up Timer: Enabled. This will give the oscillator time to start. Its recommended if you don't use a MCLR/ network.
    Leave the other stuff disabled as it is. CONFIG1 = 3F19h

    Note that with the internal oscillator, you have to set OSCCON in your code to set the osc frequency. The default frequency is 31KHz. Add OSCCON = 0x60; as the first line of your init code to set the system clock to 4MHz. See section 4.6 of the datasheet. Note that setting 4MHz in MikroC's project setup window does not set the PIC frequency, it only tells MikroC how to calculate delays.

    You might consider better power to the PIC. Bring +5V and GND to the PIC via the busses on the proto board then connect Vdd/Vss with short wires. Decouple Vdd/Vss as close to the PIC as possible with a 1uF tantalum cap in parallel with a .1 ceramic. Usually, PICs will run OK with almost any hookup but since you are having problems, its not a bad idea.

    Be sure to check the basics, power supply voltage, GND etc. Make sure Vpp can go high without fouling your 5V regulator (although if it consistantly programs and verifies, it's probably OK). Verify the oscillator is running.

    I built your code and got essentially the same .HEX image except for some of the delay values. Don't know why that is.

    I would also recommend you do NOT set up your ports like you have. Single-bit changes on the PORTs and especially on TRIS can be cause problems. The preferred way is shown in post #6. Doing things like trisab1_bit=0 frequently does NOT work as expected. Same for PORTs. Search AAC for read-modify-write and r-m-w for lots of info on this problem.

    Finally - again- use CODE tags to post your code. I typed in yours from the photo but you are not making it easy.

    See what that does..
    Good Luck.
     
  20. gatoulisss

    Thread Starter Member

    Jan 23, 2015
    34
    0

    Problem solved!! it was OSCCON = 0x60; missing from the code...! i write it and i program again the pic and everything now works!! thank you a lot!!!
     
Loading...