Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 9th May 2008, 05:01 PM   (permalink)
Experienced Member
SPDCHK has a spectacular aura about
Default Why does my 18F1320 take 33seconds to reset?

I'm using the 18F1320 that comes with the Junebug kit in a breadboard arrangement with Hitachi HD44780 LCD controller and programming it with Swordfish SE.

The Swordfish code is as follow... (From one of the forums)

Code:
Device = 18F1320
Clock = 8

// some LCD options...
#option LCD_DATA = PORTB.4
#option LCD_RS = PORTB.3
#option LCD_EN = PORTB.2
// import LCD library...
Include "LCD.bas" 
Include "convert.bas"
Dim Variable As Word
// Start Of Program...

'Enable MCLR on Pin 4 (RA5)
Config MCLRE = ON 

Config osc = INTIO2 // I had to add this to get the 
OSCCON = $76       // one second timer to work correctly

DelayMS(150)                            // Let the LCD warm up
LCD.Cls                                 // Clear the LCD screen
LCD.WriteAt(1,1,"Hello World")          // Send some text to the LCD
Variable = 0                            // Clear the "Variable" register
While True
    Inc(Variable)                       // Decrement the "Var1" register
    // Convert to a string, 
    //  and always display 5 characters    
    LCD.WriteAt(2,1,Convert.DecToStr(Variable,5))   
    DelayMS(1000)                       // Delay for 1 second                 
Wend
When I program the PIC, remove and re-connect the power or use the MCLR switch to reset the PIC, it takes roughly 33 seconds before anything happens. In this 33 second waiting time the LCD display has the typical display that a LCD has that is not configured.

Is it a 18F1320 problem or the way that Swordfish makes the HEX file?
SPDCHK is offline   Reply With Quote
Old 9th May 2008, 05:05 PM   (permalink)
Experienced Member
 
Blog Entries: 4
blueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to behold
Send a message via Skype™ to blueroomelectronics
Default

You also should turn off the watchdog timer, I'm not sure if Swordfish takes care of this automatically but best to turn it off unless you're using it.

Code:
'Enable MCLR on Pin 4 (RA5)
// Config MCLRE = ON Unnessary

Config OSC=INTIO2, LVP=OFF, WDT=OFF // I had to add this to get the 
OSCCON = $72       // one second timer to work correctly
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 9th May 2008, 05:10 PM   (permalink)
Experienced Member
SPDCHK has a spectacular aura about
Default

Bill, it makes no difference. It still takes 33-35 seconds from reload or power recycle to start operating. Once it goes it seems to work 100% fine, (well, as accurate as an RC clock can be?)
SPDCHK is offline   Reply With Quote
Old 9th May 2008, 05:12 PM   (permalink)
Experienced Member
 
Blog Entries: 4
blueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to behold
Send a message via Skype™ to blueroomelectronics
Default

Also Swordfish can use the PK2CMD.EXE command line to program with the Junebug. Make sure you have the /R option to allow the device to come out of reset (RUN) automatically after programming.

Code:
/PPIC$target-device$ /F$long-hex-filename$ /M /R /H2
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 9th May 2008, 05:36 PM   (permalink)
Experienced Member
speakerguy79 is a jewel in the roughspeakerguy79 is a jewel in the rough
Send a message via AIM to speakerguy79 Send a message via MSN to speakerguy79
Default

Are you running Windows?
speakerguy79 is offline   Reply With Quote
Old 9th May 2008, 06:01 PM   (permalink)
Experienced Member
SPDCHK has a spectacular aura about
Default

Quote:
Originally Posted by speakerguy79
Are you running Windows?
Yes. Windows XP Professional.

Bill helped me to get the Swordfish to program directly via the PICKit command line, but the 33s reset still persists.
SPDCHK is offline   Reply With Quote
Old 9th May 2008, 06:30 PM   (permalink)
Experienced Member
 
ericgibbs has much to be proud ofericgibbs has much to be proud ofericgibbs has much to be proud ofericgibbs has much to be proud ofericgibbs has much to be proud ofericgibbs has much to be proud ofericgibbs has much to be proud ofericgibbs has much to be proud of
Default

hi,
After pressing the RESET button, during the long delay period [33s] measure the voltage on pin 4 of the 18F1320, MCLR pin.

Lets know what you measure

Regards
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is online now   Reply With Quote
Old 10th May 2008, 05:55 AM   (permalink)
Experienced Member
SPDCHK has a spectacular aura about
Default

Quote:
Originally Posted by ericgibbs
hi,
After pressing the RESET button, during the long delay period [33s] measure the voltage on pin 4 of the 18F1320, MCLR pin.

Lets know what you measure
Regards
Eric,

+5V Rail: 5.044V
MCLR before reset pressed: 5.040V
MCLR with reset pressed : 0V
MCLR again after reset pressed: 5.040V

When pressing the reset button, the LCD screen stays static with last displayed values and text, and then only after the aforementioned time delay does the PIC actually reset and resume from start.
SPDCHK is offline   Reply With Quote
Old 10th May 2008, 06:25 AM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

It is because the initialization code for the LCD is run at 32kHz. Open LCD.bas and at the end you will find,

Code:
// initialise the module...
Initialize
Add OSCCON = $70 before the line with initialize on it. You will have to double click the little padlock in order to edit it.

Alternatively, make a module called init and include it before the LCD include. Init should contain,
Code:
Module init
OSCCON=$70
Mike.

Last edited by Pommie; 10th May 2008 at 07:49 AM.
Pommie is offline   Reply With Quote
Old 10th May 2008, 08:33 AM   (permalink)
Experienced Member
 
Blog Entries: 2
gramo is just really nicegramo is just really nicegramo is just really nicegramo is just really nice
Default

Your using the internal oscillator, so you have to remember that your Include files will initializes first, and of course, the piece of code that sets up the internal oscillator for 8Mhz will not be executed until that occurs.


basically your PIC is running at 31Khz until it gets to your first piece of code in the main program outside of the "LCD.bas" initialisation.


Solution: Create a User Module called "IntOSC_1320.bas"

In the module, copy and paste this code;

Code:
Module IntOSC_1320

Clock = 8
Config OSC = INTIO2 

OSCCON = %11110011
Save the module in the following directory ..\Swordfish\UserLibrary

Now, back in your main program remove the Clock, Config and OSCCON settings, and include "IntOSC_1320.bas" before any other includes.

Now your program will service the module's code first, and in return you will have an 8Mhz internal OSC from the get go

__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net
gramo is offline   Reply With Quote
Old 10th May 2008, 08:41 AM   (permalink)
Experienced Member
 
Blog Entries: 2
gramo is just really nicegramo is just really nicegramo is just really nicegramo is just really nice
Default

Quote:
Originally Posted by Pommie
You will have to double click the little padlock in order to edit it.

Stay away from the padlock lol Only use this if you know what your doing!

Just saying that as you do not want to know what happened when a newbie of SF learnt that little feature a little to early from me
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net

Last edited by gramo; 10th May 2008 at 09:45 AM.
gramo is offline   Reply With Quote
Old 10th May 2008, 12:39 PM   (permalink)
Experienced Member
SPDCHK has a spectacular aura about
Default

Gramo,

I suppose that's why they pay you the BIG BUCKS hey?

Super solution! Works like a charm. Thank you very much sir!
SPDCHK is offline   Reply With Quote
Old 10th May 2008, 02:44 PM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

Quote:
Originally Posted by SPDCHK
Gramo,

I suppose that's why they pay you the BIG BUCKS hey?

Super solution! Works like a charm. Thank you very much sir!
I guess you must have missed my earlier post then.

Mike.
Pommie is offline   Reply With Quote
Old 10th May 2008, 04:13 PM   (permalink)
Experienced Member
SPDCHK has a spectacular aura about
Default

Sorry Pommie.

When I open the forum I usually go to the last post first. Saves me time scanning (paging down through it all again). I did notice your post, but with gramo's warning for NOOBS not to play with library code, I'd thought it best to heed the warning.

I'm now "playing" with the DS1820 1-wire temperature sensor chip, modifying the example code for the 18F1320, and not USART but LCD. So far I'm not having any luck. I don't read anything from the sensor. But, I'll first fiddle around as much as I can before posting another thread on that topic.
SPDCHK is offline   Reply With Quote
Old 10th May 2008, 04:15 PM   (permalink)
Experienced Member
 
Blog Entries: 4
blueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to behold
Send a message via Skype™ to blueroomelectronics
Default

Is it an 18S20 or 18B20
There are libraries for both as part of Swordfish
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Brown-out reset on LF PIC bananasiong Micro Controllers 10 17th May 2007 12:33 AM
74LS90 power-on auto reset Torben Electronic Projects Design/Ideas/Reviews 17 20th December 2006 04:18 AM
vx-5r reset problem tom muleady General Electronics Chat 2 5th July 2006 06:01 PM
uC 'network' reset circuitry rockin_rick Electronic Projects Design/Ideas/Reviews 8 30th May 2006 01:03 AM
How to reset SCR used for triggering camera flash shootfirst Electronic Projects Design/Ideas/Reviews 20 28th September 2005 08:40 PM



All times are GMT. The time now is 06:33 PM.


Electronic Circuits  |  Radio Controlled
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.