Author Topic: code working in simulation but not working in hardware  (Read 3232 times)

0 Members and 1 Guest are viewing this topic.

Offline ect_09Topic starter

  • Contributor
  • Posts: 17
code working in simulation but not working in hardware
« on: November 15, 2014, 09:03:22 am »
Hello,
I am using PIC18F452 with MPLAB and HI-TECH compiler.
i write this code that take input and show the corresponding output. simulation showing that its working OK,
but when burn the hex file not taking the input.
Code: [Select]
#include<htc.h>

__CONFIG(1,OSCSDIS & HSPLL);
__CONFIG(2,PWRTDIS & WDTDIS & BORDIS);
__CONFIG(3,CCP2RC1);
__CONFIG(4,LVPDIS & STVREN);
__CONFIG(5, UNPROTECT);
__CONFIG(6,WRTEN);
__CONFIG(7,TRU);



void main()
{
TRISB4=1;
TRISD=0;

while(1)
{
   
if(!RB4)
{
PORTD=0x55;
}
else
{
LATD=0xFF;
}
}
}
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 1726
  • Country: 00
Re: code working in simulation but not working in hardware
« Reply #1 on: November 15, 2014, 04:42:26 pm »
Your post is a bit vague, so I can only ask lots of questions with a chance we're still missing the whole picture:

Can you program the PIC? If not, what programmer do you use?
How do you power the PIC?
Have you got decoupling capacitors on VDD/GND pins?
Have you got a pull-up resistor on MCLR?
Do you have got a crystal oscillator , as is defined in your fuse settings? The PIC18F452 does not have an internal oscillator!
Make sure you "program" the PIC and not "debug" it - debug HEX files usually don't start without a debugger starting up.
 

Offline janengelbrecht

  • Regular Contributor
  • *
  • Posts: 181
  • Country: dk
    • JP-Electronics
Re: code working in simulation but not working in hardware
« Reply #2 on: November 15, 2014, 04:53:32 pm »
Decent simulators like Labcenter Proteus ISIS will pick up those kind of errors.....but less expensive ones..no...Depends on how much/how deep they simulate...do they simulate a lot of hardware too ? Thats important.

But these days i think you are better off by emulating : running the software on the actual hardware with breakpoints and access to register contents and so on....Mostly because of the complex circuits used...a lot of simulator packages just give up....CPU load 120% :P

Offline ect_09Topic starter

  • Contributor
  • Posts: 17
Re: code working in simulation but not working in hardware
« Reply #3 on: November 15, 2014, 05:32:26 pm »
i attached the image.
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3440
  • Country: gb
Re: code working in simulation but not working in hardware
« Reply #4 on: November 15, 2014, 06:12:26 pm »
when burn the hex file not taking the input.


That's not a very useful description of the problem.  Describe the actual symptoms.  Is the code running at all?

Also why are you writing to the PORTD register for one part of the if condition, but writing to the LATD register for the other?
 

Offline janengelbrecht

  • Regular Contributor
  • *
  • Posts: 181
  • Country: dk
    • JP-Electronics

jucole

  • Guest
Re: code working in simulation but not working in hardware
« Reply #6 on: November 16, 2014, 08:23:34 am »
Have you had code running successfully with that chip on your board before?

I can't see any caps on your crystal - is it oscillating?   

What speed is your crystal?











 

Offline bookaboo

  • Frequent Contributor
  • **
  • Posts: 771
  • Country: ie
Re: code working in simulation but not working in hardware
« Reply #7 on: November 17, 2014, 09:54:49 am »
Yep you need caps from the pins of the osc to ground, will depend on the frequency and osc spec but 22pf is a good guess.
Also, I'd avoid simulation software, especially microchips. Much better to pick up something like a PICKIT3 or something along those lines.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf