View previous topic :: View next topic |
Author |
Message |
POPE19
Joined: 27 Jun 2017 Posts: 71
|
PIC reset problem |
Posted: Thu Aug 31, 2017 10:28 am |
|
|
I am using PIC16f1939. I am having problems with
pic reset. When power to my PIC is on and programming using ICSP it executes the instructions in void main () program. However as soon as i power off the PIC and turn it back on, it skips all the instructions between the start of void_main() loop to While(true) loop. Seems like the program memory is stuck and doesn't reset when power is off.
Code: |
#include <16F1939.h>
#fuses HS, NOVCAP, MCLR, NOWDT, PUT, NOIESO, BROWNOUT, NOFCMEN, PLL_SW
#use delay(crystal=20MHz, clock=20MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
void main()
{
printf("started \r \n");
while(TRUE)
{
output_high (PIN_D1);
delay_ms(1000);
output_low (PIN_d1);
delay_ms(1000);
printf("\r \n hello");
}
}
|
It does not serial print "started " when i turn off and turn it back on. However the led blinks at 1 Hz. It only executes that portion when i am programming PIC using ICSP while powered on. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu Aug 31, 2017 10:50 am |
|
|
You talk about ICSP. What programming environment are you using?. MPLAB?. CCS IDE?. CCSLoad?. Are you disconnecting the ICSP header?. Remember this has power. Are you sure you are compiling the code for RUN, rather than DEBUG operation?. What other circuitry is attached?. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Aug 31, 2017 11:19 am |
|
|
also
what serial monitoring device is attached to the PIC? A terminal, a PC, serial LCD ??
If a PC, what software is the 'terminal program'.
If PC, is it RS-232 or a USB<>TTL device on the PIC ?
If PC what else has control, or possible control over the communication channel the PIC is attached to ?
BTW, I normally have a 1 second delay BEFORE I try to transmit anything to a PC terminal program.
Jay |
|
|
POPE19
Joined: 27 Jun 2017 Posts: 71
|
|
Posted: Thu Aug 31, 2017 11:47 am |
|
|
I am using MPLAB IPE v3.65 to program
pic. I am using Microchip PM-3 programmer. Yes i am disconnecting ICSP header. I am not using Debug operation. My compiler is CCS PCWH 5.074.
I am using USB to TTL and the serial monitor is computer. The software is the CCSload serial monitor in compiler tools menu. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu Aug 31, 2017 1:03 pm |
|
|
You do realise that MPLAB _defaults_ to enabling DEBUG, unless you specifically set it to build for 'release' mode?. Are you building using CCS through it's IDE, or using the MPLAB IDE environment to build?. If the latter, you need to select 'Release'.
Once built for debug, the code will not run correctly, unless the debugger is attached or the debug pins are biased low..... |
|
|
POPE19
Joined: 27 Jun 2017 Posts: 71
|
|
Posted: Thu Aug 31, 2017 1:30 pm |
|
|
No, I am using CCS Compiler to build just using MPLAB to write it to chip. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Aug 31, 2017 2:11 pm |
|
|
You MUST set the 'build configuration' in MPLAB to 'release' and NOT 'debug' (the default mode) as Mt. T says.
I got caught by that years ago, asked Microchip MPLAB team to allow ME to select the default, 2 releases later it was coded in.
I told him I never, ever use 'debug' to test software, that's what the Real World is for, having started this gig in assembler and paper tape (aka Teletypes), I tend to think/code/think again/recode/compile then test.
Jay |
|
|
POPE19
Joined: 27 Jun 2017 Posts: 71
|
|
Posted: Thu Aug 31, 2017 3:49 pm |
|
|
Sorry but I don't understand what are you trying to say. How would I do that in MPLab ? Sorry but I am new to this field and learning. Can you please explain or post a link which can better explain me what am I doing wrong ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Aug 31, 2017 5:06 pm |
|
|
OK...
run MPLAB....
select a project...
4th tab to the right is 'Project'
scroll down to 'build configuration'
select 'release'
NOW compile aka 'make' or F10
In newer versions of MPLAB (8v86 +) selecting 'release' will STAY as the default build configuration. Early versions always used 'debug' as the default and you had to manuall, EVERY time, select 'release'...which for an old guy like me was a pain.
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 31, 2017 6:54 pm |
|
|
temtronic, he is not using MPLAB 8.xx at all. He said:
Quote: | I am using MPLAB IPE v3.65 to program pic. |
He should have said "MPLAB X", to be accurate.
The "IPE" is a programmer application that is installed as part of MPLAB X.
It doesn't have Debug/Release settings.
MPLAB X IPE user's guide:
http://ww1.microchip.com/downloads/en/DeviceDoc/50002027D.pdf |
|
|
POPE19
Joined: 27 Jun 2017 Posts: 71
|
|
Posted: Thu Aug 31, 2017 8:48 pm |
|
|
Sorry I forget to mention mplabX IPE v 3.65. Yes PCM programmer is right. I'm just using it to write to chip and mainly I am using ccs IDE to write the code and can never it to hex. I cannot understand why is this happening.
Any suggestions? |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Fri Sep 01, 2017 12:24 am |
|
|
POPE19 wrote: | Sorry I forget to mention mplabX IPE v 3.65. Yes PCM programmer is right. I'm just using it to write to chip and mainly I am using ccs IDE to write the code and can never it to hex. I cannot understand why is this happening.
Any suggestions? |
They have made suggestions. Did you try that? What was the result?
If you don't give feedback, then expect everybody here to lose interest. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Fri Sep 01, 2017 1:09 am |
|
|
That is why I asked:
"Are you building using CCS through it's IDE, or using the MPLAB IDE environment to build?.". After he referred to the IPE.
However, though the IPE doesn't itself have debug/release it does have the option to not erase everything before programming, and if the fuses were not being erased, and had been set to debug earlier, then the behaviour would be normal.
The other possibility is it may actually be working fine.
If he is using a serial connection with a MAX232, that takes a few mSec to wake, the initial message might just be missed.
Code: |
#include <16F1939.h>
#fuses HS, NOVCAP, MCLR, NOWDT, PUT, NOIESO, BROWNOUT, NOFCMEN, PLL_SW
#use delay(crystal=20MHz, clock=20MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
void main()
{
delay_ms(100);
printf("started \r \n");
while(TRUE)
{
output_high (PIN_D1);
delay_ms(1000);
output_low (PIN_d1);
delay_ms(1000);
printf("\r \n hello");
}
}
|
|
|
|
POPE19
Joined: 27 Jun 2017 Posts: 71
|
|
Posted: Fri Sep 01, 2017 5:39 am |
|
|
ok Ttelmeh i have tried your suggestion when you mentioned in the beginning yesterday by giving 1 sec delay but it is still same. I dont know MPLAB x IDE so here is what i did.I am programming PIC16F1939 using CCS ICD-u64 which also support debugging.
here too the phrase "started" is displayed only once after i reprogram . but if i am turning pic power off and turning it back on it will only display phrase hello & donot execute the instructions above while(TRUE) loop.
you are right serial communication with MAX232 takes few msec to wake. i didnt observed yesterday but today i saw that as soon as the hex file is written to pic it displays "tarted" --->( Skipped S letter) with 1000msec delay. but if i put more delay like 1900 msec. it will display "Started" . i experimented giving different combination of seconds.
however the problem still persist . it wont display "started" once it is powered off & powered back on
Code: | #include <16F1939.h>
#fuses HS ,NOVCAP, MCLR, NOWDT, PUT, NOIESO, BROWNOUT, NOFCMEN,PLL_SW
#use delay(crystal=20MHz, clock=20MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
void main()
{
delay_ms(1900);
printf("started \r \n");
while(TRUE)
{
output_high (PIN_D1);
delay_ms(1000);
output_low (PIN_d1);
delay_ms(1000);
printf("\r \n hello");
}
}
| [/code] |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Fri Sep 01, 2017 5:48 am |
|
|
How are your MCLR connected? |
|
|
|