Powered by Invision Power Board


Forum Rules Forum Rules (Please read before posting)
  Reply to this topicStart new topicStart Poll

> PIC mcu not starting code by itself
stanigator
Posted: September 22, 2007 07:04 am
Reply to this postQuote Post


Newbie
**

Group: Members+
Posts: 35
Member No.: 10,171
Joined: July 16, 2007




I have managed to get a sample code of blinking the LEDs compiled and
built into a hex file. I have managed to write the code onto a
PIC18F2620 using a PICKIT2 programmer using pk2 in ubuntu. However, I
can only run the microcontroller when I type in "pk2 -on" to turn on
the power supply from the computer to the mcu. If I try to run the
control code without a pk2 connected to be supplying the computer
power supply to the mcu circuit (i.e. only connecting Vdd and Vss pins
to the DC power supply and output pins), it seems that the code never
executes. I'm suspecting that I'm doing something wrong with the MCLR
pin. I haven't enclosed any software coding b/c I'm currently
suspecting that it's a hardware problem. Does anyone have any ideas?
PMEmail Poster
Top
mankku
Posted: September 22, 2007 07:20 am
Reply to this postQuote Post


Forum Addict ++
*******

Group: Spamminator Taskforce
Posts: 3,613
Member No.: 9,683
Joined: June 05, 2007




Check that the MCLR pin is high... Also you'll need a clock source if you're not using the internal oscillator...

The clock is needed to make the uC move forward in the program... Only connecting power but having no clock means no progress... Unless you've setup to use the internal clock, but you didn't mention that...

Mankku
PMEmail PosterUsers Website
Top
spency
Posted: September 22, 2007 08:39 am
Reply to this postQuote Post


Newbie
*

Group: Members+
Posts: 7
Member No.: 11,143
Joined: September 21, 2007




Could you post your code and wiring diagram?


--------------------
PMEmail PosterUsers Website
Top
Colt45
Posted: September 22, 2007 04:39 pm
Reply to this postQuote Post


Forum Addict ++
*******

Group: Trusted Members
Posts: 4,300
Member No.: 1,333
Joined: October 02, 2004




throw a 10k pullup on /MCLR, and make sure you've got some sort of osc...

make sure you've got the right fusebits set for the osc that you are using too.


--------------------
>]:::|-
PMEmail PosterICQ
Top
PIC
Posted: September 24, 2007 02:05 am
Reply to this postQuote Post


Forum Addict ++
*******

Group: Cleanup Taskforce
Posts: 1,052
Member No.: 6,662
Joined: October 08, 2006




Make sure the LVP (low-voltage programming) fuse is unchecked. Also tie the MCLR pin high.
PM
Top
stanigator
Posted: September 24, 2007 05:46 am
Reply to this postQuote Post


Newbie
**

Group: Members+
Posts: 35
Member No.: 10,171
Joined: July 16, 2007




In terms of the schematic diagram, I think it would be simpler to say that pin 1 (MCLR) is connected to 5V through a 10k pull-up resistor, pin 8 to 5V, pin 19 to ground, pin 20 to 5V, and each of pins 21-28 (port B ) has a 1k resistor and LED connected in series from the output to ground.

The following is the code that I'm using in Piklab and sdcc compiler-syntax. I'm sure that LVP has been turned off by verifying _conf4 in the header with the PIC18F2620.h. Also, I have tried switching _conf3 between enabling and disabling MCLR, but the mcu just won't initiate without having my pickit2 connected, having pk2 command the programmer to turn on. By looking at _conf0, internal RC oscillator is used in mode 2, so there is an oscillator set up.

CODE

#include "/usr/share/sdcc/include/pic16/pic18fregs.h"

// Set the __CONFIG words:
code char at __CONFIG1H _conf0 = _OSC_INTIO7_1H;
code char at __CONFIG2L _conf1 = _BOREN_OFF_2L;
code char at __CONFIG2H _conf2 = _WDT_DISABLED_CONTROLLED_2H;
code char at __CONFIG3H _conf3 = _MCLRE_MCLR_ON_RE3_OFF_3H;
// switched to enable MCLR, disable RE3
code char at __CONFIG4L _conf4 = _LVP_OFF_4L;
code char at __CONFIG5L _conf5 = _CP_0_OFF_5L & _CP_1_OFF_5L;
code char at __CONFIG5H _conf6 = _CPD_OFF_5H & _CPB_OFF_5H;
code char at __CONFIG6L _conf7 = _WRT_0_OFF_6L & _WRT_1_OFF_6L;
code char at __CONFIG6H _conf8 = _WRTD_OFF_6H & _WRTB_OFF_6H & _WRTC_OFF_6H;
code char at __CONFIG7L _conf9 = _EBTR_0_OFF_7L & _EBTR_1_OFF_7L;
code char at __CONFIG7H _conf10 = _EBTRB_OFF_7H;

//void init_cpu() {
/* INT Osc with 8MHz */
// OSCCON = 0x70;        /* 01110000 */
//}

void delay(int dly)
{
  while(--dly > 0)
    dly = dly;

}

void main()
{
  OSCCON = 0x70;   // Int osc at 8 MHz
                   // See p. 30 of 18F2620 data sheet

  ADCON1 = 0x0f;   // All ports digital
                   // See 18F2620 data sheet, p. 94
  ADCON2 = 0x05;   // Set AN10-AN12 on PORTB as digital I/O
                   // See p. 224 of 18F2620 data sheet

  TRISB = 0;       // All PORTB lines as outputs

  while(1)
  {
     PORTB = 0x55; //  Flash 8 LEDs on PORTB in checkerboard pattern
     delay(1000);  //  at approx 5 Hz
     PORTB = 0xAA;
     delay(1000);
  }
}


This post has been edited by stanigator on September 24, 2007 06:10 am
PMEmail Poster
Top
mankku
Posted: September 24, 2007 09:23 am
Reply to this postQuote Post


Forum Addict ++
*******

Group: Spamminator Taskforce
Posts: 3,613
Member No.: 9,683
Joined: June 05, 2007




Make sure that you have a decent capacitor on the supply lines, as flashing the LEDs may cause significant voltage dips... This would cause your uC to reset...

Mankku
PMEmail PosterUsers Website
Top
PIC
Posted: September 24, 2007 10:26 am
Reply to this postQuote Post


Forum Addict ++
*******

Group: Cleanup Taskforce
Posts: 1,052
Member No.: 6,662
Joined: October 08, 2006




Hi

Try adding: OSCTUNE = 0

PM
Top
stanigator
Posted: September 25, 2007 06:41 am
Reply to this postQuote Post


Newbie
**

Group: Members+
Posts: 35
Member No.: 10,171
Joined: July 16, 2007




Tried to add OSCTUNE register settings shown in the following; didn't work:

CODE

#include "/usr/share/sdcc/include/pic16/pic18fregs.h"

// Set the __CONFIG words:
code char at __CONFIG1H _conf0 = _OSC_INTIO7_1H;
code char at __CONFIG2L _conf1 = _BOREN_OFF_2L;
code char at __CONFIG2H _conf2 = _WDT_DISABLED_CONTROLLED_2H;
code char at __CONFIG3H _conf3 = _MCLRE_MCLR_ON_RE3_OFF_3H;
// switched to enable MCLR, disable RE3
code char at __CONFIG4L _conf4 = _LVP_OFF_4L;
code char at __CONFIG5L _conf5 = _CP_0_OFF_5L & _CP_1_OFF_5L;
code char at __CONFIG5H _conf6 = _CPD_OFF_5H & _CPB_OFF_5H;
code char at __CONFIG6L _conf7 = _WRT_0_OFF_6L & _WRT_1_OFF_6L;
code char at __CONFIG6H _conf8 = _WRTD_OFF_6H & _WRTB_OFF_6H & _WRTC_OFF_6H;
code char at __CONFIG7L _conf9 = _EBTR_0_OFF_7L & _EBTR_1_OFF_7L;
code char at __CONFIG7H _conf10 = _EBTRB_OFF_7H;

//void init_cpu() {
/* INT Osc with 8MHz */
// OSCCON = 0x70;        /* 01110000 */
//}

void delay(int dly)
{
  while(--dly > 0)
    dly = dly;

}

void main()
{
  OSCTUNE = 0;  // oscillator tuning register:
  // internal oscillator low-frequency source select bit disabled
  // frequency multiplier PLL for INTOSC enable bit disabled
  // center frequency

  OSCCON = 0x72;   // Int osc at 8 MHz
                   // See p. 30 of 18F2620 data sheet

  ADCON1 = 0x0f;   // All ports digital
                   // See 18F2620 data sheet, p. 94
  ADCON2 = 0x05;   // Set AN10-AN12 on PORTB as digital I/O
                   // See p. 224 of 18F2620 data sheet

  TRISB = 0;        // All PORTB lines as outputs
  //RCON = 0x0f;  // reset control register: default interrupt priority, hardware reset

  while(1)
  {
     PORTB = 0x55; //  Flash 8 LEDs on PORTB in checkerboard pattern
     delay(10);  //  at approx 5 Hz
     PORTB = 0xAA;
     delay(10);
  }
}
PMEmail Poster
Top
gramo
Posted: September 25, 2007 08:41 am
Reply to this postQuote Post


Forum Addict
******

Group: Trusted Members
Posts: 625
Member No.: 8,536
Joined: March 06, 2007




QUOTE (stanigator @ September 24, 2007 05:46 am)
In terms of the schematic diagram, I think it would be simpler to say that pin 1 (MCLR) is connected to 5V through a 10k pull-up resistor, pin 8 to 5V, pin 19 to ground, pin 20 to 5V, and each of pins 21-28 (port B ) has a 1k resistor and LED connected in series from the output to ground.

From what I gathered there, you said

Pin 1: 5V via 10K Resistor
Pin 8: 5V
Pin 19: GND
Pin 20: 5V



You aware that Pin 8 should be a ground? I shudder to imagine what would happen internally connecting it to 5V

Here's a quick how-to guide for wiring up a pic http://users.tpg.com.au/gramo/Site/wiring_the_pic1.htm


--------------------
digital-diy.com - Hobby microcontroller projects and tutorials. Assembly, PICBasic and C examples.
PMEmail PosterUsers Website
Top
mankku
Posted: September 25, 2007 02:03 pm
Reply to this postQuote Post


Forum Addict ++
*******

Group: Spamminator Taskforce
Posts: 3,613
Member No.: 9,683
Joined: June 05, 2007




Good point! That may well be the problem!

Mankku
PMEmail PosterUsers Website
Top
stanigator
Posted: September 26, 2007 05:27 am
Reply to this postQuote Post


Newbie
**

Group: Members+
Posts: 35
Member No.: 10,171
Joined: July 16, 2007




I've made a mistake in describing how my mcu is wired up. Pin 8 was connected to ground during the whole time. However, I found out the issue with my mcu not self-starting has to do with the dc adapter that I'm using. I'll be posting more details in a later message.
PMEmail Poster
Top
stanigator
Posted: September 27, 2007 12:07 am
Reply to this postQuote Post


Newbie
**

Group: Members+
Posts: 35
Member No.: 10,171
Joined: July 16, 2007




I've ensured that MCLR is high through a power on reset connected as
such http://imagebin.ca/view/4YjqO0.html as instructed in the power-on
reset section of the manual. However, the time it takes to return to
5V from 0V after the reset button is turned on in this configuration
is 250 ms, but no matter which combination of the R and C I've tried,
it still won't reset automatically when I first power up using
anything other than a PICKIT 2. I'm not sure what other information
would be useful. I guess I could try changing MCLR reset on in the
code. I'm using a DC adapter that's scrapped off a decommissioned
wireless router. Any insights on this would be much appreciated.
PMEmail Poster
Top
gramo
Posted: September 27, 2007 01:48 am
Reply to this postQuote Post


Forum Addict
******

Group: Trusted Members
Posts: 625
Member No.: 8,536
Joined: March 06, 2007




Hmmm, just a couple of thoughts;


- Are you using in circuit programming?

- Do you need the Reset funtion? Why not just connect 5V---10K Resistor---MCLR?

- Try placing a 1uF-10uF cap from the 5V supply to earth to help filter the supply. Like the 10uF caps in this picture





--------------------
digital-diy.com - Hobby microcontroller projects and tutorials. Assembly, PICBasic and C examples.
PMEmail PosterUsers Website
Top
stanigator
Posted: September 27, 2007 05:14 pm
Reply to this postQuote Post


Newbie
**

Group: Members+
Posts: 35
Member No.: 10,171
Joined: July 16, 2007




I believe PICKIT2 is a in-circuit programmer. I have tried leaving MCLR pulled up to 5V with a 10k resistor. I also tried hooking up the regulator as shown in the link shown. But the mcu still won't self-initiate.
PMEmail Poster
Top
gramo
Posted: September 27, 2007 10:53 pm
Reply to this postQuote Post


Forum Addict
******

Group: Trusted Members
Posts: 625
Member No.: 8,536
Joined: March 06, 2007




The PICKit2 can be used to program PIC's in-circuit, and out of circuit.

If you are hooking up the 5 lines required for programming;

1) MCLR
2) PGD
3) PGC
4) Vdd
5) Vss

without any additional components for "in-circuit" programming, then essentially your just direct programming the PIC. This is almost no different to the basic requirements of the PIC.

So if your PIC functions with the PICKit2 connected, keep in mind that the PICKit2 is simply putting (with power on from the PICkit2 software);

1) MCLR = 5V
2) Vdd = 5V
3) Vss = GND (remember 28 Pin PIC's have 2 Vss and 40 Pin PIC's have 2 Vdd's and 2 Vss's)

If you remove the PICKit2 and supply the same pins with the above requirements, then what’s different to having the PICkit2 connected? Nothing.

Without a stable supply, your PIC will reset intermittently, as MCLR requires a steady 5V to disable a hard reset, hence the need for a 1uF-10uF cap on the supply.


--------------------
digital-diy.com - Hobby microcontroller projects and tutorials. Assembly, PICBasic and C examples.
PMEmail PosterUsers Website
Top
stanigator
Posted: September 29, 2007 08:10 am
Reply to this postQuote Post


Newbie
**

Group: Members+
Posts: 35
Member No.: 10,171
Joined: July 16, 2007




I have now found out that my problems might have to do with 2 things: 1. unclean power supply, or 2. fusebits in the code not set properly since I'm not too familiar with sdcc c syntax.

To address the power supply issue, it has been suggested that I look into using brown out reset and power on timer as mentioned in http://forum.microchip.com/tm.aspx?m=283989. I'm just wondering my last reply on that thread would be on the right track on diagnosing that part of the problem.

Meanwhile, I will ask on the SDCC mailing list on the possibility of the fusebit initialization problems and get back on the results on this forum for future reference by other hobbyists.
PMEmail Poster
Top
stanigator
Posted: October 09, 2007 03:07 am
Reply to this postQuote Post


Newbie
**

Group: Members+
Posts: 35
Member No.: 10,171
Joined: July 16, 2007




Haven't posted here for a while, so I would like to update on what's going on recently. I have talked to the people subscribed to sdcc mailing list and fixed a few bugs on the Makefile. Also, according to the staff, it appears that I haven't initialized the power on reset and stack variable initialization properly, which I have accepted their recommendations on changing those aspects in my source code. However, I'm still currently experiencing the same problem of it not being able to self-execute with an external power supply other than hot-plugging a PICKIT2 with the power supply from the usb turned on. Does anyone have any thoughts of further looking into brown out reset and PWRT?
PMEmail Poster
Top
mankku
Posted: October 10, 2007 08:01 pm
Reply to this postQuote Post


Forum Addict ++
*******

Group: Spamminator Taskforce
Posts: 3,613
Member No.: 9,683
Joined: June 05, 2007




I'm beginning to suspect there's something wrong with your external power supply. What kind is it? If you made it yourself, post a schematic or explain how it's built?

Mankku
PMEmail PosterUsers Website
Top
stanigator
Posted: October 10, 2007 08:04 pm
Reply to this postQuote Post


Newbie
**

Group: Members+
Posts: 35
Member No.: 10,171
Joined: July 16, 2007




Just to give everyone an update on the issue. The fault is not on the power supply. I think it's the microcontroller itself. I swapped it out with a PIC18F2220 with basically the same pinouts, changed some code, and that problem is gone. I'm just wondering the difference between 2220 and 2620, although I should compare them on the Microchip website of post on another topic.

Thank you all for your help.
PMEmail Poster
Top
FunnyNYPD
Posted: November 10, 2007 11:07 pm
Reply to this postQuote Post


Jr. Member
***

Group: Trusted Members
Posts: 58
Member No.: 11,897
Joined: November 10, 2007




Did you check the config bits?


--------------------
Funny N.
PMEmail PosterUsers Website
Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 


:: support us ::




ElectronicsSkin by DutchDork & The-Force