Autor Tema: Problemas con manejos bit a bit de un puerto...  (Leído 5581 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado STAI

  • PIC12
  • **
  • Mensajes: 81
Problemas con manejos bit a bit de un puerto...
« en: 20 de Septiembre de 2009, 15:10:05 »
Hola a todos estoy tratando de modificar un solo bit del PORTB de mi dsPIC33FJ... pero cuando hago la instrucción PORTbits.RB15 = 1 me modifica todo lo que tenía el PORTB..., alguien que me colabore con ese asuntico... estoy pensando que es mi compilador pero no estoy seguro... gracias...
Álvaro I. Sandoval T.
Ing. en Control Electrónico e Instrumentación

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18310
    • MicroPIC
Re: Problemas con manejos bit a bit de un puerto...
« Respuesta #1 en: 20 de Septiembre de 2009, 15:12:04 »
¿Utilizas C30?
En cualquier caso, prueba a escribir en el registro LAT, en lugar de directo al puerto.

Desconectado STAI

  • PIC12
  • **
  • Mensajes: 81
Re: Problemas con manejos bit a bit de un puerto...
« Respuesta #2 en: 20 de Septiembre de 2009, 15:44:07 »
Si nocturno el C30, y voy a intentar lo que me dices, muchas gracias... te estare comentando...
¿Utilizas C30?
En cualquier caso, prueba a escribir en el registro LAT, en lugar de directo al puerto.
Álvaro I. Sandoval T.
Ing. en Control Electrónico e Instrumentación

Desconectado STAI

  • PIC12
  • **
  • Mensajes: 81
Re: Problemas con manejos bit a bit de un puerto...
« Respuesta #3 en: 20 de Septiembre de 2009, 16:08:53 »
OK nocturno muchas gracias si me funciono, pero me queda la duda por qué no puedo utilizar PORTXbits.RBXX = #?
¿Utilizas C30?
En cualquier caso, prueba a escribir en el registro LAT, en lugar de directo al puerto.
Álvaro I. Sandoval T.
Ing. en Control Electrónico e Instrumentación

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18310
    • MicroPIC
Re: Problemas con manejos bit a bit de un puerto...
« Respuesta #4 en: 20 de Septiembre de 2009, 16:12:17 »
No estoy seguro, creo recordar que venía explicado en la datasheet, pero ahora mismo no me acuerdo porqué ocurre eso.

Desconectado RedPic

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 5552
    • Picmania by Redraven
Re: Problemas con manejos bit a bit de un puerto...
« Respuesta #5 en: 20 de Septiembre de 2009, 17:05:38 »
Del documento dspic30f family reference manual (70046e.pdf) Página 254 y siguientes:

11.2.2 PORT Registers
Data on an I/O pin is accessed via a PORTx register. A read of the PORTx register reads the
value of the I/O pin, while a write to the PORTx register writes the value to the port data latch.
Many instructions, such as BSET and BCLR instructions, are read-modify-write operations.
Therefore, a write to a port implies that the port pins are read, this value is modified, and then
written to the port data latch. Care should be taken when read-modify-write commands are used
on the PORTx registers and when some I/O pins associated with the port are configured as
inputs. If an I/O pin configured as an input is changed to an output at some later time, an unexpected
value may be output on the I/O pin. This effect occurs because the read-modify-write
instruction reads the instantaneous value on the input pin and loads that value into the port data
latch.


11.2.3 LAT Registers
The LATx register associated with an I/O pin eliminates the problems that could occur with
read-modify-write instructions. A read of the LATx register returns the values held in the port
output latches, instead of the values on the I/O pins. A read-modify-write operation on the LAT
register, associated with an I/O port, avoids the possibility of writing the input pin values into the
port latches. A write to the LATx register has the same effect as a write to the PORTx register.
The differences between the PORT and LAT registers can be summarized as follows:
• A write to the PORTx register writes the data value to the port latch.
• A write to the LATx register writes the data value to the port latch.
• A read of the PORTx register reads the data value on the I/O pin.
• A read of the LATx register reads the data value held in the port latch.
Any bit and its associated data and control registers that are not valid for a particular device will
be disabled. That means the corresponding LATx and TRISx registers, and the port pin, will read
as zeros


La diferencia fundamental está en que hay instrucciones que implican escritura que al actuar directamente sobre el registro del PORT realizan una lectura del estado del PORT que es transferida al LATCH,  pudiendo darse entonces un estado contradictorio entre el estado del PORT y del LATCH, al cambiar posteriormente el TRIS del puerto puede producirse un estado indefinido del mismo. Por ello aconsejan solo "leer" el PORT, no escribir en él pero por el contrario "leer"  y "escribir" alegremente el LATCH ya que éste no presenta los problemas del PORT.

Contra la estupidez los propios dioses luchan en vano. Schiller
Mi Güeb : Picmania

Desconectado STAI

  • PIC12
  • **
  • Mensajes: 81
Re: Problemas con manejos bit a bit de un puerto...
« Respuesta #6 en: 20 de Septiembre de 2009, 17:56:18 »
OK nocturno muchas gracias por tu completa explicación, exitos...

Del documento dspic30f family reference manual (70046e.pdf) Página 254 y siguientes:

11.2.2 PORT Registers
Data on an I/O pin is accessed via a PORTx register. A read of the PORTx register reads the
value of the I/O pin, while a write to the PORTx register writes the value to the port data latch.
Many instructions, such as BSET and BCLR instructions, are read-modify-write operations.
Therefore, a write to a port implies that the port pins are read, this value is modified, and then
written to the port data latch. Care should be taken when read-modify-write commands are used
on the PORTx registers and when some I/O pins associated with the port are configured as
inputs. If an I/O pin configured as an input is changed to an output at some later time, an unexpected
value may be output on the I/O pin. This effect occurs because the read-modify-write
instruction reads the instantaneous value on the input pin and loads that value into the port data
latch.


11.2.3 LAT Registers
The LATx register associated with an I/O pin eliminates the problems that could occur with
read-modify-write instructions. A read of the LATx register returns the values held in the port
output latches, instead of the values on the I/O pins. A read-modify-write operation on the LAT
register, associated with an I/O port, avoids the possibility of writing the input pin values into the
port latches. A write to the LATx register has the same effect as a write to the PORTx register.
The differences between the PORT and LAT registers can be summarized as follows:
• A write to the PORTx register writes the data value to the port latch.
• A write to the LATx register writes the data value to the port latch.
• A read of the PORTx register reads the data value on the I/O pin.
• A read of the LATx register reads the data value held in the port latch.
Any bit and its associated data and control registers that are not valid for a particular device will
be disabled. That means the corresponding LATx and TRISx registers, and the port pin, will read
as zeros


La diferencia fundamental está en que hay instrucciones que implican escritura que al actuar directamente sobre el registro del PORT realizan una lectura del estado del PORT que es transferida al LATCH,  pudiendo darse entonces un estado contradictorio entre el estado del PORT y del LATCH, al cambiar posteriormente el TRIS del puerto puede producirse un estado indefinido del mismo. Por ello aconsejan solo "leer" el PORT, no escribir en él pero por el contrario "leer"  y "escribir" alegremente el LATCH ya que éste no presenta los problemas del PORT.


Álvaro I. Sandoval T.
Ing. en Control Electrónico e Instrumentación

Desconectado RedPic

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 5552
    • Picmania by Redraven
Re: Problemas con manejos bit a bit de un puerto...
« Respuesta #7 en: 21 de Septiembre de 2009, 04:10:15 »

OK nocturno muchas gracias por tu completa explicación, exitos...


De nada ... pero no soy Nocturno.  :mrgreen:
Contra la estupidez los propios dioses luchan en vano. Schiller
Mi Güeb : Picmania

Desconectado BrunoF

  • Administrador
  • DsPIC30
  • *******
  • Mensajes: 3865
Re: Problemas con manejos bit a bit de un puerto...
« Respuesta #8 en: 21 de Septiembre de 2009, 04:28:55 »
Ah! ya los confunden. :mrgreen: :mrgreen: :mrgreen:
"All of the books in the world contain no more information than is broadcast as video in a single large American city in a single year. Not all bits have equal value."  -- Carl Sagan

Sólo responderé a mensajes personales, por asuntos personales. El resto de las consultas DEBEN ser escritas en el foro público. Gracias.

Desconectado STAI

  • PIC12
  • **
  • Mensajes: 81
Re: Problemas con manejos bit a bit de un puerto...
« Respuesta #9 en: 21 de Septiembre de 2009, 12:21:59 »
Un hermano qué pena, miré muy de afan y no me fije bien, muchas gracias... exitos...

[/quote]

De nada ... pero no soy Nocturno.  :mrgreen:
[/quote]
Álvaro I. Sandoval T.
Ing. en Control Electrónico e Instrumentación

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18310
    • MicroPIC
Re: Problemas con manejos bit a bit de un puerto...
« Respuesta #10 en: 21 de Septiembre de 2009, 14:50:29 »
Por mí no hay problema, es un honor que me confundas con él.


 

anything