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.

Why does my 18F1320 take 33seconds to reset?

Status
Not open for further replies.

SPDCHK

Member
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 

[COLOR="Red"]Config osc = INTIO2[/COLOR] // I had to add this to get the 
[COLOR="Red"]OSCCON = $76[/COLOR]       // 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?
 
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, 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?)
 
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
 
speakerguy79 said:
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.
 
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
 
ericgibbs said:
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.
 
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:
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

:eek:
 
Pommie said:
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 ;)
 
Last edited:
Gramo,

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

Super solution! Works like a charm. Thank you very much sir! :D
 
SPDCHK said:
Gramo,

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

Super solution! Works like a charm. Thank you very much sir! :D

I guess you must have missed my earlier post then.:rolleyes:

Mike.
 
Sorry Pommie. :eek:

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 said:
I'm now "playing" with the DS1820 1-wire temperature sensor chip, modifying the example code for the 18F1320, and not USART but LCD.

You may find this interesting.

Mike.
 
I have noticed that there are two different libraries. The chip I got is the DS1820. NO S or B in the name. What I did find is that the DS18S20 lib worked in Swordfish. I modified it for the 18F1320 chip and read the input on PortA<0>. I tested the circuit with melting and boiling water. in the ice it came down to about 0.5°C, but the boiling water only got to 87°C. Up here in Johannesburg (being about 1650m above sea level) it's normal for water to start boiling in a kitchen kettle at 90°C

Code:
Device = 18F1320
Clock = 8

// import modules...
Include "IntOSC_1320.bas"
Include "convert.bas"
Include "LCD.bas" 
Include "DS18S20.bas"
Include "utils.bas"

Dim 
   TempA As ShortInt,
   TempB As Byte    // for the DS18S20.bas lib this is a WORD
SetPin(PORTA.0)

// Find() will search the bus for a single DS1820 device
// and load its ROM ID into the DS1820 public variable RomID - you
// could do this manually. For example, RomID = MyRomID...

SetAllDigital
If Not Find Then
LCD.Cls                                 // Clear the LCD screen
LCD.WriteAt(1,1,"No device found")          // Send some text to the LCD
Else
   While true
      ConvertAll
      GetTemp(TempA, TempB)
      LCD.WriteAt(1,1,Convert.DecToStr(TempA),".",DecToStr(TempB)," C")   //
      LCD.WriteAt(2,1,GetTempAsStr, " C")                                       // The same as the line above
      DelayMS(500)
   Wend
EndIf
 
The DS18S20 uses a bandgap temperature sensing rather than the dual-oscillator architecture used by the DS1820, this difference is invisible to the user

The main difference between the two parts is the temperature conversion time: DS1820 = 500ms (max) and DS18S20 = 750ms (max)

In most applications, DS18S20 is software compatible with the DS1820
 
Status
Not open for further replies.

Latest threads

Back
Top