PDA

View Full Version : Don't know what's wrong!



PICante
- 19th December 2007, 17:50
Hi all,

Being a total greenhorn around microcontrollers and all that belongs to them I would appreciate a little help.
Problem: I don’t know where it goes wrong when I try to make my own hex file. I can put some readymade hex code into my 16F628A and get it to work, no problem. But a compiled hex file (PBP) made in MicroCode Studio Plus will not run in my 628A.
Can someone please point me in the right direction?

Thanks!

Charles Linquis
- 19th December 2007, 18:12
Just a guess...

Make sure your configuration fuses are set properly. Especially the oscillator type.

PICante
- 19th December 2007, 18:18
Hi Charles,

Thanks for the suggestion but as I mentioned I am green and “configuration fuses” don’t say much to me! Sorry, can you try to explain what they are and where to set them…. I warned you I am a rookie! :-)

Ioannis
- 19th December 2007, 18:22
As always a program you wrote and a sample schematic are needed to help you.

Ioannis

PICante
- 19th December 2007, 18:49
Hi Ioannis,

Well the program is an example provided with the software compiled for 628A (I believe):

loop:
High 0 ' Turn on LED connected to PORTB.0
Pause 500 ' Delay for .5 seconds

Low 0 ' Turn off LED connected to PORTB.0
Pause 500 ' Delay for .5 seconds

Goto loop ' Go back to loop and blink LED forever
End


And the schematic is simple and the circuit works fine with “readymade” code so I guess its ok.

Thanks.

skimask
- 19th December 2007, 18:56
Hi Ioannis,
Well the program is an example provided with the software compiled for 628A (I believe):
loop:
High 0 ' Turn on LED connected to PORTB.0
Pause 500 ' Delay for .5 seconds
Low 0 ' Turn off LED connected to PORTB.0
Pause 500 ' Delay for .5 seconds
Goto loop ' Go back to loop and blink LED forever
End
And the schematic is simple and the circuit works fine with “readymade” code so I guess its ok.
Thanks.

So that's the code that works. Can't help you with that...'cause...well...it works...

Post the code that doesn't work... Make sure it's compiling for the correct PIC, make double sure you're not compiling for, say, the 16F628, when you're actually programming a 16F628A, or something like that.

mackrackit
- 19th December 2007, 19:02
http://www.picbasic.co.uk/forum/showthread.php?t=543
Tells about configuring fuses.

PICante
- 19th December 2007, 19:06
Hi skimask,

No, that’s the code I try to get to work!
I compile it in MCS (no fault messages) for 628A which is the one I got but it does not run. The code I run successfully is a hex code which I can’t change nor se how it is made “inside”.
I run my 628A on its internal oscillator in both cases.

Thanks!

mackrackit
- 19th December 2007, 19:17
If you have not changed the 16F628A.inc then I bet it is trying to use the XT OSC.
Look at the link I sent before and the data sheet for the correct setting when using the internal OSC.

It will be something like INTOSC instead of XT.

PICante
- 19th December 2007, 19:36
Hi Dave,

How does the compiler pick up the *.inc file and where is it originally placed. In assembler there is an “Include” command but in PBP there are not as far as I have seen.
I will have a look at the PIC datasheet and the link you supplied, thanks!

mackrackit
- 19th December 2007, 19:46
The *.inc is in you PBP directory.
When you compile with Pic Basic it will automatically look there. Or you can do it in your code.
The link tells how.

Look at the ASM file made after you compile and you will see the includes.

Ioannis
- 19th December 2007, 19:47
If this is all the code and you are trying to run it on a 628A device, I bet it will never do anything!

Since in a reply or more replies it is impossible to teach you what all these fuses and configurations are, you have to do your homework too.

1. Get a data sheet of the device (in this case 16F628A from microchip)

2. Read it thouroughly as it has many systems and subsystems that all are multiplexed with the 16 pins of the device.

3. Also study the PBP manual.

Then you may start blinking a LED!

Are you sure thet you are running the chip on the internal osc? How did you set it to? Have you set the MCLR pin at the appropriate level (HIGH) or did you disabled from the config fuses or more from within the programmer?

By the way, what is your programmer?

Ioannis

KVLV
- 19th December 2007, 20:05
loop:
high portb.0
pause 500
low portb.0
pause 500
goto loop



try that.

skimask
- 19th December 2007, 21:02
Hi skimask,

No, that’s the code I try to get to work!
I compile it in MCS (no fault messages) for 628A which is the one I got but it does not run. The code I run successfully is a hex code which I can’t change nor se how it is made “inside”.
I run my 628A on its internal oscillator in both cases.

Thanks!

Ohhh...ok...I get ya now...
Make sure your MCLR is pulled high regardless of the config bit settings and try it again, except instead of waiting a second for the LED to blink, wait for about 2 minutes.

If it blinks in 2 minutes instead of once per second, the PIC is running on the low speed internal oscillator (32khz - 48khz depending on which datasheet for the 628A you look at) instead of the high speed internal oscillator (4mhz nominal).

If that's the case, then, as stated before by others, do a bit of searchin' and learn how to play with config's and fuse settings.

Archangel
- 19th December 2007, 21:11
Hello PICante,
The 628A has analog comparator inputs, so unless you are using them turn them off with
CMCON = 7
then read the post on config fuses
try:


@ DEVICE pic16F628A, HS_OSC ' Change HS to XT for 4mhz

@ DEVICE pic16F628A, WDT_ON
' Watchdog Timer

@ DEVICE pic16F628A, PWRT_ON
' Power-On Timer

@ DEVICE pic16F628A, MCLR_ON
' Master Clear Options (Internal)

@ DEVICE pic16F628A, BOD_OFF
' Brown-Out Detect

@ DEVICE pic16F628A, LVP_OFF
' Low-Voltage Programming

@ DEVICE pic16F628A, CPD_OFF
' Data Memory Code Protect
' Set to CPD_OFF for Development Copy
' Set to CPD_ON for Release Copy

@ DEVICE pic16F628A, PROTECT_OFF

DEFINE OSC 20 ' for 20 mhz, change to fit your OSC speed


that code should setup your configs if using the default compiler, MAPSM uses different configs.

Welcome back skimask

skimask
- 19th December 2007, 21:21
Hello PICante,
The 628A has analog comparator inputs, so unless you are using them turn them off with
CMCON = 7

But not on PortB.0...(that was my first thought too).
Everything else still applies in full...if not more... :)

PICante
- 21st December 2007, 11:32
Thanks all of you!

I have some reading to do (obviously) and I get back on this matter if I don’t figure it out myself!
One 180 page datasheet and then some … phuuuu.

Thanks again :-)

Merry Christmas!

mackrackit
- 21st December 2007, 11:46
Stop whining :)

I am looking at the data sheet for the 18F4550 over the holiday.

428 pages!

Merry Christmas to you too.