Continue to Site

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.

  • 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.

16F886 Power on issue?

Status
Not open for further replies.

lmichals80

New Member
Hello everyone,

Being I am a newbie, and I have searched this and other forums without success, I will try posting in hopes to not get verbally abused too badly. I am having a problem intializing the PIC program I guess. I am running a simple LED flash program, but when I first give the PIC power, the program runs about 4-5 times as slow. if I pull out the Vdd wire from the breadboard and plug it back in the program runs at normal speed. I am assuming this is a config word issue or something with the POR but have tried different options with no results. (PWTE on and off with and without BOR on and off, MCLR on and bridging to the Vdd) with no luck. Here is my setup:

Power supply: DC regulated power supply or 9v battery, fed through an LM317T voltage regulator to produce 5V tested with a multimeter(I have also tested with a strait connection from the power supply set at 5V with the same results)

compiler: mikcroC

PIC Programmer: Microchip PICkit 2

PIC: 16f886

Settings:
clock 4mhz, HS osc on, WDT off, LVP off

Code:

void main(void){
osccon = 0x60;
ansel = 0;
trisb = 0x00;
portb = 0x00;


while (1) {
portb = 0xff;
delay_ms(500);
portb = 0x00;
delay_ms(500);
}
}


Initally I started with a function, but ruled that out as the cause. (it appears to be a totally different problem with putting delays in the function) I realize the format is bad, but it does function when I pull and replace the wire. Any help would be greatly appreciated!!!

Thanks,

Luke
 
I suspect your crystal oscillator isn't working correctly. Do you have the correct capacitors? However, if you crystal oscillator fails, it should use the internal oscillator which you are setting to 4MHz and so I can't see what would cause your problem.

If you set OSCCON to 0x61, does it solve your problem.


Mike.
 
WOW you guys are fast... I should have said I was using the internal osc, however after all the headaches...I attempted to debug using MPLAB, pretty much winging it and failed. I loaded a new project into MPLAB and attempted to build, and that failed...at some point in time I remember wiping out the memory on the chip during the debug. I noticed the posts and loaded the mikroC compiled program on, and it appears to be working just fine now. I tried the 0x61 and that also worked(setting the bit to the internal osc, I looked that up). So that problem was solved. since you guys are around maybe you could give a tip as to why if I put the code listed below into a function and then run that in the while loop it doesn't work... it seems the delay_ms command makes it unhappy?

void ex_funct(void){
while (1) {
portb = 0xff;
delay_ms(500);
portb = 0x00;
delay_ms(500);
}
}

void main(void){
osccon = 0x60;
ansel = 0;
trisb = 0x00;
portb = 0x00;


while (1) {
ex_funct();
}
}
 
I have no idea why that wouldn't work. It should work.

BTW, if you type
Code:
[/I] before your code and [I]
after it then it will keep it's formatting.

Mike.
 
Your correct it should work. In fact it does work if I change the build type to "Release" instead of "ICD debug" in the compiler... I will now write a program to slap me upside the head when I overlook the obvious and ask you all for help.

Thanks,

Luke
 
Last edited:
Have you allocated the required resources for the ICD2. For the 886 it requires locations 0x70 (all banks) and 0x1e5 to 0x1ef.

Mike.
 
more than likely I haven't...I'm not really literate on the debug setup at all...I used the software simulator to step through the program, but never on the chip itself. Is the mikroC debug even compatible with the PICkit2 programmer, or do I need to use MPLAB? When I switch the build type to release, everything works as expected, so that seems to be a good thing. since I got the program to work, I am now attempting to use a separate power source to turn the LED on from a pin input, where I have run into my next issue. When I load the program below, the LED turns on right away, and never turns off. I think there is something I'm missing, because even though I turn TRISB to an output, for some reason even with the Vdd off, if I connect a different power source to just about every pin, it turns the LED on?!! with the vdd on the input pin has no effect on the the LED. I have tried different ports and different pins as the "on" pin, along with rewriting the code to use an if statement, all with the same results...I triple checked my compiler settings and can find nothing. Once again, any help would be appreciated!!!
Code:
void main(void){
     osccon = 0x61;
     ansel = 0x00;
     trisc = 0x04;
     trisb = 0x00;

     //porta = 0;
     portb = 0x00;
     while((portc & (1<<0)) == 1)portb |= (1<<0);
           portb = 0x00;
     }

Luke
 
Pommie:
I'd like to do some ICD via pickit2 on a 16f886, can u direct me to resources that detail the requirements?
thanks?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top