Autor Tema: DRIVER PARA 18F4458  (Leído 4782 veces)

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

Desconectado washi_w_z_r

  • PIC10
  • *
  • Mensajes: 20
DRIVER PARA 18F4458
« en: 09 de Abril de 2009, 14:37:49 »
Hola MAESTROS DE LA ROBOTECNIA Y PROTOCULTURA 8) , una consulta para todos ustedes, el pic18f4458 pertence a la familifa q soporta el USB 2.0 (segun su datasheet), lei en varios post asi como varios proyectos el uso del USB y envio de datos desde el pic ala pc, en muchos de ellos usan en su mayoria el pic18f4550, cuyos proyectos descarge compile y probe en proteus y vuala resulto de maravillas  :D , yo tengo el pic18f4458 asi que probe en proteus y vuala funciona los proyectos PiscUSB, PicUSBnut y el proyecto PIC18F4550_USB, todos ellos funcionan  :shock: .

Weno intente conectar fisicamente mi pic18f4458 con estos proyectos, pero la pc no lo reconoce , estuve bajando muchos DRIVERS : ftdibus,picusb, mchpusb, mchpcdc,oscusb ,macro ,,weno y muchos mas , pero ninguno recnoce dicho pic.

inclusive JIM tiene un post donde modifica el .inf , para el PID y VID , uhmm la verdad no se q falla , epero atentamente sus consejos  :P .

PD: no tengo problemas en compilar tanto en ccs ni en c#

Desconectado micro_cadaver

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2102
    • blog microembebidos
Re: DRIVER PARA 18F4458
« Respuesta #1 en: 15 de Abril de 2009, 12:01:40 »
hola paisano, postea tu circuito derepente por ahi encontramos el detalle.

PD: de que parte de Peru eres?  :-/
a cosechar!!!... :P
pic32... ahi voy....
aguante el micro 16f84  !!!!

visita mi pagina: http://www.microembebidos.wordpress.com

Desconectado washi_w_z_r

  • PIC10
  • *
  • Mensajes: 20
Re: DRIVER PARA 18F4458
« Respuesta #2 en: 15 de Abril de 2009, 19:08:27 »
Hola:
aqui ta mi ckto y los codigos correspondientes
,[/color]
Código: C#
  1. #include <18F2550.h>
  2. #fuses XTPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN
  3. #use delay(clock=48000000)
  4.  
  5.  
  6. /////////////////////////////////////////////////////////////////////////////
  7. //
  8. // CCS Library dynamic defines.  For dynamic configuration of the CCS Library
  9. // for your application several defines need to be made.  See the comments
  10. // at usb.h for more information
  11. //
  12. /////////////////////////////////////////////////////////////////////////////
  13. #define USB_HID_DEVICE     FALSE             //deshabilitamos el uso de las directivas HID
  14. #define USB_EP1_TX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for IN bulk/interrupt transfers
  15. #define USB_EP1_RX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
  16. #define USB_EP1_TX_SIZE    1                 //size to allocate for the tx endpoint 1 buffer
  17. #define USB_EP1_RX_SIZE    3                 //size to allocate for the rx endpoint 1 buffer
  18.  
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. //
  22. // If you are using a USB connection sense pin, define it here.  If you are
  23. // not using connection sense, comment out this line.  Without connection
  24. // sense you will not know if the device gets disconnected.
  25. //       (connection sense should look like this:
  26. //                             100k
  27. //            VBUS-----+----/\/\/\/\/\----- (I/O PIN ON PIC)
  28. //                     |
  29. //                     +----/\/\/\/\/\-----GND
  30. //                             100k
  31. //        (where VBUS is pin1 of the USB connector)
  32. //
  33. /////////////////////////////////////////////////////////////////////////////
  34. //#define USB_CON_SENSE_PIN PIN_B2  //CCS 18F4550 development kit has optional conection sense pin
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. //
  38. // Include the CCS USB Libraries.  See the comments at the top of these
  39. // files for more information
  40. //
  41. /////////////////////////////////////////////////////////////////////////////
  42. #include <pic18_usb.h>     //Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
  43. #include <PicUSB.h>         //Configuración del USB y los descriptores para este dispositivo
  44. #include <usb.c>           //handles usb setup tokens and get descriptor reports
  45.  
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. //
  49. // Al conectar el PicUSB al PC encendemos el Led Rojo hasta que el dispositivo
  50. // halla sido configurado por el PC, en ese momento encederemos el Led Verde.
  51. // Esperaremos hasta que se reciba un paquete proveniente del PC. Comprobaremos
  52. // el primer byte del paquete recibido para comprobar si queremos entrar en el
  53. // modo Suma, donde se realizará una suma de dos operandos, que corresponderan
  54. // con los dos bytes restantes del paquete recibido; una vez realizada la suma
  55. // enviaremos el paquete con el resultado de vuelta al PC. Si entramos en el
  56. // modo Led comprobaremos el segundo byte del paquete recibido para comprobar
  57. // si deberemos apagar los leds, encender el verder o el rojo.
  58. //
  59. /////////////////////////////////////////////////////////////////////////////
  60. #define LEDV    PIN_B6
  61. #define LEDR    PIN_B7
  62. #define LED_ON  output_high
  63. #define LED_OFF output_low
  64.  
  65. #define modo      recibe[0]
  66. #define param1    recibe[1]
  67. #define param2    recibe[2]
  68. #define resultado envia[0]
  69.  
  70.  
  71. void main(void) {
  72.  
  73.    int8 recibe[3];                  //declaramos variables
  74.    int8 envia[1];
  75.  
  76.    LED_OFF(LEDV);                   //encendemos led rojo
  77.    LED_ON(LEDR);
  78.  
  79.    usb_init();                      //inicializamos el USB
  80.  
  81.    usb_task();                      //habilita periferico usb e interrupciones
  82.    usb_wait_for_enumeration();      //esperamos hasta que el PicUSB sea configurado por el host
  83.  
  84.    LED_OFF(LEDR);
  85.    LED_ON(LEDV);                    //encendemos led verde
  86.  
  87.    while (TRUE)
  88.    {
  89.       if(usb_enumerated())          //si el PicUSB está configurado
  90.       {
  91.          if (usb_kbhit(1))          //si el endpoint de salida contiene datos del host
  92.          {
  93.             usb_get_packet(1, recibe, 3); //cojemos el paquete de tamaño 3bytes del EP1 y almacenamos en recibe
  94.  
  95.             if (modo == 0) // Modo_Suma
  96.             {
  97.                resultado = param1 + param2;  //hacemos la suma
  98.  
  99.                usb_put_packet(1, envia, 1, USB_DTS_TOGGLE); //enviamos el paquete de tamaño 1byte del EP1 al PC
  100.             }
  101.  
  102.             if (modo == 1) // Modo_Led
  103.             {
  104.                if (param1 == 0) {LED_OFF(LEDV); LED_OFF(LEDR);} //apagamos los leds
  105.                if (param1 == 1) {LED_ON(LEDV); LED_OFF(LEDR);} //encendemos led verde
  106.                if (param1 == 2) {LED_OFF(LEDV); LED_ON(LEDR);} //encendemos led rojo
  107.             }
  108.          }
  109.       }
  110.    }
  111. }
los descriptores:
Código: C#
  1. #IFNDEF __USB_DESCRIPTORS__
  2. #DEFINE __USB_DESCRIPTORS__
  3.  
  4. #include <usb.h>
  5.  
  6. //////////////////////////////////////////////////////////////////
  7. ///
  8. ///   start config descriptor
  9. ///   right now we only support one configuration descriptor.
  10. ///   the config, interface, class, and endpoint goes into this array.
  11. ///
  12. //////////////////////////////////////////////////////////////////
  13.  
  14.    #DEFINE USB_TOTAL_CONFIG_LEN      32 //config+interface+class+endpoint
  15.  
  16.    //configuration descriptor
  17.    char const USB_CONFIG_DESC[] = {
  18.    //config_descriptor for config index 1
  19.          USB_DESC_CONFIG_LEN,     //length of descriptor size
  20.          USB_DESC_CONFIG_TYPE,         //constant CONFIGURATION (0x02)
  21.          USB_TOTAL_CONFIG_LEN,0,  //size of all data returned for this config
  22.          1,      //number of interfaces this device supports
  23.          0x01,                //identifier for this configuration.  (IF we had more than one configurations)
  24.          0x00,                //index of string descriptor for this configuration
  25.          0xC0,                //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 reserved and bit7=1
  26.          0x32,                //maximum bus power required (maximum milliamperes/2)  (0x32 = 100mA)
  27.  
  28.    //interface descriptor 0 alt 0
  29.          USB_DESC_INTERFACE_LEN,  //length of descriptor
  30.          USB_DESC_INTERFACE_TYPE,      //constant INTERFACE (0x04)
  31.          0x00,                //number defining this interface (IF we had more than one interface)
  32.          0x00,                //alternate setting
  33.          2,       //number of endpoints, not counting endpoint 0.
  34.          0xFF,                //class code, FF = vendor defined
  35.          0xFF,                //subclass code, FF = vendor
  36.          0xFF,                //protocol code, FF = vendor
  37.          0x00,                //index of string descriptor for interface
  38.  
  39.    //endpoint descriptor
  40.          USB_DESC_ENDPOINT_LEN, //length of descriptor
  41.          USB_DESC_ENDPOINT_TYPE,     //constant ENDPOINT (0x05)
  42.          0x81,              //endpoint number and direction (0x81 = EP1 IN)
  43.          0x02,              //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
  44.          USB_EP1_TX_SIZE,0x00,         //maximum packet size supported
  45.          0x01,              //polling interval in ms. (for interrupt transfers ONLY)
  46.  
  47.    //endpoint descriptor
  48.          USB_DESC_ENDPOINT_LEN, //length of descriptor
  49.          USB_DESC_ENDPOINT_TYPE,     //constant ENDPOINT (0x05)
  50.          0x01,              //endpoint number and direction (0x01 = EP1 OUT)
  51.          0x02,              //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
  52.          USB_EP1_RX_SIZE,0x00,         //maximum packet size supported
  53.          0x01,              //polling interval in ms. (for interrupt transfers ONLY)
  54.  
  55.   };
  56.  
  57.    //****** BEGIN CONFIG DESCRIPTOR LOOKUP TABLES ********
  58.    //since we can't make pointers to constants in certain pic16s, this is an offset table to find
  59.    //  a specific descriptor in the above table.
  60.  
  61.    //NOTE: DO TO A LIMITATION OF THE CCS CODE, ALL HID INTERFACES MUST START AT 0 AND BE SEQUENTIAL
  62.    //      FOR EXAMPLE, IF YOU HAVE 2 HID INTERFACES THEY MUST BE INTERFACE 0 AND INTERFACE 1
  63.    #define USB_NUM_HID_INTERFACES   0
  64.  
  65.    //the maximum number of interfaces seen on any config
  66.    //for example, if config 1 has 1 interface and config 2 has 2 interfaces you must define this as 2
  67.    #define USB_MAX_NUM_INTERFACES   1
  68.  
  69.    //define how many interfaces there are per config.  [0] is the first config, etc.
  70.    const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={1};
  71.  
  72.    #if (sizeof(USB_CONFIG_DESC) != USB_TOTAL_CONFIG_LEN)
  73.       #error USB_TOTAL_CONFIG_LEN not defined correctly
  74.    #endif
  75.  
  76.  
  77. //////////////////////////////////////////////////////////////////
  78. ///
  79. ///   start device descriptors
  80. ///
  81. //////////////////////////////////////////////////////////////////
  82.  
  83.    //device descriptor
  84.    char const USB_DEVICE_DESC[] ={
  85.          USB_DESC_DEVICE_LEN,          //the length of this report
  86.          0x01,                //constant DEVICE (0x01)
  87.          0x10,0x01,           //usb version in bcd
  88.          0x00,                //class code (if 0, interface defines class.  FF is vendor defined)
  89.          0x00,                //subclass code
  90.          0x00,                //protocol code
  91.          USB_MAX_EP0_PACKET_LENGTH,   //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8)
  92.          0xD8,0x04,           //vendor id (0x04D8 is Microchip)
  93.          0x11,0x00,           //product id, me gusta el 11 ;)
  94.          0x01,0x00,           //device release number
  95.          0x01,                //index of string description of manufacturer. therefore we point to string_1 array (see below)
  96.          0x02,                //index of string descriptor of the product
  97.          0x00,                //index of string descriptor of serial number
  98.          USB_NUM_CONFIGURATIONS   //number of possible configurations
  99.    };
  100.  
  101.  
  102. //////////////////////////////////////////////////////////////////
  103. ///
  104. ///   start string descriptors
  105. ///   String 0 is a special language string, and must be defined.  People in U.S.A. can leave this alone.
  106. ///
  107. ///   You must define the length else get_next_string_character() will not see the string
  108. ///   Current code only supports 10 strings (0 thru 9)
  109. ///
  110. //////////////////////////////////////////////////////////////////
  111.  
  112. //the offset of the starting location of each string.
  113. //offset[0] is the start of string 0, offset[1] is the start of string 1, etc.
  114. const char USB_STRING_DESC_OFFSET[]={0,4,12};
  115.  
  116. #define USB_STRING_DESC_COUNT sizeof(USB_STRING_DESC_OFFSET)
  117.  
  118. char const USB_STRING_DESC[]={
  119.    //string 0
  120.          4, //length of string index
  121.          USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
  122.          0x09,0x04,   //Microsoft Defined for US-English
  123.    //string 1 --> la compañia del producto ???
  124.          8, //length of string index
  125.          USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
  126.          'J',0,
  127.          '1',0,
  128.          'M',0,
  129.    //string 2 --> nombre del dispositivo
  130.          22, //length of string index
  131.          USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
  132.          'J',0,
  133.          '1',0,
  134.          'M',0,
  135.          ' ',0,
  136.          'P',0,
  137.          'i',0,
  138.          'c',0,
  139.          'U',0,
  140.          'S',0,
  141.          'B',0
  142. };
  143.  
  144.  
  145. #ENDIF

y aqui ta los datos del driver:
Código: C#
  1. [Version]
  2. Signature="$WINDOWS NT$"
  3. Class=%ClassName%
  4. ClassGuid={4D36E911-E325-11CE-BFC1-08002BE10319}
  5. Provider=%MFGNAME%
  6. DriverVer=03/10/2005,1.0.0.0
  7. CatalogFile=picusb.cat
  8.  
  9. [DestinationDirs]
  10. DefaultDestDir = 12
  11. PicUSB.ClassCopyFiles = 11
  12.  
  13. ;------------------------------------------------------------------------------
  14. ;  Class installation sections
  15. ;------------------------------------------------------------------------------
  16.  
  17. [ClassInstall32]
  18. AddReg=PicUSB.ClassReg
  19. CopyFiles=PicUSB.ClassCopyFiles
  20.  
  21. [PicUSB.ClassReg]
  22. HKR,,,0,%ClassName%
  23. HKR,,Class,,%ClassDesc%
  24. HKR,,Icon,,11
  25. HKR,,Installer32,,"picusbci.dll,PicUSBClassInstaller"
  26.  
  27.  
  28. [PicUSB.ClassCopyFiles]
  29. picusbci.dll
  30.  
  31. ;------------------------------------------------------------------------------
  32. ;  Device  Install Section
  33. ;------------------------------------------------------------------------------
  34.  
  35. [Manufacturer]
  36. %MFGNAME%=Standard
  37.  
  38. [Standard]
  39. %DESCRIPTION%=DriverInstall, USB\VID_0x04D8&PID_0011
  40.  
  41. [SourceDisksNames]
  42. 1 = %INSTDISK%,,,""
  43.  
  44. [SourceDisksFiles]
  45. mchpusb.sys  = 1,,
  46. wdmstub.sys  = 1,,
  47. picusbci.dll = 1,,
  48.  
  49. ;------------------------------------------------------------------------------
  50. ;  Windows 2000/XP Sections
  51. ;------------------------------------------------------------------------------
  52.  
  53. [DriverInstall.NT]
  54. CopyFiles=DriverCopyFiles
  55.  
  56. [DriverCopyFiles]
  57. mchpusb.sys
  58.  
  59. [DriverInstall.NT.Services]
  60. AddService = PicUSB, 2, DriverService
  61.  
  62. [DriverService]
  63. DisplayName    = %SVCDESC%
  64. ServiceType    = 1               ; SERVICE_KERNEL_DRIVER
  65. StartType      = 3               ; SERVICE_DEMAND_START
  66. ErrorControl   = 1               ; SERVICE_ERROR_NORMAL
  67. ServiceBinary  = %12%\mchpusb.sys
  68. LoadOrderGroup = Extended Base
  69.  
  70. ;------------------------------------------------------------------------------
  71. ;  Windows 98/Me Sections
  72. ;------------------------------------------------------------------------------
  73.  
  74. [DriverInstall]
  75. AddReg=DriverAddReg
  76. CopyFiles=DriverCopyFiles,StubCopyFiles
  77. DriverVer=09/26/2005,1.0.0.0
  78.  
  79. [DriverAddReg]
  80. HKR,,DevLoader,,*ntkern
  81. HKR,,NTMPDriver,,"wdmstub.sys,mchpusb.sys"
  82.  
  83. [StubCopyFiles]
  84. wdmstub.sys
  85.  
  86. ;------------------------------------------------------------------------------
  87. ;  String Definitions
  88. ;------------------------------------------------------------------------------
  89.  
  90. [Strings]
  91. MFGNAME="J1M PicUSB"
  92. INSTDISK="PicUSB Device Driver Disc"
  93. DESCRIPTION="PicUSB"
  94. SVCDESC="PicUSB Device Driver"
  95. ClassName="PIC 18Fxx5x USB Devices"
  96. ClassDesc="PicUSB Sample Device"

weno podran observar solo cambie el encabezado del pic a 18f4458, uhm como no dio resultado consegui el pic 18f4550 , cambie el encabezado #include <18f4550.h> y naaa los mismos errores ,  :8} ya no se que hacer

Desconectado migsantiago

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8257
    • Sitio de MigSantiago
Re: DRIVER PARA 18F4458
« Respuesta #3 en: 15 de Abril de 2009, 20:29:55 »
¿Tu versión de CCS ya compila programas para el pic18f4458?

Desconectado washi_w_z_r

  • PIC10
  • *
  • Mensajes: 20
Re: DRIVER PARA 18F4458
« Respuesta #4 en: 16 de Abril de 2009, 00:33:27 »
Ante todo mil disculpas a todos ustedes especialmente a micro_cadaver por haberlo molestado tanto , si es cierto acabo de ver que COMETI UN GRAVE ERROR tanto estar probando con el proteus  no me di cuenta de la conex, es decir estaba conectando el capacitor de 47uF al pin 20 , lo cual obviamente es incorrecto ya que el pin correcto es el pin18, nuevamente mil disculpas a todos ,,  :( , y confirmo el driver que dejo JIM si funciona para este PIC18F4458 , ahora estoy probando el ADC de 12bits que tiene este pic, para mi proyecto.

 :-/

Desconectado micro_cadaver

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2102
    • blog microembebidos
Re: DRIVER PARA 18F4458
« Respuesta #5 en: 16 de Abril de 2009, 10:39:15 »
hey no hay problema  :-), precisamente de eso trata una ayuda, y mejor si uno mismo se da cuenta.

no me dijistes de que parte de PERU eres, o estas en el extranjero?

saludos  :-/
a cosechar!!!... :P
pic32... ahi voy....
aguante el micro 16f84  !!!!

visita mi pagina: http://www.microembebidos.wordpress.com

Desconectado washi_w_z_r

  • PIC10
  • *
  • Mensajes: 20
Re: DRIVER PARA 18F4458
« Respuesta #6 en: 16 de Abril de 2009, 22:11:25 »
hola micro_cadaver, soy de la capital historica CUSCO    :-/

Actualmente estoy desarrolando mi proyecto biomedico  :D de adquisicion de datos provenientes de un sensor dedal ( se coloca en dedo indice de la mano izquierda) , esta señal es acoplada y filtrada despues lo llevo la pic para enviarlo ala PC y en la PC recogerlo por c# alamcenarlo en SQL y denuevo mostrarlo en c# (graficar) ya que necesito ondas fotopletismograficas  :shock:.

saludos

Desconectado micro_cadaver

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2102
    • blog microembebidos
Re: DRIVER PARA 18F4458
« Respuesta #7 en: 17 de Abril de 2009, 10:16:47 »
pues que bien, te deseo exitos en tu proyecto, siempre postea tus dudas para ver en que te podemos apoyar. saludos  :-/

yo soy de Lima. :mrgreen:
a cosechar!!!... :P
pic32... ahi voy....
aguante el micro 16f84  !!!!

visita mi pagina: http://www.microembebidos.wordpress.com

Desconectado washi_w_z_r

  • PIC10
  • *
  • Mensajes: 20
Re: DRIVER PARA 18F4458
« Respuesta #8 en: 21 de Abril de 2009, 02:07:17 »
hola amigos, nuevamente molestandolos, sigo e mi proyecto de adquirir datos med ADC del pic 18f4458 ( tiene ADC 12bits) estuve desarrollando este codigo:

Código: C#
  1. #include <18F4458.h>
  2. #DEVICE ADC=12 // cad a 8 bits
  3. #fuses XTPLL,NOMCLR,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN,NOPBADEN
  4. #use delay(clock=48000000)
  5.  
  6.  
  7. #define USB_HID_DEVICE     FALSE             //deshabilitamos el uso de las directivas HID
  8. #define USB_EP1_TX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for IN bulk/interrupt transfers
  9. #define USB_EP1_RX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
  10. #define USB_EP1_TX_SIZE    12                 //size to allocate for the tx endpoint 1 buffer
  11. #define USB_EP1_RX_SIZE    12                 //size to allocate for the rx endpoint 1 buffer
  12.  
  13. #define USB_EP2_TX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for IN bulk/interrupt transfers
  14. #define USB_EP2_RX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
  15. #define USB_EP2_TX_SIZE    12                 //size to allocate for the tx endpoint 1 buffer
  16. #define USB_EP2_RX_SIZE    12                 //size to allocate for the rx endpoint 1 buffer
  17.  
  18.  
  19. #define USB_CON_SENSE_PIN PIN_E3
  20. #define DERECHA 0
  21.  
  22. #include <pic18_usb.h>     //Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
  23. #include <TESIS_ADC_CONMUTADO.h>      //Configuración del USB y los descriptores para este dispositivo
  24. #include <usb.c>        //handles usb setup tokens and get descriptor reports
  25.  
  26. #define Led_Verde  PIN_B7
  27. #define Led_Rojo   PIN_B6
  28.  
  29. #define Enciende output_High
  30. #define Apaga    output_Low
  31. #define Conmuta  output_Toggle
  32.  
  33. #byte ADCON0 = 0xFC2
  34. #byte ADRESL = 0xFC3
  35. #byte ADRESH = 0XFC4
  36.  
  37.  
  38. int H,L;
  39. void config_adcon2(short justificacion);
  40.  
  41. void Leer_ADC()
  42. {
  43.    int e;
  44.    int8 BUFFER_OXI[10];    //BUFFER DE ALM,ACENAMIENTO DATOS ADC
  45.    
  46.    setup_adc_ports( AN0 || VSS_VDD );  // canal AN0, Vref+ = Vdd, Vref- = Vss
  47.    config_adcon2(DERECHA);   // justificación derecha, Tacq= 2Tad
  48.    for(e = 0; e <= 5 ; e++)
  49.    {
  50.       if(e==1) // ROJO_AC
  51.       {
  52.          set_adc_channel(0);
  53.          bit_set(ADCON0,1);
  54.          while(bit_test(ADCON0,1));
  55.          H=ADRESH;
  56.          L=ADRESL;
  57.          BUFFER_OXI[0]=H;
  58.          BUFFER_OXI[1]=L;
  59.       }
  60.       if(e==2) // ROJO_DC
  61.       {
  62.          set_adc_channel(1);
  63.          bit_set(ADCON0,1);
  64.          while(bit_test(ADCON0,1));
  65.          H=ADRESH;
  66.          L=ADRESL;
  67.          BUFFER_OXI[2]=H;
  68.          BUFFER_OXI[3]=L;
  69.       }
  70.       if(e==3) // INFROJO_AC
  71.       {
  72.          set_adc_channel(2);
  73.          bit_set(ADCON0,1);
  74.          while(bit_test(ADCON0,1));
  75.          H=ADRESH;
  76.          L=ADRESL;
  77.          BUFFER_OXI[4]=H;
  78.          BUFFER_OXI[5]=L;
  79.       }
  80.       if(e==4) // INFROJO_DC
  81.       {
  82.          set_adc_channel(3);
  83.          bit_set(ADCON0,1);
  84.          while(bit_test(ADCON0,1));
  85.          H=ADRESH;
  86.          L=ADRESL;
  87.          BUFFER_OXI[6]=H;
  88.          BUFFER_OXI[7]=L;
  89.       }
  90.       if(e==5) // LUZ_TEZ
  91.       {
  92.          set_adc_channel(4);
  93.          bit_set(ADCON0,1);
  94.          while(bit_test(ADCON0,1));
  95.          H=ADRESH;
  96.          L=ADRESL;
  97.          BUFFER_OXI[8]=H;
  98.          BUFFER_OXI[9]=L;
  99.       }
  100.    }
  101.    usb_put_packet(2,BUFFER_OXI,10, USB_DTS_TOGGLE);
  102. }
  103.  
  104. //-----------------------------------------------------------------------------------------
  105. // cumple la función de configurar el bit ADFM para hacer
  106. // la justificación, también se incluye el retardo por hardware de Tacq
  107. // datos de entrada: bandera de justificación
  108. // datos de salida: nada
  109. //-----------------------------------------------------------------------------------------
  110. void config_adcon2(short justificacion){
  111.    setup_adc(ADC_CLOCK_DIV_64 );  // reloj de conversión = Fosc / 64
  112.     if(justificacion){
  113.     #asm
  114.     bsf 0xFC0,7    // ADFM <- 1
  115.     #endasm
  116.     }
  117.     else{
  118.     #asm
  119.       bcf 0xFC0,7   // ADFM <- 0
  120.    #endasm
  121.    }
  122.    #asm          // configura Tacq = 2Tad
  123.     bsf 0xFC0,3
  124.     bcf 0xFC0,4
  125.     bcf 0xFC0,5
  126.    #endasm
  127. }
  128.  
  129.  
  130. void main(){
  131.    
  132.    int envia[1];
  133.    int recibe[1];
  134.    Apaga(Led_Verde);
  135.    Enciende(Led_Rojo);
  136.    set_tris_a(0x1);  // Ra[0]=entradas, los demas=salida
  137.  
  138.    usb_init_cs();  // inicializa el USB y lo desactiva
  139.  
  140.  
  141.     while(true){
  142.        usb_task();    //habilita periferico usb e interrupciones
  143.        envia[0]= read_adc();
  144.        if(usb_enumerated()){ // primer if
  145.             Apaga(Led_Rojo);
  146.             Enciende(Led_verde);
  147.           if(usb_kbhit(1)){  // segundo if
  148.              //si el endpoint de salida contiene datos del host        
  149.              usb_get_packet(1, recibe, 1);
  150.              //cojemos el paquete de tamaño 1bytes del EP1 y almacenamos en recibe
  151.              if(recibe[0]=='a'){ // tercer if
  152.                 usb_put_packet(1, envia, 1, USB_DTS_TOGGLE);
  153.                 Conmuta(Led_Verde);
  154.                 Enciende(Led_Rojo);  //enviamos el paquete de tamaño 1 bytes del EP1 al PC
  155.               // leemos el adc
  156.                Leer_ADC();
  157.              }
  158.           }
  159.         }
  160.    }
  161. }

como veran hice un mix de todos los archivos que encontre , jejej , uhm weno varias preguntas:
1. ¿que me conviene? , sequir con el cod que desarrolle lineas arriba ò implementar mas ENDPOINT para almacenar los datos
2.Como pdria aumentar la veloc de adquisicion de datos
3. En mi prog desarrollado en C# solo me envia 00000 ...  :8}


Uuyuyy valga la aclaracion estoy tomando 5 señales multiplexadas provenientes de un sensor, el cual despues de filtrarlo y darle una ganacia a la señal ,la cual esta en el rango de 0.4v y 4.5v.

Ala espera de sus sugerencias y comentarios ,
saludos  :-/

Desconectado washi_w_z_r

  • PIC10
  • *
  • Mensajes: 20
Re: DRIVER PARA 18F4458
« Respuesta #9 en: 21 de Abril de 2009, 23:21:18 »
Disculpen por el desorden de mi proyecto pero me saca canas verdes cada vez que avanzo para el pic desarrolle el siguiente programa:

Código: C#
  1. #include <18F4458.h>
  2. #device ADC=12   // ADC DE 10 BITS
  3. #fuses XTPLL,NOMCLR,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN
  4. #use delay(clock=48000000)
  5.  
  6.  
  7. /////////////////////////////////////////////////////////////////////////////
  8. //
  9. // CCS Library dynamic defines.  For dynamic configuration of the CCS Library
  10. // for your application several defines need to be made.  See the comments
  11. // at usb.h for more information
  12. //
  13. /////////////////////////////////////////////////////////////////////////////
  14. #define USB_HID_DEVICE     FALSE             //deshabilitamos el uso de las directivas HID
  15. #define USB_EP1_TX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for IN bulk/interrupt transfers
  16. #define USB_EP1_RX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
  17. #define USB_EP1_TX_SIZE    3                 //size to allocate for the tx endpoint 1 buffer
  18. #define USB_EP1_RX_SIZE    3                 //size to allocate for the rx endpoint 1 buffer
  19.  
  20. #define USB_CON_SENSE_PIN PIN_E3  
  21. #define DERECHA 0
  22.  
  23. #include <pic18_usb.h>     //Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
  24. #include <USB_ADC_TESIS.h>         //Configuración del USB y los descriptores para este dispositivo
  25. #include <usb.c>           //handles usb setup tokens and get descriptor reports
  26.  
  27. #byte ADCON0 = 0xFC2
  28. #byte ADRESL = 0XFC3
  29. #byte ADRESH = 0XFC4
  30.  
  31.  
  32. #define LEDV    PIN_B6
  33. #define LEDR    PIN_B7
  34. #define LED_ON  output_high
  35. #define LED_OFF output_low
  36.  
  37. #define modo      recibe[0]
  38. #define param1    recibe[1]
  39. #define param2    recibe[2]
  40. #define MedidaAlta   envia[0]
  41. #define MedidaBaja  envia[1]
  42.  
  43. void config_adcon2(short justificacion);
  44. int H,L;
  45.  
  46. void main(void) {
  47.  
  48.    int8 recibe[3];                  //declaramos variables
  49.    int8 envia[2];
  50.    
  51.    set_tris_a(0x1);    // configuramos RA como entrada
  52.    
  53.    LED_OFF(LEDV);                   //encendemos led rojo
  54.    LED_ON(LEDR);
  55.  
  56.    usb_init_cs();                      //inicializamos el USB
  57.    setup_adc_ports(AN0 || VSS_VDD);
  58.    config_adcon2(DERECHA);
  59.    while (TRUE)
  60.    {
  61.       usb_task();                      //habilita periferico usb e interrupciones
  62.       if(usb_enumerated())          //si el PicUSB está configurado
  63.       {
  64.          LED_OFF(LEDR);
  65.          LED_ON(LEDV);                    //encendemos led verde
  66.  
  67.          if (usb_kbhit(1))          //si el endpoint de salida contiene datos del host
  68.          {
  69.             usb_get_packet(1, recibe, 3); //cojemos el paquete de tamaño 3bytes del EP1 y almacenamos en recibe
  70.  
  71.             if (modo == 1) // Modo_Led
  72.             {
  73.                if (param1 == 0) {LED_OFF(LEDV); LED_OFF(LEDR);} //apagamos los leds
  74.                if (param1 == 1) {LED_ON(LEDV); LED_OFF(LEDR);} //encendemos led verde
  75.                if (param1 == 2) {LED_OFF(LEDV); LED_ON(LEDR);} //encendemos led rojo
  76.             }
  77.             if (modo == 2)  //Modo ADC
  78.             {
  79.               set_adc_channel(0);
  80.               while(bit_set(ADCON0,1));
  81.               H = ADRESH;
  82.               L = ADRESL;
  83.               MedidaAlta = H;
  84.               MedidaBaja = L;
  85.               usb_put_packet(1, envia, 1, USB_DTS_TOGGLE);
  86.               LED_On(LEDR);
  87.               LED_ON(LEDV);                    //encendemos led verde
  88.             }
  89.          }
  90.       }
  91.    }
  92. }
  93. void config_adcon2(short justificacion)
  94. {
  95.    setup_adc(ADC_CLOCK_DIV_64 );  // reloj de conversión = Fosc / 64
  96.     if(justificacion){
  97.     #asm
  98.     bsf 0xFC0,7    // ADFM <- 1
  99.     #endasm
  100.     }
  101.     else{
  102.     #asm
  103.       bcf 0xFC0,7   // ADFM <- 0
  104.    #endasm
  105.    }
  106.    #asm          // configura Tacq = 2Tad
  107.     bsf 0xFC0,3
  108.     bcf 0xFC0,4
  109.     bcf 0xFC0,5
  110.    #endasm
  111. }

para visual c# desarrolle el siguiente:

Código: C#
  1. [code]using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9.  
  10. using PVOID = System.IntPtr;
  11. using DWORD = System.UInt32;
  12.  
  13. namespace USB_ADC_TESIS
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         PicUSBAPI usbapi = new PicUSBAPI();
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.         unsafe public class PicUSBAPI
  23.         {
  24.             #region Definición de los Strings: EndPoint y VID_PID
  25.             string vid_pid_norm = "vid_04d8&pid_0042";
  26.  
  27.             string out_pipe = "\\MCHP_EP1";
  28.             string in_pipe = "\\MCHP_EP1";
  29.             #endregion
  30.  
  31.             #region Funciones importadas de la DLL: mpusbapi.dll
  32.             [DllImport("mpusbapi.dll")]
  33.             private static extern DWORD _MPUSBGetDLLVersion();
  34.             [DllImport("mpusbapi.dll")]
  35.             private static extern DWORD _MPUSBGetDeviceCount(string pVID_PID);
  36.             [DllImport("mpusbapi.dll")]
  37.             private static extern void* _MPUSBOpen(DWORD instance, string pVID_PID, string pEP, DWORD dwDir, DWORD dwReserved);
  38.             [DllImport("mpusbapi.dll")]
  39.             private static extern DWORD _MPUSBRead(void* handle, void* pData, DWORD dwLen, DWORD* pLength, DWORD dwMilliseconds);
  40.             [DllImport("mpusbapi.dll")]
  41.             private static extern DWORD _MPUSBWrite(void* handle, void* pData, DWORD dwLen, DWORD* pLength, DWORD dwMilliseconds);
  42.             [DllImport("mpusbapi.dll")]
  43.             private static extern DWORD _MPUSBReadInt(void* handle, DWORD* pData, DWORD dwLen, DWORD* pLength, DWORD dwMilliseconds);
  44.             [DllImport("mpusbapi.dll")]
  45.             private static extern bool _MPUSBClose(void* handle);
  46.             #endregion
  47.  
  48.             void* myOutPipe;
  49.             void* myInPipe;
  50.  
  51.             //Constantes
  52.             const int MaxRec = 2;
  53.             const int MaxEnv = 2;
  54.             //**** FUNCION ABRIR PIPE ****
  55.             public void AbrirPipes()
  56.             {
  57.                 DWORD seleccion = 0;
  58.                 myOutPipe = _MPUSBOpen(seleccion, vid_pid_norm, out_pipe, 0, 0);
  59.                 myInPipe = _MPUSBOpen(seleccion, vid_pid_norm, in_pipe, 1, 0);
  60.             }
  61.             //**** FUNCION CERRAR PIPE ****
  62.             public void CerrarPipes()
  63.             {
  64.                 _MPUSBClose(myOutPipe);
  65.                 _MPUSBClose(myInPipe);
  66.             }
  67.  
  68.             /**** FUNCIONES ENVIO RECEPCION DE PAQUETES ******/
  69.             private void EnvioPaquete(byte* SendPacket, DWORD SendLength)
  70.             {
  71.                 uint Sendelay = 1000;
  72.                 DWORD SendDataLength;
  73.                 _MPUSBWrite(myOutPipe, (void*)SendPacket, SendLength, &SendDataLength, Sendelay);
  74.             }
  75.             private void ReciboPaquete(byte* ReceiveData, DWORD* ReceiveLength)
  76.             {
  77.                 uint ReceiveDelay = 1000;
  78.                 DWORD ExpectReceiveLentgh = *ReceiveLength;
  79.                 _MPUSBRead(myInPipe, (void*)ReceiveData, ExpectReceiveLentgh, ReceiveLength, ReceiveDelay);
  80.             }
  81.             /****  PRENDER APAGAR LEDS ******/
  82.             public void LedPIC(uint led)
  83.             {
  84.                 byte* send_buf = stackalloc byte[2];
  85.                 send_buf[0] = 0x01;
  86.                 send_buf[1] = (byte)led;
  87.                 EnvioPaquete(send_buf, 2);
  88.             }
  89.             ///////////////////////////////////////////////
  90.             /**** FUNCIONES PERSONALIZADAS ****/
  91.             //public void RecibirPaquetePic(byte* BufferRec)
  92.             public float RecibirPaquetePic()
  93.             {
  94.                 float Conversion = 0;
  95.                 byte* BufferRec = stackalloc byte[3];              
  96.                
  97.                 DWORD RecvLentgh = 2;
  98.  
  99.                 ReciboPaquete(BufferRec, &RecvLentgh);
  100.                
  101.                // if (BufferRec[0]==0)
  102.                // return Conversion = BufferRec[0];
  103.                 //else
  104.                return Conversion = BufferRec[1];
  105.             }
  106.             // **** FUNCION QUE PIDA DATOS AL PIC ****
  107.             public void PideDatosPic()
  108.             {
  109.                 byte* send_buf = stackalloc byte[2];
  110.                 send_buf[0] = 0x02;  //pedimos al pic iniciar ADC
  111.                 send_buf[1] = 0;     // no iplementado
  112.                 EnvioPaquete(send_buf, 2);
  113.             }
  114.         }
  115.  
  116.         private void btnAbrir_Click(object sender, EventArgs e)
  117.         {
  118.             try
  119.             {
  120.                 // CERRAMOS ENLACES ABIERTOS PARA INICIAR NUEVO ENLACE
  121.                 usbapi.CerrarPipes();
  122.                 // ABRIENDO NUEVO ENLACE
  123.                 usbapi.AbrirPipes();
  124.                 usbapi.LedPIC(0x00);
  125.             }
  126.             catch
  127.             {
  128.                 MessageBox.Show("NO SE PUDO ABRIR ENLACE");
  129.             }
  130.            
  131.         }
  132.  
  133.         private void btnCerrar_Click(object sender, EventArgs e)
  134.         {
  135.             usbapi.CerrarPipes();
  136.         }
  137.  
  138.         private void btnRojo_Click(object sender, EventArgs e)
  139.         {
  140.             usbapi.LedPIC(0x01);
  141.         }
  142.  
  143.         private void btnVerde_Click(object sender, EventArgs e)
  144.         {
  145.             usbapi.LedPIC(0x02);
  146.         }
  147.  
  148.         private void btnADC_Click(object sender, EventArgs e)
  149.         {
  150.             usbapi.PideDatosPic();
  151.             timer1.Start();
  152.         }
  153.  
  154.         private void timer1_Tick(object sender, EventArgs e)
  155.         {
  156.             usbapi.RecibirPaquetePic();
  157.             textBox1.Text = usbapi.RecibirPaquetePic().ToString();
  158.             this.listBox1.Items.Add(usbapi.RecibirPaquetePic().ToString());
  159.         }
  160.  
  161.         private void btnPausa_Click(object sender, EventArgs e)
  162.         {
  163.             timer1.Stop();
  164.         }
  165.      
  166.        
  167.     }
  168. }
[/code]


uhm ;  cuando estuve programando para encender y apagr lo leds todo de maravilla  :-/  , pero cuando aumente el codigo para adquirir datos mediante el ADC ahi surgieron los problemas  :8} , ya no abria el PIPE que controlo con el boton "ABRIR", el prog se queda en nada, es decir ni responde el encendido y apàgdo de Leds , cosa que estan aparte de la instrucciones de adquisicion de datos , saludos , y esperando sus comentarios


 

anything