External clock on 16f819 problem.
	
	
		OK, I've read the datasheet but I'm still confused.
I have someone elses pre-made project that I'm altering. It already runs from asm with a 16F818 but I wanted to add big characters for the LCD.
The project uses non standard pins for the LCD so I'm using LCD_AnyPin.pbp and it uses an external 10Mhz oscillator as clock in.
 
I have a small test board running the code I want successfully using the odd pins, but a standard crystal 10Mhz oscillator as DEFINE OSC 10.
I read the datasheet as EICON for the external oscillator option but I have no idea how to set it ?
I tried DEFINE EXT_OSC 10 and selecting EXTCLOCK on the programmer but although I get two lines showing (Contrast up) there is no data.
I also tried  'clkin VAR portA.7' with no success.
Anyone point me in the right direction?
 As I say the code works with Xtal osc but not external clock so seems no point posting the code.
	 
	
	
	
		Re: External clock on 16f819 problem.
	
	
		If it already runs in assembler, why assume posting your new basic code is pointless?
Port A is analog in many (if not all) PICs, you have to set it to digital to use it with the LCD.
It's difficult to make suggestions if we can't see your code, a schematic of your project wouldn't hurt either.
Robert
Note: This thread is just 4 below yours right now:
http://www.picbasic.co.uk/forum/showthread.php?t=16016
	 
	
	
	
		Re: External clock on 16f819 problem.
	
	
		Hmm, my post isn't very clear.
I have the software working on a development board. This board uses a 10Mhz Xtal osc as standard.
The board I want to use it on uses an external 10Mhz oscillator source on one pin only OSC1.
I believe I need to set OSCCON=8 to select mode 8 in the oscillator settings. It appears my programmer is defaulting to the 'inc' values.
	 
	
	
	
		Re: External clock on 16f819 problem.
	
	
		
	Quote:
	
		
		
			
				Originally Posted by 
tasmod
				 
			...The board I want to use it on uses an external 10Mhz oscillator source on one pin only OSC1.
...
			
		
	 
 Can you give more information about that board?
I've never seen a circuit using only one pin for the oscillator (it doesn't mean it doesn't exist).
Robert
EDIT: Interesting, Pierce and Colpitts oscillators have only one output:
http://ww1.microchip.com/downloads/e...tes/00826a.pdf
	Quote:
	
		
		
			
				Originally Posted by 
tasmod
				 
			...The board I want to use it on uses an external 10Mhz oscillator source on one pin only OSC1....
			
		
	 
 After glancing through that application note, I'd start by checking just how accurate the oscillator is working.
	 
	
	
	
		Re: External clock on 16f819 problem.
	
	
		Robert, Havent you ever ran a PIC from an external oscillator before? You only need 1 pin for the input. That frees up another pin for some external use by the designer.
	 
	
	
		1 Attachment(s)
	
	
		Re: External clock on 16f819 problem.
	
	
		
	Quote:
	
		
		
			
				Originally Posted by 
Dave
				 
			Robert, Havent you ever ran a PIC from an external oscillator before? ...
			
		
	 
 Always.
	Quote:
	
		
		
			
				Originally Posted by 
Dave
				 
			...You only need 1 pin for the input. ...
			
		
	 
 Not wired like this:
Attachment 6234
Robert
	 
	
	
		1 Attachment(s)
	
	
		Re: External clock on 16f819 problem.
	
	
		No Robert, Like this:
Attachment 6237
	 
	
	
	
		Re: External clock on 16f819 problem.
	
	
		
	Quote:
	
		
		
			
				Originally Posted by 
Dave
				 
			Robert, Havent you ever ran a PIC from an external oscillator before? You only need 1 pin for the input.
			
		
	 
 What you posted is an external clock input, like the title says. That's not really an external oscillator.
	 
	
	
	
		Re: External clock on 16f819 problem.
	
	
		Wouldn't that need a CONFIG fuse?
Dave, do you have an example from one of your programs?
Robert
EDIT: These are the available fuses for a 16F819:
	Code:
	
_CP_ALL                      EQU     H'1FFF'
_CP_OFF                             EQU     H'3FFF'
_CCP1_RB2                     EQU     H'3FFF'
_CCP1_RB3                    EQU     H'2FFF'
_DEBUG_OFF                   EQU     H'3FFF'
_DEBUG_ON                    EQU     H'37FF'
_WRT_ENABLE_OFF              EQU     H'3FFF'
_WRT_ENABLE_512              EQU     H'3DFF'
_WRT_ENABLE_1024             EQU     H'3BFF'
_WRT_ENABLE_1536             EQU     H'39FF'
_CPD_ON                      EQU     H'3EFF'
_CPD_OFF                     EQU     H'3FFF'
_LVP_ON                      EQU     H'3FFF'
_LVP_OFF                     EQU     H'3F7F'
_BODEN_ON                    EQU     H'3FFF'
_BODEN_OFF                   EQU     H'3FBF'
_MCLR_ON                     EQU     H'3FFF'
_MCLR_OFF                    EQU     H'3FDF'
_PWRTE_OFF                   EQU     H'3FFF'
_PWRTE_ON                    EQU     H'3FF7'
_WDT_ON                      EQU     H'3FFF'
_WDT_OFF                     EQU     H'3FFB'
_EXTRC_CLKOUT                     EQU     H'3FFF'
_EXTRC_IO                     EQU     H'3FFE'
_INTRC_CLKOUT                EQU     H'3FFD'
_INTRC_IO                     EQU     H'3FFC'
_EXTCLK                             EQU     H'3FEF'
_HS_OSC                      EQU     H'3FEE'
_XT_OSC                      EQU     H'3FED'
_LP_OSC                      EQU     H'3FEC'
 
And these are the default settings (PM and MPASM):
	Code:
	
        device  pic16F819, hs_osc, wdt_on, pwrt_on, lvp_off, protect_off
        ...    else
        ...        __config _HS_OSC & _WDT_ON & _PWRTE_ON & _LVP_OFF & _CP_OFF
 
	 
	
	
	
		Re: External clock on 16f819 problem.
	
	
		To all intents and purposes a clock and oscillator are one and the same.
The answer lies at the end of the fuses list 4th from bottom      _EXTCLK needs setting as my programmer defaults to standard inc setting.
This is what I need :
 _LVP_OFF & _CP_OFF & _BODEN_ON & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _EXTCLK & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB3
	 
	
	
	
		Re: External clock on 16f819 problem.
	
	
		Hmm, I posted another reply but it vanished into the ether !
	 
	
	
	
		Re: External clock on 16f819 problem.
	
	
		OK, changing the INC file and putting that line in did the trick. Seems my programmer options don't work it always goes back to the standard INC, modifying that worked.
The LCD now responds in a single line format but I seem to be screwed up with the ADCON TRIS etc. No surprise there then.
I'll post the code once I have it from the other computer.
	 
	
	
	
		Re: External clock on 16f819 problem.
	
	
		OK, this is the test code. Just trying to reproduce characters.
The IN/OUTS ADC etc are there but there's no code to run them in this version.
The ADCON1 register is setup and the LCD displays one line but I need to study up the rest TRIS etc.
	Code:
	
'****************************************************************
'*  Name    :                                      *
'*  Author  : Rob Lane                                          *
'*  Notice  :                                                   *
'*          :                                                   *
'*  Date    : 13/01/2012                                        *
'*  Version : 1.0                                               *
'*  Notes   : Using 16f819                                      *
'*                                                              *
'****************************************************************
LCD_DB4    VAR PORTB.4 
LCD_DB5    VAR PORTB.5 
LCD_DB6    VAR PORTB.2 
LCD_DB7    VAR PORTB.7 
LCD_RS     VAR PORTA.2 
LCD_E      VAR PORTA.3 
LCD_Lines  CON 2 ' # of Lines on LCD, 1 or 2 (Note: use 2 for 4 lines) 
LCD_DATAUS CON 50 ' Data delay time in us 
LCD_COMMANDUS CON 2000 ' Command delay time in us
clear
  ' Define ADCIN parameters
Define        ADC_BITS        10        ' Set number of bits in result
Define        ADC_CLOCK        0        ' Set clock source (Fosc/2)
Define        ADC_SAMPLEUS        50        ' Set sampling time in uS
INCLUDE "LCD_AnyPin.pbp" ; *** Include MUST be AFTER LCD Pin assignments ****
'setup the custom characters
LCDOUT  $FE,$40,$01,$01,$01,$01,$01,$01,$01,$01  ' Cust Char #0 
LCDOUT  $FE,$48,$1F,$11,$11,$11,$11,$11,$11,$11  ' Cust Char #1  
LCDOUT  $FE,$50,$1F,$10,$10,$10,$10,$10,$10,$1F  ' Cust Char #2  
LCDOUT  $FE,$58,$01,$01,$01,$01,$01,$01,$01,$1F  ' Cust Char #3  
LCDOUT  $FE,$60,$1F,$11,$11,$11,$11,$11,$11,$1F  ' Cust Char #4  
LCDOUT  $FE,$68,$11,$11,$11,$11,$11,$11,$11,$1F  ' Cust Char #5  
LCDOUT  $FE,$70,$1F,$01,$01,$01,$01,$01,$01,$1F  ' Cust Char #6  
LCDOUT  $FE,$78,$1F,$01,$01,$01,$01,$01,$01,$01  ' Cust Char #7 
'setup the THICKER custom characters
'LCDOUT  $FE,$40,$03,$03,$03,$03,$03,$03,$03,$03  ' Cust Char #0 
'LCDOUT  $FE,$48,$1F,$1F,$1B,$1B,$1B,$1B,$1B,$1B  ' Cust Char #1  
'LCDOUT  $FE,$50,$1F,$1F,$18,$18,$18,$18,$1F,$1F  ' Cust Char #2  
'LCDOUT  $FE,$58,$03,$03,$03,$03,$03,$03,$1F,$1F  ' Cust Char #3  
'LCDOUT  $FE,$60,$1F,$1F,$1B,$1B,$1B,$1B,$1F,$1F  ' Cust Char #4  
'LCDOUT  $FE,$68,$1B,$1B,$1B,$1B,$1B,$1B,$1F,$1F  ' Cust Char #5  
'LCDOUT  $FE,$70,$1F,$1F,$03,$03,$03,$03,$1F,$1F  ' Cust Char #6  
'LCDOUT  $FE,$78,$1F,$1F,$03,$03,$03,$03,$03,$03  ' Cust Char #7 
nPos  var byte
nDig  var byte
in_count  var word
tr_out  var word
batt_volt  VAR BYTE
batt_adc var porta.0
freq_in var portb.6
freq_lockout var portb.3
'TRISA=%10001101
'TRISB=%01000000
'ADCON0=%00000000
ADCON1=%10001110   
LOW PortB.0                   ;r/w lcd line
'CONFIGURE DISPLAY 
pause 1000
ln1 con $80
ln2 con $C0
CS  con 1
pause 500
LCDOUT $FE,1
lcdout $fe, CS            ' Clear screen
main:  
        nDig=1 : npos=0 : gosub displaydigit  
        nDig=2 : npos=1 : gosub displaydigit
    nDig=3 : npos=2 : gosub displaydigit
    nDig=4 : npos=3 : gosub displaydigit
    lcdout $FE,$80+6,"Test" 
                   
goto main
  
displaydigit:
if ndig=0 then gosub zero
if ndig=1 then gosub One
if ndig=2 then gosub Two
if ndig=3 then gosub Three
if ndig=4 then gosub Four
if ndig=5 then gosub Five
if ndig=6 then gosub Six
if ndig=7 then gosub Seven
if ndig=8 then gosub Eight
if ndig=9 then gosub nine
return
           
Zero:
        LCDOUT $FE,$80+nPos,1
        LCDOUT $FE,$C0+nPos,5
return
One:
        LCDOUT $FE,$80+nPos,0
        LCDOUT $FE,$C0+nPos,0
return
Two:
        LCDOUT $FE,$80+nPos,7
        LCDOUT $FE,$C0+nPos,2
return
Three:
        LCDOUT $FE,$80+nPos,6
        LCDOUT $FE,$C0+nPos,3
return
Four:
        LCDOUT $FE,$80+nPos,5
        LCDOUT $FE,$C0+nPos,0
return
Five:
        LCDOUT $FE,$80+nPos,2
        LCDOUT $FE,$C0+nPos,3
return
Six:
        LCDOUT $FE,$80+nPos,2
        LCDOUT $FE,$C0+nPos,5
return
Seven:
        LCDOUT $FE,$80+nPos,7
        LCDOUT $FE,$C0+nPos,0
return
Eight:
        LCDOUT $FE,$80+nPos,4
        LCDOUT $FE,$C0+nPos,5
return
Nine:
        LCDOUT $FE,$80+nPos,4
        LCDOUT $FE,$C0+nPos,3
return
    
end
 
	 
	
	
	
		Re: External clock on 16f819 problem.
	
	
		I've studied the datasheet time and time again, I just don't get it. I need some help to understand what I'm missing here.
The LCD still gives one line with the code and fuses as mentioned in posts above.
BUT I can't see what's wrong.
I need the settings as follows:-
PortA.0    <----- ADC in
PortA.1    NC
PortA.2    -------> LCD RS
PortA.3    -------> LCD Enable
PortA.4   NC
PortA.5   NC
PortA.6   NC
PortA.7   <------  EXT Osc in (Working)
PortB.0   RW (Low, working)
PortB.1   NC
PortB.2   -----> LCD D6
PortB.3   -----> PWM Out
PortB.4   -----> LCD D4
PortB.5  ------> LCD D5
PortB.6  <----   clk count in for a ref frequency to compare against external clock using tmr
PortB.7  ------> LCD D7
I have set ADCON1=%10001110  without this the LCD is blank.
I've tried other settings but I'm now completely confused.
Can someone please help.
	 
	
	
	
		Re: External clock on 16f819 problem.
	
	
		I posted in the LCD_Anypin thread.
My code with LCD_Anypin works with a 10mhz crystal oscillator but produces strange results on the LCD with EXTCLK.
	 
	
	
	
		Re: External clock on 16f819 problem.
	
	
		
	Quote:
	
		
		
			I have set ADCON1=%10001110 without this the LCD is blank.
			
		
	
 
Datasheet page 83, section 11-0.
Read settings for ADCON0 and ADCON1.
At a glance, ADCON1 looks good, I think you need to set ADCON0 as well.
Robert