PDA

View Full Version : PIC16F819 LED not blinking



ronbowalker
- 30th November 2009, 18:50
Using a PIC16F819 and below PBP program. My volt meter does not show a HIGH/LOW cycle occuring on the pin for the LED. (Pins 10 and 17). 31.25kHz is desired OSC speed and internal. All pins converted to digital.

MPASM Code:

@__Config_INTRC_OSC
@__Config_PWRT_OFF
@__Config_MCLR_OFF
@__Config_BOREN_OFF
@__Config_DEBUG_OFF

DEFINE OSC 3
OSCCON = %00000000
ADCON1=7
TRISA = %00000000
TRISB = %00000000
TRISB.4 = 0
TRISA.0 = 0
PORTB.4 = 0
PORTB.4 = 0

LOOP:

PULSOUT PORTB.4,20
PAUSE 20
PULSOUT PORTA.0,20
PAUSE 20

'Goto LOOP

Please help if you can. I have been using other posts to fix, but I have been unsucessful.

Melanie
- 30th November 2009, 20:14
Oooohhhh.... not good...

The DEFEINE OSC 3 tells PICBasic that you're running at 3.58MHz, whereas you are actually running almost 110x slower at 32kHz...

This means that EVERY time critical function (including PULSEOUT) will be totally shot to pieces.

As a test... try this...

Loop:
High PortB.4
Pause 2
Low PortB.4
Pause 2
Goto Loop

You might find the LED blinks at about 2Hz (give or take)...

I don't recall if PICBasic (my manual is a little old) allowed definitions below 3.58 MHz... but I think 32kHz will cause numerous problems.

May I also suggest you SWITCH OFF the WATCHDOG TIMER (which is ON by default with PICBasic). The program may be running so slowly that your PIC is actually timing-out and resetting before it actually executes anything.

ronbowalker
- 30th November 2009, 20:46
I have been reading a lot of posts you have made over the years on this issue Melanie, and I am very happy to hear from you in particular. You seem to be well versed in the changes that have been made to this chip over the years. Is it worth using?, or would the 16F87/88 be better? NANO and 16-pins I/O are my only requirements on this......and also, I am going to be using a Timer that will require me to use MPASM. This section will be added to the program IF I get this chip running properly (IF being key word here!).

As you can see, I am trying to preserve power and was hoping to get 31.25kHz on this project internally. But due to problems at this point, I can go higher on the OSC to get this thing going in the right direction if need be.

I removed the "Define OSC 3" statement, as well as the commands as you suggested. No Luck.

So in order to move forward, what would be the best settings on this chip to get the LED's (pin 10 & 17) to blink the LED? 1MHz?

Note: What is the FOSC0:FOSC2 needing to be set to 100 all about? I saw this somewhere and don't understand this area.

Dennis
- 30th November 2009, 21:16
Hi Ron

I noticed your LOOP code seems to have a problem at the end ....
The GOTO LOOP has a comment in the beginning , at first it looked like a spec of dust ;-)
Look carefully at the beginning of the GOTO line :-)
your code...


LOOP:

PULSOUT PORTB.4,20
PAUSE 20
PULSOUT PORTA.0,20
PAUSE 20

'Goto LOOP


Corrected code



LOOP:

PULSOUT PORTB.4,20
PAUSE 20
PULSOUT PORTA.0,20
PAUSE 20

Goto LOOP


Did you try Melanie's code in place of yours ?

Hope that works ...
Dennis

ronbowalker
- 30th November 2009, 21:20
[QUOTE=Dennis;81575]Hi Ron

I noticed your LOOP code seems to have a problem at the end ....
The GOTO LOOP has a comment in the beginning , at first it looked like a spec of dust ;-)
Look carefully at the beginning of the GOTO line :-)
your code...

Good eyes Dennis, but this is only on the forum post....I already corrected that on the program! Thanks for the help in any case. I am still trying to get this thing running, so any addidtional help is appreciated.

No luck with Melanies info changes.....Datasheet 35-37 are on the INTRC and INTOSC settings. What do we do when going to higher OSC frequency in this area?

Bruce
- 30th November 2009, 21:30
Your config options have ZERO effect on actual config settings.


@__Config_INTRC_OSC
@__Config_PWRT_OFF
@__Config_MCLR_OFF
@__Config_BOREN_OFF
@__Config_DEBUG_OFF
So your config settings are whatever the default config options are set to in your
PBP 16F819.INC file for the MPASM assembler.

And, like Melanie mentioned, you for sure will want the WDT disabled since DEFINE OSC 3
is for a 3MHz osc & not 32kHz osc, so your timing is way off.

Try this just to verify it's working;


DEFINE OSC 4
@ __CONFIG _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _MCLR_OFF & _BODEN_OFF & _DEBUG_OFF
OSCCON = %01100000 ' 4MHz
ADCON1=7
TRISA = %00000000
TRISB = %00000000
TRISB.4 = 0
TRISA.0 = 0
PORTA.0 = 0
PORTB.4 = 0

LOOP:

PULSOUT PORTB.4,20
PAUSE 20
PULSOUT PORTA.0,20
PAUSE 20

Goto LOOP


And, for PBP 2.6 you'll want to change LOOP to something like LOOPS since LOOP is now a
reserved word.

ronbowalker
- 30th November 2009, 22:03
@ __CONFIG _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _MCLR_OFF & _BODEN_OFF

This gives me illegal character "&" error message......asm.51

So I need to go and make these settings permanent in MPASM file to keep from having to make this statement, correct?

Also, datasheet (DS39598E)2004 shows:
A. WDT is WDTEN (Watchdog Timer)
B. MCLR is MCLRE (Memory Clear)
C. BODEN is BOREN (Brown-Out)

Is this correct?
Thanks for the info Bruce....I appreciate all the help I can get.
I will try to change the file settings...can you tell me what to have for pic16f819.inc file, I think I messed mine up.
Here is mine:
;************************************************* ***************
;* 16F819.INC *
;* *
;* By : Leonard Zerman, Jeff Schmoyer *
;* Notice : Copyright (c) 2004 microEngineering Labs, Inc. *
;* All Rights Reserved *
;* Date : 01/07/04 *
;* Version : 2.45 *
;* Notes : *
;************************************************* ***************
NOLIST
ifdef PM_USED
LIST
include 'M16F81x.INC' ; PM header
device pic16F819, intrc_IO, wdt_off, pwrte_off, lvp_off, protect_off
XALL
NOLIST
else
LIST
LIST p = 16F819, r = dec, w = -302
INCLUDE "P16F819.INC" ; MPASM Header
__config _INTRC_osc & _WDT_OFF & _PWRTE_ON & _LVP_OFF & _CP_OFF
NOLIST
endif
LIST

Bruce
- 30th November 2009, 22:11
This gives me illegal character "&" error message......asm.51
I have no clue what this error message is. What assembler are you using?


asm.51
Almost looks like you're trying to use an 8051 assembler?

ronbowalker
- 30th November 2009, 22:29
I am using PICBASIC PRO from MicroCode Studio.

In the settings window, I have selected the MPASM assembler checkbox.

This is all I know. I reset the .inc file to where is was originally. Here it is....

;************************************************* ***************
;* 16F819.INC *
;* *
;* By : Leonard Zerman, Jeff Schmoyer *
;* Notice : Copyright (c) 2004 microEngineering Labs, Inc. *
;* All Rights Reserved *
;* Date : 01/07/04 *
;* Version : 2.45 *
;* Notes : *
;************************************************* ***************
NOLIST
ifdef PM_USED
LIST
include 'M16F81x.INC' ; PM header
device pic16F819, hs_osc, wdt_off, pwrt_off, lvp_off, protect_off
XALL
NOLIST
else
LIST
LIST p = 16F819, r = dec, w = -302
INCLUDE "P16F819.INC" ; MPASM Header
__config _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF & _CP_OFF
NOLIST
endif
LIST

I have been trying to get this MPASM Header, the way you wrote it, to compile correctly all day, but it still gives me errors.

Bruce
- 30th November 2009, 22:34
If you prefer to edit your 16F819.INC file, then just change it to;

__CONFIG _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _MCLR_OFF & _BODEN_OFF & _DEBUG_OFF

If not, then just comment it out in the .INC file & add your config settings to your code.

Melanie posted a nice intro here http://www.picbasic.co.uk/forum/showthread.php?t=543 on setting config options.

NOTE: This applies only to the 16F819.INC file in your PBP directory. Not the P16F819.INC
file in your MPLAB directory. These are different. You shouldn't ever need to modify the
P16F819.INC file in your MPLAB directory.

ronbowalker
- 30th November 2009, 22:36
This compiles without error.....

@__CONFIG_HS_OSC_WDT_OFF_PWRTE_ON

But more than this will cause a "Label truncated at 32 characters" error.

Bruce
- 30th November 2009, 22:47
Try the config line I posted above. What you're trying to do here isn't any good.

ronbowalker
- 30th November 2009, 22:55
Try the config line I posted above. What you're trying to do here isn't any good.

Okay...I now understand what is to be done, and the changes were made as you said to the .inc file. Compile is now error free. Pop-up window settings are now as per your suggestion. Sorry for the crazy rookie mistakes. Let's see what happens now....

Update...LED is on steady. No blinking

Bruce
- 30th November 2009, 23:05
Update...LED is on steady. No blinking
You might want to try something like this to see your LEDs blink;


DEFINE OSC 4
@ __CONFIG _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _MCLR_OFF & _BODEN_OFF & _DEBUG_OFF
OSCCON = %01100000 ' 4MHz
ADCON1=7
TRISA = %00000000
TRISB = %00000000
TRISB.4 = 0
TRISA.0 = 0
PORTA.0 = 0
PORTB.4 = 0

LOOP:
PORTB.4 = PORTB.4 ^ 1
PAUSE 250
PORTA.0 = PORTA.0 ^ 1
PAUSE 250
Goto LOOP
Check your PBP manual to see why your LEDs aren't visibly blinking with PULSEOUT...;o)

ronbowalker
- 1st December 2009, 00:32
You might want to try something like this to see your LEDs blink;


DEFINE OSC 4
@ __CONFIG _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _MCLR_OFF & _BODEN_OFF & _DEBUG_OFF
OSCCON = %01100000 ' 4MHz
ADCON1=7
TRISA = %00000000
TRISB = %00000000
TRISB.4 = 0
TRISA.0 = 0
PORTA.0 = 0
PORTB.4 = 0

LOOP:
PORTB.4 = PORTB.4 ^ 1
PAUSE 250
PORTA.0 = PORTA.0 ^ 1
PAUSE 250
Goto LOOP
Check your PBP manual to see why your LEDs aren't visibly blinking with PULSEOUT...;o)

Still no blink. Tried above program as well. PULSOUT did not work either...?

ronbowalker
- 1st December 2009, 02:04
I now have blimking LED's....

DEFINE 4 statement was not needed.