PDA

View Full Version : 12F1840 config issues



enigma
- 10th February 2015, 19:38
Hi All
I searched for an answer to this but came up blank. The program has been reduced to a single serout2 command to test. It works fine on both a 12F683 and 16F688 with the correct configs but I cant seem to get it to function on the 12F1840. There is data out but its garbage and clearly the wrong baud rate. I suspect I have not configured something, probably the oscillator correctly so requesting help. Its probably obvious but I cant spot it.
Cheers Pete

Code: PBP3


#CONFIG

__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_ON & _BOREN_OFF
__CONFIG _CONFIG2, _PLLEN_ON & _BORV_LO & _LVP_OFF

#ENDCONFIG

OPTION_REG = %10000001
WPUA = %00000000 'weak pull ups disabled
ANSELA = %00000000 'Select all digital
TRISA = %00001101 ' Make A0,A2,A3 inputs,A1,A4,A5 outputs

OSCCON = %11110000 'SET INTOSC TO 32MHZ
OSCTUNE = %00000000

INTCON = 0 'Latch out interrupt
CM1CON0 = 0 'disable comparators
FVRCON = 0 'Fixed voltage reference disabled


DEFINE OSC 32

Test:
serout2 PORTA.5,16468,["Testing",13,10]

pause 1000
goto Test

Acetronics2
- 10th February 2015, 20:55
Hi Enigma




' Config
'************************************************* ******************************

#IF __PROCESSOR__ = "12F1840"

#CONFIG
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_ALL & _PLLEN_ON & _STVREN_OFF & _BORV_LO & _LVP_OFF
#ENDCONFIG

#ELSE
#MSG "Wrong Processor selected!"
#ENDIF

'************************************************* ****************************
'Includes
'************************************************* ****************************

INCLUDE "DT_INTS-14-2k.bas"
INCLUDE "ReEnterPBP.bas"

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?

INT_Handler TMR1_INT, _ClockCount, PBP, yes

endm
INT_CREATE ; Creates the interrupt processor
ENDASM


INTCON.7 = 0 ' Pour čtre sur !!!

'************************************************* ******************************
' Ports init

TRISA = 0
PORTA = 0
LATA = 0

NeoPinW1 VAR LATA.0
NeoPinW2 VAR LATA.1
NeoPinR VAR LATA.2

'************************************************* ******************************
' Chip Initialization

OSCCON = %11110000 ' 8 Mhz internal x 4
OSCTUNE = %00000000 ' Internal osc Adjustment

WHILE !OSCSTAT.3 ' Wait for stable OSC ...
WEND

INTCON = 0
CPSCON0 = 0
CPSCON1 = 0
ADCON0 = 0
ADCON1 = %10000000
ANSELA = 0
CCP1CON = 0
CM1CON0 = 0
DACCON0 = 0
FVRCON = 0

' Timer 1

T1CON = %00110101 ' Preload @ 15536, PS=8, run
T1GCON = 0
INTCON = %11000000
PIE1 = %00000001
PIR1 = 0


This config works ...

But I remember It was somewhat tricky ...

I think this


WHILE !OSCSTAT.3 ' Wait for stable OSC ...
WEND

made the chip run fine ...

Alain

Charlie
- 11th February 2015, 14:12
Your clock setup looks fine, but you can always do a blink test to confirm.
However, what baud rate are you trying to achieve? 16468 seems to be about 60 baud by my calculations?

Dave
- 11th February 2015, 15:09
It looks like 9600 baud by my calculations w/ open wire mode enabled. As far as the config's go everything looks good. Here is my config's for a Waterstick I designed and works great.


DEFINE OSC 32

#CONFIG
;----- CONFIG1 Options --------------------------------------------------
__config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON

;----- CONFIG2 Options --------------------------------------------------
__config _CONFIG2, _WRT_OFF & _PLLEN_ON & _STVREN_ON & _BORV_19 & _LVP_OFF
#ENDCONFIG

' ************************************************** ******************
' SYSTEM INITIALIZATION
' ************************************************** ******************
clear
PORTA = %00000000
TRISA = %00001111 'INITIALIZE PORT DIRECTIONS
OSCCON = %11110000 'PLL ENABLED,8Mhz,FSOSC<2:0>
INTCON = %00000000 'CLEAR GIE,PEIE,TMR0IE,INTE,RBIE,TMR0IF,INTF,RBIF
PIE1 = %00000000 'CLEAR ALL INTERRUPT ENABLE BITS
PIR1 = %00000000 'CLEAR ALL INTERRUPT FLAGS
PIE2 = %00000000 'CLEAR ALL INTERRUPT ENABLE BITS
PIR2 = %00000000 'CLEAR ALL INTERRUPT FLAGS
APFCON = %00000000 'ALL DEFAULTS
ANSELA = %00000011 'AN0:AN1 ANALOG,AN2:AN4 DIGITAL I/O
CPSCON0 = %11001100 'ENABLE CAP SENSE,DAC/FVR,HIGH RANGE
WPUA = %00001100 'WEAK PULLUP'S OFF, EXCEPT A.2,A.3
ADCON0 = %00000000 'CHS2:0,GO/DONE,ADOFF
ADCON1 = %11100000 'RIGHT JUSTIFIED,FOSC/64,VSS,VDD
SRCON0 = %00000000
SRCON1 = %00000000
CM1CON0 = %00000000 'CLEAR/DISABLE COMPARATOR
CM1CON1 = %00000000 'CLEAR/DISABLE COMPARATOR
CMOUT = %00000000 'DISABLE OUTPUT REGISTER
DACCON0 = %11001000 'ENABLE DAC,ENABLE POS REFERENCE,SOURCE IS FVR
DACCON1 = %00001000 'SET FOR 1/4 SCALE (8) ~ 1.024
FVRCON = %10001100 'ENABLE VOLTAGE REFERENCE,4,096
OPTION_REG = %00000000 'INTEDG,T0CS,T0SE,PSA,PS
T1CON = %11000001 'CAPOSC INPUT,PRESCALER 1/1,START TIMER 1
T1GCON = %00000000 'NO GATE CONTROL
T2CON = %00000000 'POSTSCALER 1/1,STOP,PRESCALER 1
TMR2 = 0 'CLEAR TMR2 MODULE REGISTER
PR2 = 255 'SET PERIOD ((((1 / 32,000,000)*4) * 1 PRESCALE) * (1+255 PR2)) = 31.25 KHZ.
CCP1CON = %00000000 'PLACE CCP1 INTO DISABLE MODE
CCPR1L = $00 'CLEAR CCP1 LOWER 8 BITS
CCPR1H = $00 'CLEAR CCP1 UPPER 2 BITS
PSTR1CON = %00000001'DEFAULT

enigma
- 11th February 2015, 16:34
Many thanks, I will run through these and see. These seem tricky beasts to set up and I am sure I have probably not set something I need to. Will report back! Cheers Pete

enigma
- 12th February 2015, 09:36
I now have the code below. The serial data appears to come out at intervals of one second but is complete garbage still. Replacing the PIC with an appropriately configured 12F683 all functions fine. I am wondering if anyone else can replicate a serout2 on the 12F1840 and see if its the same. If the code looks good I am wondering if its a problem with PBP?. Cheers Pete


:
#CONFIG
;----- CONFIG1 Options --------------------------------------------------
__config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON

;----- CONFIG2 Options --------------------------------------------------
__config _CONFIG2, _WRT_OFF & _PLLEN_ON & _STVREN_ON & _BORV_19 & _LVP_OFF
#ENDCONFIG

' ************************************************** ******************
' SYSTEM INITIALIZATION
' ************************************************** ******************
clear
'PORTA = %00000000
TRISA = %00001101 ' Make A0,A2,A3 inputs,A1,A4,A5 outputs
OSCCON = %11110000 'PLL ENABLED,8Mhz,FSOSC<2:0>
OSCTUNE = %00000000 ' Internal osc Adjustment
WHILE !OSCSTAT.3 ' Wait for stable OSC ...
WEND
INTCON = %00000000 'CLEAR GIE,PEIE,TMR0IE,INTE,RBIE,TMR0IF,INTF,RBIF
PIE1 = %00000000 'CLEAR ALL INTERRUPT ENABLE BITS
PIR1 = %00000000 'CLEAR ALL INTERRUPT FLAGS
PIE2 = %00000000 'CLEAR ALL INTERRUPT ENABLE BITS
PIR2 = %00000000 'CLEAR ALL INTERRUPT FLAGS
APFCON = %00000000 'ALL DEFAULTS
ANSELA = %00000000 'Select all digital
CPSCON0 = %11001100 'ENABLE CAP SENSE,DAC/FVR,HIGH RANGE
WPUA = %00000000 'weak pull ups disabled
ADCON0 = %00000000 'CHS2:0,GO/DONE,ADOFF
ADCON1 = %11100000 'RIGHT JUSTIFIED,FOSC/64,VSS,VDD
SRCON0 = %00000000
SRCON1 = %00000000
CM1CON0 = %00000000 'CLEAR/DISABLE COMPARATOR
CM1CON1 = %00000000 'CLEAR/DISABLE COMPARATOR
CMOUT = %00000000 'DISABLE OUTPUT REGISTER
DACCON0 = %11001000 'ENABLE DAC,ENABLE POS REFERENCE,SOURCE IS FVR
DACCON1 = %00001000 'SET FOR 1/4 SCALE (8) ~ 1.024
FVRCON = %10001100 'ENABLE VOLTAGE REFERENCE,4,096
OPTION_REG = %00000000 'INTEDG,T0CS,T0SE,PSA,PS
T1CON = %11000001 'CAPOSC INPUT,PRESCALER 1/1,START TIMER 1
T1GCON = %00000000 'NO GATE CONTROL
T2CON = %00000000 'POSTSCALER 1/1,STOP,PRESCALER 1
TMR2 = 0 'CLEAR TMR2 MODULE REGISTER
PR2 = 255 'SET PERIOD ((((1 / 32,000,000)*4) * 1 PRESCALE) * (1+255 PR2)) = 31.25 KHZ.
CCP1CON = %00000000 'PLACE CCP1 INTO DISABLE MODE
CCPR1L = $00 'CLEAR CCP1 LOWER 8 BITS
CCPR1H = $00 'CLEAR CCP1 UPPER 2 BITS
PSTR1CON = %00000001'DEFAULT
FVRCON = 0 'Fixed voltage reference disabled

DEFINE OSC 32

initialise:
serout2 PORTA.5,16468,["Waiting for X200",13,10]
pause 1000
goto initialise

Charlie
- 12th February 2015, 14:00
I guess SEROUT2 has changed for PBP3, because in PBP 2.6, the number 16468 is definitely wrong.
Anyway, are you seeing any characters correctly? If so, you may need to put a pause between characters. I needed to do this with the 1840 talking to some devices.
The clock may also be slightly off, causing some characters to get messed up.

HenrikOlsson
- 12th February 2015, 14:30
According to the manual (http://pbp3.com/downloads/PBP_Reference_Manual.pdf) 16468 would be 9600, driven, inverted, no parity. Bit 15 is set which means driven, bit 14 says inverted, bit 13 says no parity. The rest of the bits says 84 which according to the formuala (1000000 / baud - 20) should result in 9600 baud.

/Henrik.

enigma
- 12th February 2015, 18:12
Yes 9600 inverted and the same line works correctly on other PIC types I have tried, its only with the 12F1840 it doesnt

amgen
- 12th February 2015, 19:37
if you cant check clock with frequency meter.......... add in loop once per second (on serout) increment or decrement osctune to see if characters come in view then try to figure about how far off and in what direction (raise/lower freq)
amgen

Archangel
- 12th February 2015, 20:55
Try Turning off the fail safe clock monitor, if I understand correctly it monitors an EXTERNAL clock. . .
I would TRY altering bit 1 in OSCON just to see if it has any effect . . .

I would add to config1
_IESO_OFF ; Internal/External Switchover mode is disabled

and I would disable WDT while troubleshooting at least once to judge if it has any effect.

Oh yes, I would make a blinky program to test my configs without any serouts . . . a stopwatch using a blinky will give you a rough idea as to whether or not you are running at expected OSC speed.

enigma
- 13th February 2015, 07:34
Hi All

I LED on the same pin configured to blink once per second, does just that so I am pretty sure some configs are right. I`ll try the last suggestions and see before I put in a support message. Many thanks for all the help! Cheers Pete

Archangel
- 14th February 2015, 10:29
Hi Pete,
Do you think trying to use timer 1 and trying to output serial data on T1 Clkin pin might be in conflict? I don't know, just sayin' . . . Have you tried using another pin, say RA1?

enigma
- 15th February 2015, 07:49
That's possible, I am not using timer 1 though so I will look to disable it. Unfortunately this is a PIC upgrade from a 12F683 so I am stuck with using the same pins for this app. I've sent a support question to MELabs and I`ll post the findings. Many thanks!