Vous êtes sur la page 1sur 13

CONTROL DE TENSION ASISTIDO POR

MEDIO DE LA INTERFAZ USB


1. Introducción
Una respuesta a la necesidad de comunicar de forma sencilla y genérica dispositivos electrónicos,
Utilizando una PC para comunicarse con dispositivos electrónicos, y así poder lograr lo siguiente:

 Aumentar la potencialidad de los dispositivos.


 Aprovechar las capacidades de procesamiento, y almacenamiento del PC.
 Aumentar la Interacción con el mundo físico.
 Simplificar el manejo de los dispositivos.

2. Diagrama de Bloques

COMUNICACIÓN USB

PC

CONTROL DE LA GENERACION DE
LUMINOSIDAD PULSOS
MEDIANTE PC

ENCENDIDO O
APAGADO
RELE
SALIDA DEL VOLTAJE
3. Descripción de los Bloques
3.1. comunicación USB
En este módulo usamos un pc para poder manipular el encendido o apagado del proyecto, así
también disminuir o decrementar la salida de la tensión.

Para todo esto usaremos el HID terminal como interfaz para la comunicación entre pc y pic.

3.2. Generación de pulsos


Se encarga de generar la señal que activará el relé y así dará funcionamiento al circuito,
también cumplirá la función de manipular la tensión de salida mediante el pc y el programa
grabado dentro del pic.

3.3. Encendido o apagado


Se encarga de encender o apagar el circuito gracias a los pulsos enviados del pic.

3.4. Salida
La salida de voltaje va variando debido a la manipulación del pc.

4. Especificación de componentes por módulo


4.1. Pc
Es necesario ya que el programa funciona con la manipulación desde un pc.

4.2. Pic
Es el encargado de enviar los pulsos al relé para el funcionamiento del circuito, este pulso llega
transistor BC548 para poder activar el relé.

4.3. relé
es el encargado de recibir los pulsos para activar el funcionamiento del circuito.

4.4. salida de voltaje


la salida depende de uso del pc para generar voltajes de salida diferentes, esto con la ayuda de
un transformador de 12 voltios y un tiristor, esto funciona con la manipulación de decremento
o incremento desde el pc.
5. Pruebas realizadas

Imagen # 1 Proceso de armado

Imagen # 2 Prueba y error


6. Diagrama de Flujo

INICIO

ENCENDEMOS O APAGAMOS EL
CIRCUITO

INCREMENTAMOS O DECREMENTAMOS LOS


VALORES MEDIANTE EL PC

SE VISUALIZA EN UN
FOCO LA INTENISDAD

FIN

7. Diagrama Esquemático
RL1(NO)

RL1
G2R-14-AC120
U1
2
RA0/AN0 RC0/T1OSO/T1CKI
15
R1 Q1
3 16 BC548
RA1/AN1 RC1/T1OSI/CCP2/UOE
4 17 220
RA2/AN2/VREF-/CVREF RC2/CCP1/P1A
5 23
RA3/AN3/VREF+ RC4/D-/VM
6 24
RA4/T0CKI/C1OUT/RCV RC5/D+/VP
7 25
RA5/AN4/SS/LVDIN/C2OUT RC6/TX/CK
14
RA6/OSC2/CLKO RC7/RX/DT/SDO
26 U2
13 TRIAC
OSC1/CLKI
33 19 TR1
RB0/AN12/INT0/FLT0/SDI/SDA RD0/SPP0
34 20
RB1/AN10/INT1/SCK/SCL RD1/SPP1
35 21
RB2/AN8/INT2/VMO RD2/SPP2
36 22
37
RB3/AN9/CCP2/VPO RD3/SPP3
27 L1
RB4/AN11/KBI0/CSSPP RD4/SPP4 12V
38 28
RB5/KBI1/PGM RD5/SPP5/P1B
39 29
RB6/KBI2/PGC RD6/SPP6/P1C
40 30
RB7/KBI3/PGD RD7/SPP7/P1D
8
RE0/AN5/CK1SPP
9
RE1/AN6/CK2SPP
10 TRAN-2P2S
RE2/AN7/OESPP
18 1
VUSB RE3/MCLR/VPP
PIC18F4550

Imagen # 3Diagrama esquematico


8. Código fuente totalmente comentado
PRIMER PROGRAMA (USB4.c)

unsigned char readbuff[64] absolute 0x500; //crea una cadena de lectura de 64 bits en la
dirección
0x500;
unsigned char writebuff[64] absolute 0x540;//crea una cadena de escritura de 64 bits en la
dirceccion 0x540;
int cnt ; //creamos la variable entera cnt
unsigned short duty = 0;
char txt[64] ;
char txtInc[] = "Inc";
char txtDec[] = "Dec";
char txtOn[] = "On";
char txtOff[] = "Off";
unsigned char puente[64];
void interrupt(){
USB_Interrupt_Proc();
}
void main(){
ADCON1 |= 0x0F;
CMCON |= 7;
PORTB = 255; // sets port c to all 0
TRISB = 255;
PORTC = 0; // sets port c to all 0
TRISC = 0; //configures port c as output port
PWM1_Init (5000); // sets pwm frequency to 5000Hz
PWM1_Start(); // starts pwm1 peripheral

HID_Enable(&readbuff,&writebuff); // establecemos conexion atravez del HID


PWM1_Set_Duty(0);
while(1){
while(!HID_Read());
for(cnt=0;cnt<64;cnt++){
writebuff[cnt]=readbuff[cnt];
}
if(strncmp(readbuff,txtOff,3)==0){
PORTC.F1 = 0;
}
if(strncmp(readbuff,txtOn,3)==0){
PORTC.F1 = 1;
}
if(strncmp(readbuff,txtInc,2)==0){
if (duty >= 250) duty = 255;
else duty = duty +25;
PWM1_Set_Duty(duty); // Establece ciclo de trabajo
Delay_ms(10); // 10 msec delay
}
if(strncmp(readbuff,txtDec,2)==0){
if (duty <= 5) duty = 0;
else duty = duty -25;
PWM1_Set_Duty(duty); // Establece ciclo de trabajo
Delay_ms(10); // 10 msec delay
}
ByteToStr(duty,txt);
while(!HID_Write(&writebuff,64)) ;
for(cnt=0;cnt<64;cnt++){
writebuff[cnt] = txt[cnt];
}
while(!HID_Write(&writebuff,64));
}
}

SEGUNDO PROGRAMA (USBdsc.c)

const unsigned int USB_VENDOR_ID = 0x5423;


const unsigned int USB_PRODUCT_ID = 0x0001;
const char USB_SELF_POWER = 0x80; // Self powered 0xC0, 0x80 bus powered
const char USB_MAX_POWER = 50; // Bus power required in units of 2 mA
const char HID_INPUT_REPORT_BYTES = 64;
const char HID_OUTPUT_REPORT_BYTES = 64;
const char USB_TRANSFER_TYPE = 0x03; //0x03 Interrupt
const char EP_IN_INTERVAL = 1;
const char EP_OUT_INTERVAL = 1;

const char USB_INTERRUPT = 1;


const char USB_HID_EP = 1;
const char USB_HID_RPT_SIZE = 33;

/* Device Descriptor */
const struct {
char bLength; // bLength - Descriptor size in bytes (12h)
char bDescriptorType; // bDescriptorType - The constant DEVICE (01h)
unsigned int bcdUSB; // bcdUSB - USB specification release number (BCD)
char bDeviceClass; // bDeviceClass - Class Code
char bDeviceSubClass; // bDeviceSubClass - Subclass code
char bDeviceProtocol; // bDeviceProtocol - Protocol code
char bMaxPacketSize0; // bMaxPacketSize0 - Maximum packet size for endpoint 0
unsigned int idVendor; // idVendor - Vendor ID
unsigned int idProduct; // idProduct - Product ID
unsigned int bcdDevice; // bcdDevice - Device release number (BCD)
char iManufacturer; // iManufacturer - Index of string descriptor for the manufacturer
char iProduct; // iProduct - Index of string descriptor for the product.
char iSerialNumber; // iSerialNumber - Index of string descriptor for the serial number.
char bNumConfigurations; // bNumConfigurations - Number of possible configurations
} device_dsc = {
0x12, // bLength
0x01, // bDescriptorType
0x0200, // bcdUSB
0x00, // bDeviceClass
0x00, // bDeviceSubClass
0x00, // bDeviceProtocol
8, // bMaxPacketSize0
USB_VENDOR_ID, // idVendor
USB_PRODUCT_ID, // idProduct
0x0001, // bcdDevice
0x01, // iManufacturer
0x02, // iProduct
0x00, // iSerialNumber
0x01 // bNumConfigurations
};

/* Configuration 1 Descriptor */
const char configDescriptor1[]= {
// Configuration Descriptor
0x09, // bLength - Descriptor size in bytes
0x02, // bDescriptorType - The constant CONFIGURATION (02h)
0x29,0x00, // wTotalLength - The number of bytes in the configuration descriptor
and all of its subordinate descriptors
1, // bNumInterfaces - Number of interfaces in the configuration
1, // bConfigurationValue - Identifier for Set Configuration and Get Configuration
requests
0, // iConfiguration - Index of string descriptor for the configuration
USB_SELF_POWER, // bmAttributes - Self/bus power and remote wakeup settings
USB_MAX_POWER, // bMaxPower - Bus power required in units of 2 mA

// Interface Descriptor
0x09, // bLength - Descriptor size in bytes (09h)
0x04, // bDescriptorType - The constant Interface (04h)
0, // bInterfaceNumber - Number identifying this interface
0, // bAlternateSetting - A number that identifies a descriptor with alternate settings
for this bInterfaceNumber.
2, // bNumEndpoint - Number of endpoints supported not counting endpoint zero
0x03, // bInterfaceClass - Class code
0, // bInterfaceSubclass - Subclass code
0, // bInterfaceProtocol - Protocol code
0, // iInterface - Interface string index

// HID Class-Specific Descriptor


0x09, // bLength - Descriptor size in bytes.
0x21, // bDescriptorType - This descriptor's type: 21h to indicate the HID class.
0x01,0x01, // bcdHID - HID specification release number (BCD).
0x00, // bCountryCode - Numeric expression identifying the country for localized
hardware (BCD) or 00h.
1, // bNumDescriptors - Number of subordinate report and physical descriptors.
0x22, // bDescriptorType - The type of a class-specific descriptor that follows
USB_HID_RPT_SIZE,0x00, // wDescriptorLength - Total length of the descriptor identified above.

// Endpoint Descriptor
0x07, // bLength - Descriptor size in bytes (07h)
0x05, // bDescriptorType - The constant Endpoint (05h)
USB_HID_EP | 0x80, // bEndpointAddress - Endpoint number and direction
USB_TRANSFER_TYPE, // bmAttributes - Transfer type and supplementary information
0x40,0x00, // wMaxPacketSize - Maximum packet size supported
EP_IN_INTERVAL, // bInterval - Service interval or NAK rate

// Endpoint Descriptor
0x07, // bLength - Descriptor size in bytes (07h)
0x05, // bDescriptorType - The constant Endpoint (05h)
USB_HID_EP, // bEndpointAddress - Endpoint number and direction
USB_TRANSFER_TYPE, // bmAttributes - Transfer type and supplementary information
0x40,0x00, // wMaxPacketSize - Maximum packet size supported
EP_OUT_INTERVAL // bInterval - Service interval or NAK rate
};

const struct {
char report[USB_HID_RPT_SIZE];
}hid_rpt_desc =
{
{0x06, 0x00, 0xFF, // Usage Page = 0xFF00 (Vendor Defined Page 1)
0x09, 0x01, // Usage (Vendor Usage 1)
0xA1, 0x01, // Collection (Application)
// Input report
0x19, 0x01, // Usage Minimum
0x29, 0x40, // Usage Maximum
0x15, 0x00, // Logical Minimum (data bytes in the report may have minimum value =
0x00)
0x26, 0xFF, 0x00, // Logical Maximum (data bytes in the report may have maximum value =
0x00FF = unsigned 255)
0x75, 0x08, // Report Size: 8-bit field size
0x95, HID_INPUT_REPORT_BYTES,// Report Count
0x81, 0x02, // Input (Data, Array, Abs)
// Output report
0x19, 0x01, // Usage Minimum
0x29, 0x40, // Usage Maximum
0x75, 0x08, // Report Size: 8-bit field size
0x95, HID_OUTPUT_REPORT_BYTES,// Report Count
0x91, 0x02, // Output (Data, Array, Abs)
0xC0} // End Collection
};

//Language code string descriptor


const struct {
char bLength;
char bDscType;
unsigned int string[1];
} strd1 = {
4,
0x03,
{0x0409}
};

//Manufacturer string descriptor


const struct{
char bLength;
char bDscType;
unsigned int string[12];
}strd2={
26, //sizeof this descriptor string
0x03,
{'S','e','t','y','u','r','y',' ','C','o','r','p'}
};
//Product string descriptor
const struct{
char bLength;
char bDscType;
unsigned int string[12];
}strd3={
26, //sizeof this descriptor string
0x03,
{'C','o','n','e','x','i','o','n',' ','U','S','B'}
};

//Array of configuration descriptors


const char* USB_config_dsc_ptr[1];

//Array of string descriptors


const char* USB_string_dsc_ptr[3];

void USB_Init_Desc(){
USB_config_dsc_ptr[0] = &configDescriptor1;
USB_string_dsc_ptr[0] = (const char*)&strd1;
USB_string_dsc_ptr[1] = (const char*)&strd2;
USB_string_dsc_ptr[2] = (const char*)&strd3;
}

9. Recomendaciones
 Este circuito solo esta diseñado para mostrar la intensidad de iluminación del foco, pero
con un poco más de programación se podría añadir un display para mostrar la salida de
tensión exacta.
 Hacer una interfaz más amigable con el operador.
10. Conclusiones

 Logramos mostrar que la interfaz USB, es una interfaz cómoda para el usuario, solo
teniendo que definir el HID y el tamaño de buffer los cuales son sencillos de definir.

11. Bibliografía y referencias


https://www.fing.edu.uy/inco/grupos/mina/pGrado/pgusb/Docs/Presentacion_Sumo.pdf

http://robotypic.blogspot.com/2013/02/comunicacion-pc-pic-por-usb.html

http://www.aquihayapuntes.com/indice-practicas-pic-en-c/comunicacion-usb-pic18f4550-
utilizando-la-clase-cdc.html

Vous aimerez peut-être aussi