PDA

View Full Version : SEROUT2 fails on newer 18F2610



gabrielg74
- 5th March 2008, 00:48
Hello,

I've been programming 18F2610s for several years now without a problem.
Now, I got a new batch of 18F2610s date coded 0804, and using the exact same code from several years it does not work. SEROUT2 sends out garbage.

I have a couple of older PICs date coded 0427 and 0730 and they work just fine, but 12 newer ones just won't work.

Is anybody aware of a silicon update that could affect SEROUT2 on this PIC?

Is there a workaround for this?

Any help will be greatly appreciated.

Thanks, Gabriel

skimask
- 5th March 2008, 13:56
Hello,
I've been programming 18F2610s for several years now without a problem.
Now, I got a new batch of 18F2610s date coded 0804, and using the exact same code from several years it does not work. SEROUT2 sends out garbage.
I have a couple of older PICs date coded 0427 and 0730 and they work just fine, but 12 newer ones just won't work.
Is anybody aware of a silicon update that could affect SEROUT2 on this PIC?
Is there a workaround for this?
Any help will be greatly appreciated.
Thanks, Gabriel

Internal or external oscillator?

gabrielg74
- 5th March 2008, 17:17
External, 20MHz crystal.
Tried 5 different boards with the new PIC (fails) and with the old one (works ok).

Gabriel

skimask
- 5th March 2008, 17:28
External, 20MHz crystal.
Tried 5 different boards with the new PIC (fails) and with the old one (works ok).

Gabriel

Just looked at the ERRATA sheets from Microchip.
Nothing specific to that particular issue, but a lot of things that could be tied into it.
Suggest paging thru them to see if you can find anything.

Which version of PBP are you using?

gabrielg74
- 5th March 2008, 17:33
PBP 2.4.6.0

Already checked the Errata and could not find anything that could be causing this.

Gabriel

skimask
- 5th March 2008, 17:39
PBP 2.4.6.0

Already checked the Errata and could not find anything that could be causing this.

Gabriel

Well,,,,,,,,,,show the code. Maybe there's a bit changed in there somewhere.

gabrielg74
- 5th March 2008, 19:04
I tried changing wait times and serial speed and still does not work.

Here is the offending code:

'------------------------------------------------------------------------------
'Initial config
'------------------------------------------------------------------------------
DEFINE OSC 20 'Osc 20MHz
DEFINE NO_CLRWDT 1 'WDT inactive

'------------------------------------------------------------------------------
'Port definition
'------------------------------------------------------------------------------
SCL3W VAR PortA.0 'Puerto de reloj del RTC (3 wire)
IO3W VAR PortA.1 'Puerto de datos del RTC (3 wire)
RST3W VAR PortA.2 'Puerto de reset del RTC (3 wire)
TXLCD VAR PortA.3 'Puerto de TX del LCD
MCLRLCD VAR PortA.5 'Puerto de reset del LCD
RARROW VAR PortB.0 'Boton a la derecha
UARROW VAR PortB.1 'Boton hacia arriba
DARROW VAR PortB.2 'Boton hacia abajo
LARROW VAR PortB.3 'Boton a la izquierda
TXPRTR VAR PortB.4 'Puerto serie asinc. para impresora TX
RXPRTR VAR PortB.5 'Puerto serie asinc. para impresora RX
KSWITCH VAR PortB.6 'Llave
ACDETECT VAR PortB.7 'Deteccion de AC
EE1 VAR PortC.0 'Habilita memoria EEPROM principal
EE2 VAR PortC.1 'Habilita memoria EEPROM secundaria
IROUT VAR PortC.2 'Salida serial IR
SCLI2C VAR PortC.3 'Puerto de reloj I2C para EEPROMs
SDAI2C VAR PortC.4 'Puerto de datos I2C para EEPROMs
IRIN VAR PortC.5 'Entrada serial de IR
TXPC VAR PortC.6 'Puerto serie asinc. para PC TX (impresora 2)
RXPC VAR PortC.7 'Puerto serie asinc. para PC RX (impresora 2)

main:
'+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++
'Initialize PIC hardware
'+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++
Init_Hardware:
ASM
movlw B'00111111'
movwf ADCON1 ;Port A is digital I/O

clrf PORTA ;Clear port A data latches
clrf PORTB ;Clear port B data latches
bsf PORTB,4 ;Printer port initial state
clrf PORTC ;Clear port C data latches
bsf PORTC,3 ;Initial state of RC3 (SCL)

bcf INTCON2,RBPU ;Enable pull-ups on port B

movlw B'00010010' ;RA1 & RA4 inputs
movwf TRISA ;

movlw B'11101111' ;RB4 output
movwf TRISB ;

movlw B'10110011' ;RC2 & RC3 outputs, RC6 & RC7 serial port
movwf TRISC ;(TX y RX)

ENDASM


'+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++
'Initialize LCD
'+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++
Init_LCD:
PAUSE 1000 'Wait for everything to power up
TXLCD=1 'Initial State of LCD comm line
MCLRLCD=1 'Enable LCD
PAUSE 100 'Wait 100ms for LCD to startup
SEROUT2 TXLCD,84,["U"] 'Send a "U" to sync comm speed
PAUSE 60
SEROUT2 TXLCD,84,[$01] 'Clear LCD
PAUSE 5
SEROUT2 TXLCD,84,[$0C] 'Turn off insertion point
PAUSE 5
SEROUT2 TXLCD,84,["Control de Impr."]
PAUSE 10
SEROUT2 TXLCD,84,[$00,$40,"v 5.0b"]
PAUSE 5000 'Display initial message for 5 seconds
SEROUT2 TXLCD,84,[$01] 'Clear LCD
PAUSE 50

'+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++

END

skimask
- 5th March 2008, 22:02
DEFINE NO_CLRWDT 1 'WDT inactive
Doesn't actually turn off the WDT. It just instructs PBP NOT to insert CLEARWDT instructions.
Might actually be getting an WDT interrupt in the middle of the SEROUT2 execution.
Check your programmer/.inc file settings.

gabrielg74
- 5th March 2008, 22:08
I have isolated the problem even more, it is not an instruction problem, it is a PORT A problem. If I set PortA.3 high and then set PortA.5 high, PortA.3 will ALWAYS go low. For example if I do this instructions:

PortA.3 = 1
PortA.5 = 1

or

TXLCD = 1
MCLRLCD = 1

or

@ bsf PORTA,3
@ bsf PORTA,5

PortA.3 will ALWAYS go low after PortA.5 goes high.
But if I reverse the instructions (first set PortA.5 then set PortA.3) it works OK.

I don't have the slightest idea what is happening, but it is affecting my program only when used on PICs date coded 08XX.

I hope anyone can help me solve this problem.

Thanks,

Gabriel

Bruce
- 5th March 2008, 22:52
Change;

TXLCD VAR PortA.3 'Puerto de TX del LCD
MCLRLCD VAR PortA.5 'Puerto de reset del LCD

to;

TXLCD VAR LATA.3 'Puerto de TX del LCD
MCLRLCD VAR LATA.5 'Puerto de reset del LCD

Does it work now?

gabrielg74
- 5th March 2008, 23:10
Thank you for your help. We solved the problem.
I don't have an explanation, but it works now.
All I did was change ADCON1=B'00111111' to ADCON1=B'00001111'
And now it works just as expected on older and newer PICs.

I still am interested in an explanation, so if anyone would like to elaborate....


Thanks, Gabriel

Bruce
- 5th March 2008, 23:50
Apparantly even with A/D disabled it's still causing problems when you have AN2 & AN3
setup as Vref- & Vref+. Clearing ADCON1 bits 4 & 5 sets Vref to Vss & Vdd, and not these
pins.

The problem you describe sounds like read-modify-write, which is more of a problem when
an output has external capacitance on it. By having ADCON1.4 = 1, AN3 is connected to
an internal circuit for Vref+. This most likely is adding enough capacitance to cause the
read-modify-write issue.

What happens is when you set RA3, it does not change fast enough before you are setting
RA5, so RA3 is read back in, then writen again on the write to RA5 causing a 0 to be writen
back to RA3.

This would also explain why it works when you reverse the order. I.E. RA5=1 then RA3=1.
It works because the extra capacitance is not present on RA5.

gabrielg74
- 6th March 2008, 00:41
Thank you for your explanation.

I could not find this in the Errata for this PIC. Maybe it is not documented.

Gabriel

Bruce
- 6th March 2008, 14:07
I doubt you will find anything on this in an errata doc. You should disconnect pins from the internal Vref circuit if they are not being used for Vref, and adjust your code as required to avoid read-modify-write problems.

Writing to the LAT registers VS port registers on the 18F series takes care of r-m-w.

skimask
- 6th March 2008, 16:35
Thank you for your explanation.
I could not find this in the Errata for this PIC. Maybe it is not documented.
Gabriel

Like Brue said above, it's not neccessaily in the Errata sheets, but the datasheets themselves usually have a little blurb about R-M-W issues somewhere.
It's a 'gotcha'. It'll get you this time...and it'll get you again probably in a few years.