Autor Tema: Recepcion DMX con Atmega8515  (Leído 8660 veces)

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

Desconectado stk500

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 4923
Recepcion DMX con Atmega8515
« en: 27 de Abril de 2008, 06:55:23 »
Hola Amigos!
Tengo un pequeños problema al Programar los Fuses con Studio4 de Atmel y el programdor STK500 ya que con el Pony programa me va pero con el STK500 no se como activar los Fuse, se que el pony al programar los Fuse lo tiene invertido y trato de hacerlo con el STK500 sin resultados, aqui os dejos el programa de ejemplo para recibir 2 canales DMX.
// Example of dmx_in usage
// 04.06.06
// (c)Hendrik Hölscher      

.include "m8515def.inc"

      #define SREGbuf        R2
      #define tempL       R16
      #define tempH       R17
      
      #define DMX_FIELD    0x60   //direcion base dmx array
      #define DMX_CHANNELS 2      //numero de canales
      #define DMXstate    R18   //Registro de Estatuto para DMX-ISR (r16-r31)

      #define F_OSC       8000     //frecuencia del oscilador en kHz (tipica 8MHz o 16MHz)
      #define USE_DIP            //should get start address from DIPs?

/* ****set interrupt-routines */

.org 0
   rjmp reset             /* reset vector address */
   reti               /* External Interrupt0 Vector Address */
   reti                /* External Interrupt1 Vector Address */
   reti               /* Input Capture1 Interrupt Vector Address */
   reti                /* Output Compare1A Interrupt Vector Address */
   reti               /* Output Compare1B Interrupt Vector Address */
   reti                /* Overflow1 Interrupt Vector Address */
   reti               /* Overflow0 Interrupt Vector Address */
   reti               /* SPI Interrupt Vector Address */
   rjmp get_byte         /* UART Receive Complete Interrupt Vector Address */
   reti               /* UART Data Register Empty Interrupt Vector Address */
   reti               /* UART Transmit Complete Interrupt Vector Address */
   reti                /* Analog Comparator Interrupt Vector Address */
   reti               /* External Interrupt2 Vector Address */
   reti               /* Output Compare0 Interrupt Vector Address */
   reti               /*  EEPROM Interrupt Vector Address */
   reti               /*  SPM complete Interrupt Vector Address */
   reti               /*  SPM complete Interrupt Vector Address */   

reset:

cli

/* ***** poner los punto stack */
   ldi      tempL,  low(RAMEND)
   ldi    tempH, high(RAMEND)
   out      SPL,tempL
   out    SPH,tempH

/* **** puerto de led */
   ser    tempL
   out      DDRE, tempL
   out      PortE, tempL

/* **** inicial recibiendo DMX  */
   rcall   init_dmx

   sei                        ;permitir interrupciones


main:
   rcall   eval_dmx            ;evaluar data dmx
   rjmp   main

 
  eval_dmx:
   lds      tempL, DMX_FIELD      ;conseguir primer canal (2do is DMX_FIELD +1)
   cpi      tempL, 127            ;is temp >127?
   brsh   led_on
   sbi      PortE, PE0            ;conmutar LED1 apagado
   ret
   led_on:
    cbi      PortE, PE0            ;conmutar LED1 encendido
   ret



/* ***** include lib */

;**** A P P L I C A T I O N   N O T E   ************************************
;*
;* Title      : DMX512 reception library
;* Version      : v1.3
;* Last updated   : 21.04.07
;* Target      : Transceiver Rev.3.01 [ATmega8515]
;* Clock      : 8MHz, 16MHz
;*
;* written by hendrik hoelscher
;***************************************************************************
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version2 of
; the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; General Public License for more details.
;
; If you have no copy of the GNU General Public License, write to the
; Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
; For other license models, please contact the author.
;
;***************************************************************************


 /************* Definitions in main source **********************
      
      #define USE_DIP            //usamos un DIP-Switch para direcional
      #define DMX_FIELD    0x60   //direcion Base del DMX array
      #define DMX_CHANNELS 8      //numero de canales
      #define DMXstate    R18   //estatos del registro para DMX-ISR (r16-r31)
     //X-Pointer reserved for DMX ISR!!

      #define F_OSC       8000     //frecuencia de Oscilacion en kHz (tipico 8MHz or 16MHz)

 **************************************************************/

   
init_dmx:
   ;**** PortD
      sbi      DDRD,  PD2
      cbi      PortD, PD2            ;activamos Recepcion

   ;**** USART
       ldi    tempL, ((F_OSC/4000)-1)    ;activamos la Usart a 250 kbaud
       out    UBRRL, tempL
       clr    tempL
       out    UBRRH, tempL
       ldi    tempL, (1<<URSEL)|(3<<UCSZ0)|(1<<USBS)
       out    UCSRC, tempL         
      in      tempL,UDR
       clr      tempL
      out      UCSRA,tempL      
      sbi    UCSRB,RXCIE
      sbi    UCSRB,RXEN         

#ifdef USE_DIP
   ;**** PortC
      clr    tempL
      out    DDRC, tempL
      ser    tempL
      out    PortC, tempL              ;entrada con PullUp para Dip_Switch
   
   ;**** PortE
      in      tempL, DDRE
      cbr       tempL, (1<<1)|(1<<2)
      out    DDRE, tempL
      in      tempL, PortE
      sbr       tempL, (1<<1)|(1<<2)
      out    PortE, tempL             ;PE2 & OPCION Pullup
#endif

   ;**** memory
      ldi      XH, high(DMX_FIELD)
      ldi      XL,  low(DMX_FIELD)
      clr      tempL                  ;ponemos todos los  canales a cero
      ldi    DMXstate, DMX_CHANNELS
   write_RxD:   
      st       X+,tempL
      dec      DMXstate
      brne   write_RxD

   //   clr    DMXstate               ;ponemos DMX estatuto para esperar por Reset
      ret


/* ***********************************************************************************************************
 *               DMX recepcion ISR
 ************************************************************************************************************/
get_byte:
      in      SREGbuf, SREG
      push   tempH
      push   tempL      

      in      tempL,UCSRA      ;conseguimos el estatuto ante de Registrar Data
      in      tempH,UDR

      sbrc   tempL,FE      ;checkeamos error de frame para ir a Reset
      rjmp   dmx_frame_error   
      
      cpi      DMXstate, 1      ;checkeamos for iniciar byte (debe ser 0)
      breq   dmx_startbyte

        cpi    DMXstate, 2      ;checkeamos para iniciar direcion
      breq    dmx_startadr
        
       cpi    DMXstate, 3   
        brsh   dmx_handle_byte

   dmx_finish:
      pop      tempL
      pop      tempH
      out     SREG, SREGbuf   
      reti         

   dmx_startbyte:
      tst    tempH                ;si es Cero-> iniciamos byte
      brne    dmx_err
      inc     DMXstate             ;sigueinte -> inicio de direcion

#ifdef USE_DIP
      in       XL, PinC             ;conseguimos iniciar direcion
      com     XL
      clr      XH
      sbis   PinE, PE2            ;el Noveno bit
      inc      XH
#else
      rcall   get_address
#endif
      rjmp   dmx_finish

    dmx_startadr:
      sbiw   XH:XL, 1
      brne   dmx_finish
      ldi    XH, high(DMX_FIELD)
      ldi      XL,  low(DMX_FIELD)
      inc     DMXstate             ;siguiente-> tratar data
      
   dmx_handle_byte:         
      st      X+, tempH

      cpi      XL, low(DMX_FIELD +DMX_CHANNELS)
      brne   dmx_finish
      cpi      XH, high(DMX_FIELD +DMX_CHANNELS)
      brne   dmx_finish   
      clr      DMXstate
      rjmp   dmx_finish
   
    dmx_frame_error:
      ldi    DMXstate, 1            ;FE detectamos un break
      cbi      UCSRA,FE            ;further framing errors, caused by longer breaks
      rjmp   dmx_finish

   dmx_err:
       clr    DMXstate            ;esperamos por error deframe         
      rjmp   dmx_finish
claro esta que el Oscilador lo uso Externo de 8Mhz y ahi tengo el lio ya que el Studio4 trae un monton de configuracion de Fuses, por eso opino que Atmel me Decepciona muchos  :x por mas que leo no encuentro el Rollo como configurarlo.


Desconectado stk500

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 4923
Re: Recepcion DMX con Atmega8515
« Respuesta #1 en: 27 de Abril de 2008, 10:37:01 »
aqui os dejo tambien la version de Compiler C

#include "lib_dmx_in.h"

int main(void)
{
cli();
DDRD |= (1<<PD7);               //red LED pin is output
init_DMX();
sei();
for(;;)
   {
   get_dips();
   if (DmxField[0] >= 127)         //enable LED if 1st DMX val is >127
      {
      PORTD &= ~(1<<PD7);         //LED ON
      }
   else
      {
      PORTD |= (1<<PD7);         //LED OFF
      }
   }
}




la libreria
/**** A P P L I C A T I O N   N O T E   ************************************
*
* Title         : DMX512 reception library
* Version      : v1.2
* Last updated   : 21.04.07
* Target      : Transceiver Rev.3.01 [ATmega8515]
* Clock         : 8MHz, 16MHz
*
* written by hendrik hoelscher, www.hoelscher-hi.de
***************************************************************************
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version2 of
 the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 General Public License for more details.

 If you have no copy of the GNU General Public License, write to the
 Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 For other license models, please contact the author.

;***************************************************************************/

#include "lib_dmx_in.h"

// ********************* local definitions *********************

enum {IDLE, BREAK, STARTB, STARTADR};         //DMX states

       uint8_t     gDmxState;
       uint8_t    *gDmxPnt;
       uint16_t    DmxCount;


// *************** DMX Reception Initialisation ****************
void init_DMX(void)
{
#ifdef USE_DIP
DDRC= 0;                              //set up DIPs
PORTC= 0xFF;
DDRE &= ~((1<<2)|(1<<1));
PORTE |= (1<<2)|(1<<1);
#endif

DDRD |= (1<<2);
PORTD &= ~(1<<2);                        //enable reception
UBRRH  = 0;
UBRRL  = ((F_OSC/4000)-1);                  //250kbaud, 8N2
UCSRC |= (1<<URSEL)|(3<<UCSZ0)|(1<<USBS);
UCSRB |= (1<<RXEN)|(1<<RXCIE);
gDmxState= IDLE;

uint8_t i;
for (i=0; i<DMX_CHANNELS; i++)
   {
   DmxField= 0;
   }

}


// ************* get DMX start address **************
void get_dips(void)
{
#ifdef USE_DIP
uint16_t Temp= (255-PINC);                  //invert DIP state
if (!(PINE &(1<<2)))
   {
   Temp= Temp +256;                     //9th bit
   }
if (Temp != 0)
   {
   DmxAddress= Temp;
   if (!(UCSRB &(1<<RXCIE)))               //if receiver was disabled -> enable and wait for break
      {
      gDmxState= IDLE;
      UCSRB |= (1<<RXCIE);
      }
   }
else
   {
   UCSRB &= ~(1<<RXCIE);                  //disable Receiver if start address = 0
   for (Temp=0; Temp<DMX_CHANNELS; Temp++)
      {
      DmxField[Temp]= 0;
      }
   }
#endif
}


// *************** DMX Reception ISR ****************
ISR (UART_RX_vect)
{
uint8_t USARTstate= UCSRA;                  //get state
uint8_t DmxByte= UDR;                     //get data
uint8_t DmxState= gDmxState;               //just get once from SRAM!!!
 
if (USARTstate &(1<<FE))                  //check for break
   {
   UCSRA &= ~(1<<FE);                     //reset flag
   DmxCount= DmxAddress;                  //reset frame counter
   gDmxState= BREAK;
   }

else if (DmxState == BREAK)
   {
   if (DmxByte == 0)
      {
      gDmxState= STARTB;                  //normal start code detected
      gDmxPnt= ((uint8_t*)DmxField +1);
      }
   else gDmxState= IDLE;
   }
   
else if (DmxState == STARTB)
   {
   if (--DmxCount == 0)                  //start address reached?
      {
      gDmxState= STARTADR;
      DmxField[0]= DmxByte;
      }
   }

else if (DmxState == STARTADR)
   {
   uint8_t *DmxPnt;
   DmxPnt= gDmxPnt;
   *DmxPnt= DmxByte;
   if (++DmxPnt >= (DmxField +DMX_CHANNELS))    //all ch received?
      {
      gDmxState= IDLE;
      }
   else gDmxPnt= DmxPnt;
   }                     
}



Desconectado stk500

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 4923
Re: Recepcion DMX con Atmega8515
« Respuesta #2 en: 28 de Abril de 2008, 01:56:19 »

Desconectado stk500

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 4923
Re: Recepcion DMX con Atmega8515
« Respuesta #3 en: 28 de Abril de 2008, 01:58:21 »

Desconectado MiCrOtRoNiC

  • PIC18
  • ****
  • Mensajes: 271
Re: Recepcion DMX con Atmega8515
« Respuesta #4 en: 02 de Mayo de 2008, 00:33:48 »
prueba a ver con el codevision.... o despues que te exporte el .hex lo grabas con el chip programmer del codevision

Desconectado stk500

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 4923
Re: Recepcion DMX con Atmega8515
« Respuesta #5 en: 02 de Mayo de 2008, 01:06:43 »
Gracia amigo Microtronic , yo lo hice con pony programa y va pero queria hacerlo con el Studio4 ya que con el compilo el programa fuente, lo
del Crystal externo ya lo tengo claro con Studio4 pero tengo un monton de dudas con los otros Fuses, quizas te anime y viene por aqui ayudarme un poco ya que quiero configurar algunos pines como salida, tengo una larga Biblioteca para mas Mcu que la estoy trabajando para compartirla por aqui y traducirla.
Saludo
 


 

anything