Professional Documents
Culture Documents
INTRODUCCION AL LABVIEW Y MIKROC........................................................2 Practica 1 Prueba de Eco Comunicacin serial...................................................3 Prctica 2 Convertidor analgico digital de 1 canal a 10 bits mediante puerto serie......................................................................................................................7 Prctica 3 Convertidor analgico digital de 3 canales 8 bits con comunicacin por puerto serie...................................................................................................10 Prctica 4 Prueba de eco USB...........................................................................14 Prctica 5 Prueba de eco USB por medio de LabView......................................29 Prctica 6 Convertidor analgico digital 1 canal, 8 bits por USB.......................34 Prctica 7 Convertidor analgico digital 1 canal, 10 bits por USB.....................40 Prctica 8. Convertidor analgico digital de 3 canales a 8 bits..........................46 Prctica 9. Convertidor analgico digital 1 canal, 10 bits con filtro....................53 Prctica 10. Convertidor analgico digital 3 canales con guardado de datos.. .56 Prctica 11. Control de motor reversible............................................................59 Prctica 12. Medicin de un potencimetro y de un generador de funciones por medio de la tarjeta USB-6008............................................................................65 Prctica 13. Frecuencmetro..............................................................................67 Prctica 14. Control de un sensor de temperatura con indicador de correo electrnico...........................................................................................................69
Push button Resistencia 10 kilo ohms Cristal 8Mhz Cable para protoboard.
1 1 1
Diagrama:
void main () { UART1_Init(9600); Delay_ms(100); TRISB = 0; PORTB = 0; while (1) { //inicializamos UART a 9600 bps //espera por UART para estabilizar //PORTB como salidas //apagamos todo el puerto //fin del ciclo 4
if (UART1_Data_Ready()) { //checamos si el dato es recibido uart_rd = UART1_Read(); PORTB = uart_rd; UART1_Write(uart_rd); } } } Programacion en Labview: //se envia dato por el UART //leemos el dato recibido
Conclusion: En esta prctica comenzamos a usar un nuevo PIC programando en un lenguaje avanzado como el C, usando como interfaz Labview logrando la comunicacin serial entre el pic y la computadora. Viendo el resultado en el control de encendido en el puertoB.
Cdigo en C char uart_rd1, uart_rd2; unsigned int temp_res; unsigned int uart_wr1, uart_wr2; 7
void main() {
while (1) { if (UART1_Data_Ready()) { temp_res = ADC_read(2); uart_rd1 = UART1_Read(); uart_wr1 = temp_res; UART1_Write(uart_wr1); PORTB = uart_wr1; Delay_ms(7); uart_rd2 = UART1_Read(); uart_wr2 = temp_res >> 8; UART1_Write(uart_wr2); PORTD = uart_wr2; Delay_ms(7); } } } Programacion en Labview:
Conclusion: Entre ms nos metemos al entorno de programacin, nos damos cuenta lo poderosa que es esta herramienta, tambin nos ayuda a conocer ms el lenguaje de programacin en C como ser capaces de disear una tarjeta adquiridora de datos para Labview.
Prctica 3 Convertidor analgico digital de 3 canales 8 bits con comunicacin por puerto serie.
Objetivo. Ahora que ya sabemos hacer la conversin y mandar los datos por puerto serie, ahora se deber de elaborar 3 convertidores a 8 bit, para ver el desempeo del PIC. Introduccin. Un CAD muestrea una seal analgica y la convierte en un valor digital de 'n' bits. Usualmente ser necesario acondicionar la seal de entrada del convertidor A-D, bien sea atenuando bien sea amplificndola. Este muestreo est definido por la funcin de transferencia. En la siguiente figura se muestra una funcin de transferencia ideal de un convertidor de 8 bits de precisin. Materiales: Potencimetros de 10 kilo con el circuito anterior Diagrama:
10
Cdigo en C. char uart_rd, uart_rd1, uart_rd2; unsigned int temp_res, temp_res1, temp_res2; unsigned int uart_wr, uart_wr1, uart_wr2; void main() { TRISA = 0XFF; TRISB = 0; UART1_Init(9600); Delay_ms(100); while (1) { if (UART1_Data_Ready()) { temp_res = ADC_read(1); uart_rd = UART1_Read(); if (uart_rd==64){ uart_wr = temp_res>> 2; UART1_Write(uart_wr); } Delay_ms(7); temp_res1 = ADC_read(2); uart_rd1 = UART1_Read(); if (uart_rd1==65){ uart_wr1 = temp_res1>> 2; UART1_Write(uart_wr1); } Delay_ms(7);
temp_res2 = ADC_read(3); 11
uart_rd2 = UART1_Read(); if (uart_rd2==69){ uart_wr2 = temp_res2>> 2; PORTB=uart_wr2; UART1_Write(uart_wr2); } Delay_ms(7); } } } Programacion en Labview:
12
Conclusin: Como podemos ver cada convertidor tiene su propia respuesta, y esto lo logramos con la programacin en C, esto se puede ver en las llaves en cada lectura. Labview nos ayuda mucho en la construccin de estas prcticas.
13
14
Cdigo en C Programa Principal. /* * Project name: HIDtest2 (USB HID Read & Write Test) * Copyright: (c) MikroElektronika, 2005-2008 * Revision History: 20050502: - initial release; * Description: This example establishes connection with the HID terminal that is active on the PC. Upon connection establishment, the HID Device Name will appear in the respective window. The character that user sends to PIC from the HID terminal will be re-sent back to user. * Test configuration: MCU: PIC18F4550 15
http://www.mikroe.com/en/tools/easypic6/ Oscillator: Ext. Modules: HS 8.000 MHz (USB osc. is raised with PLL to 48.000MHz) on-board USB-HID
http://www.mikroe.com/pdf/easypic6/easypic6_manual_v100.pdf#page14 SW: mikroC PRO for PIC http://www.mikroe.com/en/compilers/mikroc/pro/pic/ * NOTES: (*) Be VERY careful about the configuration flags for the 18F4550 - there's so much place for mistake! - Place jumpers J12 in the right position */ unsigned char k; unsigned char userWR_buffer[64], userRD_buffer[64]; const char *text = "MIKROElektronika Compilers ER \r\n"; //***************************************************************************************** ********* // Main Interrupt Routine //***************************************************************************************** ********* void interrupt() { HID_InterruptProc(); } //***************************************************************************************** *********
16
//***************************************************************************************** ********* // Initialization Routine //***************************************************************************************** ********* void Init_Main() { //-------------------------------------// Disable all interrupts //-------------------------------------INTCON = 0; INTCON2 = 0xF5; INTCON3 = 0xC0; RCON.IPEN = 0; PIE1 = 0; PIE2 = 0; PIR1 = 0; PIR2 = 0; ADCON1 |= 0x0F; as digital CMCON |= 7; //-------------------------------------// Ports Configuration //-------------------------------------TRISA = 0xFF; TRISB = 0xFF; TRISC = 0xFF; TRISD = 0; 17 // Configure all ports with analog function // Disable comparators // Disable Priority Levels on interrupts // Disable GIE, PEIE, TMR0IE,INT0IE,RBIE
TRISE = 0x07; LATA = 0; LATB = 0; LATC = 0; LATD = 0; LATE = 0; //-------------------------------------// Clear user RAM // Banks [00 .. 07] ( 8 x 256 = 2048 Bytes ) //-------------------------------------} //***************************************************************************************** //***************************************************************************************** // Main Program Routine //***************************************************************************************** void main() { unsigned char i, ch; Init_Main(); HID_Enable(&userRD_buffer, &userWR_buffer); Delay_ms(1000); Delay_ms(1000); while (1) { k = HID_Read(); i = 0; while (i < k) { ch = userRD_buffer[i]; PORTD = ch; userWR_buffer[0] = ch; 18
while (!HID_Write(&userWR_buffer, 1)) ; i++; } } HID_Disable(); } //***************************************************************************************** Programas fuente. //****************************************************************************** // // File Version 1.01 // //****************************************************************************** #include "Definit.h" #include "VARs.h" // The number of bytes in each report, // calculated from Report Size and Report Count in the report descriptor unsigned char const HID_INPUT_REPORT_BYTES unsigned char const HID_OUTPUT_REPORT_BYTES unsigned char const HID_FEATURE_REPORT_BYTES // Byte constants unsigned char const NUM_ENDPOINTS = 2; = 1; = 1; = 2;
unsigned char const ConfigDescr_wTotalLength = USB_CONFIG_DESCRIPTOR_LEN + USB_INTERF_DESCRIPTOR_LEN + USB_HID_DESCRIPTOR_LEN + (NUM_ENDPOINTS * USB_ENDP_DESCRIPTOR_LEN); unsigned char const HID_ReportDesc_len unsigned char const Low_HID_ReportDesc_len = 47; = HID_ReportDesc_len; 19
unsigned char const High_HID_ReportDesc_len 8; unsigned char const Low_HID_PACKET_SIZE unsigned char const High_HID_PACKET_SIZE 8; // Descriptor Tables
unsigned char const DescTables[USB_DEVICE_DESCRIPTOR_ALL_LEN*2] = { // Device Descriptor USB_DEVICE_DESCRIPTOR_LEN, 0, Device descriptor (always 0x12) USB_DEVICE_DESCRIPTOR_TYPE, 0, DEVICE descriptor 0x00, 0, byte) 0x02, 0, // bcdUSB // // bLength // bDescriptorType - Length of -1=
0x00, 0, // bDeviceClass - Zero means each interface operates independently (class code in the interface descriptor) 0x00, 0, 0x00, 0, // bDeviceSubClass // bDeviceProtocol - maximum size
EP0_PACKET_SIZE, 0, // bMaxPacketSize0 of a data packet for a control transfer over EP0 0x78, 0, 0x56, 0, 0x01, 0, 0x00, 0, 0x01, 0, 0x00, 0, 0x01, 0, 0x02, 0, // idVendor // // idProduct // // bcdDevice // // iManufacturer // iProduct
- Vendor ID (low byte) (high byte) - Product ID (low byte) (high byte) - ( low byte) (high byte) - String1 - String2 20
// iSerialNumber
- ( None ) -1
// bNumConfigurations
// bLength // bDescriptorType
- Length of -2=
ConfigDescr_wTotalLength, 0, // wTotalLength - Total length of this config. descriptor plus the interface and endpoint descriptors that are part of the configuration. 0x00, 0, 0x01, 0, 0x01, 0, 0x00, 0, configuration ( None ) 0xA0, 0, and "Remote wakeup" 50, 0, mA from the bus. // Interface Descriptor USB_INTERF_DESCRIPTOR_LEN, 0, Interface descriptor (always 0x09) USB_INTERFACE_DESCRIPTOR_TYPE, 0, INTERFACE descriptor 0x00, 0, based array 0x00, 0, // bInterfaceNumber // bAlternateSetting // bLength - Length of -4= // ( high byte) - Number of interfaces
// bNumInterfaces
// bConfigurationValue - Configuration Value // iConfiguration // bmAttributes // MaxPower - String Index for this - attributes - "Bus powered" - bus-powered draws 50*2
// bDescriptorType
// bNumEndPoints
// bInterfaceClass // bInterfaceSubClass
0x00, 0,
// bInterfaceProtocol
- none
0x00, 0, // iInterface describes this interface ( None ) // HID Descriptor USB_HID_DESCRIPTOR_LEN, 0, HID descriptor (always 0x09) USB_HID_DESCRIPTOR_TYPE, 0, HID descriptor 0x01, 0, 0x01, 0, 0x00, 0, 0x01, 0, 0x22, 0,
// bLength // bDescriptorType
- Length of - 0x21 =
// Localized country code (none) // # of HID class descriptor to follow (1) // Report descriptor type (HID)
Low_HID_ReportDesc_len, 0, High_HID_ReportDesc_len, 0, // EP1_RX Descriptor USB_ENDP_DESCRIPTOR_LEN, 0, descriptor (always 0x07) USB_ENDPOINT_DESCRIPTOR_TYPE, 0, ENDPOINT descriptor 0x81, 0, // bEndpointAddress // bLength - length of -5=
USB_ENDPOINT_TYPE_INTERRUPT, 0, Endpoint Type - Interrupt Low_HID_PACKET_SIZE, 0, size - low order byte High_HID_PACKET_SIZE, 0, high order byte 1, 0, // EP1_TX Descriptor USB_ENDP_DESCRIPTOR_LEN, 0, descriptor (always 0x07) // bInterval
// bmAttributes
// wMaxPacketSize //
- max packet
// bLength
- length of 22
-5=
USB_ENDPOINT_TYPE_INTERRUPT, 0, Endpoint Type - Interrupt Low_HID_PACKET_SIZE, 0, size - low order byte High_HID_PACKET_SIZE, 0, high order byte 1, 0, // HID_Report Descriptor 0x06, 0, 0xA0, 0, 0xFF, 0, 0x09, 0, 0x01, 0, 0xA1, 0, 0x01, 0, // The Input report 0x09, 0, 0x03, 0, 0x15, 0, 0x00, 0, 0x26, 0, 0x00, 0, 0xFF, 0, 0x75, 0, 0x08, 0, 0x95, 0, // bInterval
// bmAttributes
// wMaxPacketSize //
- max packet
// COLLECTION (Application)
// LOGICAL_MINIMUM (0)
// LOGICAL_MAXIMUM (255)
// REPORT_SIZE (8)
// REPORT_COUNT (2) 23
HID_INPUT_REPORT_BYTES, 0, 0x81, 0, 0x02, 0, // The Output report 0x09, 0, 0x04, 0, 0x15, 0, 0x00, 0, 0x26, 0, 0x00, 0, 0xFF, 0, 0x75, 0, 0x08, 0, 0x95, 0, // REPORT_COUNT (2) // REPORT_SIZE (8) // LOGICAL_MAXIMUM (255) // LOGICAL_MINIMUM (0) // USAGE ID - Vendor defined // INPUT (Data,Var,Abs)
HID_OUTPUT_REPORT_BYTES, 0, 0x91, 0, 0x02, 0, // The Feature report 0x09, 0, 0x05, 0, 0x15, 0, 0x00, 0, 0x26, 0, 0x00, 0, 0xFF, 0, 0x75, 0, 0x08, 0, 24 // REPORT_SIZE (8) // LOGICAL_MAXIMUM (255) // LOGICAL_MINIMUM (0) // USAGE ID - Vendor defined // OUTPUT (Data,Var,Abs)
0x95, 0,
// REPORT_COUNT (2)
HID_FEATURE_REPORT_BYTES, 0, 0xB1, 0, 0x02, 0, // End Collection 0xC0, 0 }; //****************************************************************************** unsigned char const LangIDDescr[8] = { 0x04, 0, USB_STRING_DESCRIPTOR_TYPE, 0, 0x09, 0, 0x04, 0 }; //****************************************************************************** unsigned char const ManufacturerDescr[68] = { 34, 0, USB_STRING_DESCRIPTOR_TYPE, 0, 't', 0, 0, 0, 'e', 0, 0, 0, 'm', 0, 0, 0, 'a', 0, 0, 0, 's', 0, 0, 0, ' ', 0, 0, 0, 'a', 0, 0, 0, 'v', 0, 0, 0, 'a', 0, 0, 0, 25 // LangID (0x0409) - Low // - High // END_COLLECTION // FEATURE (Data,Var,Abs)
'n', 0, 0, 0, 'z', 0, 0, 0, 'a', 0, 0, 0, 'd', 0, 0, 0, 'o', 0, 0, 0, 's', 0, 0, 0, ' ', 0, 0, 0 }; //****************************************************************************** unsigned char const ProductDescr[96] = { 48, 0, USB_STRING_DESCRIPTOR_TYPE, 0, 'm', 0, 0, 0, 'i', 0, 0, 0, 'k', 0, 0, 0, 'r', 0, 0, 0, 'o', 0, 0, 0, 'C', 0, 0, 0, ' ', 0, 0, 0, 'P', 0, 0, 0, 'I', 0, 0, 0, 'C', 0, 0, 0, ' ', 0, 0, 0, '1', 0, 0, 0, '8', 0, 0, 0, 'F', 0, 0, 0, '4', 0, 0, 0, 26
'5', 0, 0, 0, '5', 0, 0, 0, '0', 0, 0, 0, ' ', 0, 0, 0, 't', 0, 0, 0, 'e', 0, 0, 0, 's', 0, 0, 0, 't', 0, 0, 0 }; //****************************************************************************** unsigned char const StrUnknownDescr[4] = { 2, 0, USB_STRING_DESCRIPTOR_TYPE, 0 }; // Initialization Function void InitUSBdsc() { Byte_tmp_0[0] = NUM_ENDPOINTS; Byte_tmp_0[0] = ConfigDescr_wTotalLength; Byte_tmp_0[0] = HID_ReportDesc_len; Byte_tmp_0[0] = Low_HID_ReportDesc_len; Byte_tmp_0[0] = High_HID_ReportDesc_len; Byte_tmp_0[0] = Low_HID_PACKET_SIZE; Byte_tmp_0[0] = High_HID_PACKET_SIZE; DescTables; LangIDDescr; ManufacturerDescr; 27
ProductDescr; StrUnknownDescr; } Procedimiento: Conectar el dispositivo a la computadora. En MIKROC acceder a la ventana de pruebas HID. HID es Human Interface Device. Desde MikroC verificar si el dispositivo tiene comunicacin con la computadora.
Conclusin: Al desarrollar la prctica nos damos cuenta la aplicacin que se le puede dar a esta comunicacin, como tambin nos muestra la necesidad de crear driver para probar nuestro primer diseo lo cual veremos en la siguiente practica.
28
29
Cambiar el ID vendor y el ID product; POR LOS MISMOS QUE HEMOS CAMBIADO EN NUESTRO ARCHIVO FUENTE Y QUE HEMOS YA QUEMADO EN EL PIC.
30
Si se quiere, cambiar el fabricante y el modelo del dispositivo, para crear un driver ms personalizado.
31
Crearlo e instalarlo, una vez hecho esto, conectamos el dispositivo y en donde la computadora lo reconozca, actualizamos el controlador por el nuevo que acabamos de crear. Verificar: Cuando el dispositivo deje de ser HID y pase a Dispositivo de National Instrumenst, significa que hemos hecho el proceso de manera correcta. Programacin en Labview:
32
Conclusion: Ahora hemos creado el driver que nos ayudara a la elaboracin de las siguientes practicas, con esto y el programa de ECO hemos dado un paso a la programacin con USB.
33
Cdigo C Programa principal. /* * Project name: HIDtest2 (USB HID Read & Write Test) * Copyright: (c) MikroElektronika, 2005-2008 * Revision History: 20050502: 34
- initial release; * Description: This example establishes connection with the HID terminal that is active on the PC. Upon connection establishment, the HID Device Name will appear in the respective window. The character that user sends to PIC from the HID terminal will be re-sent back to user. * Test configuration: MCU: PIC18F4550 http://ww1.microchip.com/downloads/en/DeviceDoc/39632D.pdf Dev.Board: EasyPIC6
http://www.mikroe.com/en/tools/easypic6/ Oscillator: Ext. Modules: HS 8.000 MHz (USB osc. is raised with PLL to 48.000MHz) on-board USB-HID
http://www.mikroe.com/pdf/easypic6/easypic6_manual_v100.pdf#page14 SW: mikroC PRO for PIC http://www.mikroe.com/en/compilers/mikroc/pro/pic/ * NOTES: (*) Be VERY careful about the configuration flags for the 18F4550 - there's so much place for mistake! - Place jumpers J12 in the right position */ unsigned char k; unsigned char userWR_buffer[64], userRD_buffer[64]; unsigned int temp_res; const char *text = "MIKROElektronika Compilers ER \r\n"; //***************************************************************************************** 35
// Main Interrupt Routine //***************************************************************************************** void interrupt() { HID_InterruptProc(); } //**************************************************************************** //***************************************************************************************** // Initialization Routine //**************************************************************************** void Init_Main() { //-------------------------------------// Disable all interrupts //-------------------------------------INTCON = 0; INTCON2 = 0xF5; INTCON3 = 0xC0; RCON.IPEN = 0; PIE1 = 0; PIE2 = 0; PIR1 = 0; PIR2 = 0; ADCON1 |= 0x00; as digital (0X0F - Valor previo) CMCON |= 7; //-------------------------------------// Configure all ports with analog function // Disable comparators // Disable Priority Levels on interrupts // Disable GIE, PEIE, TMR0IE,INT0IE,RBIE
36
// Ports Configuration //-------------------------------------TRISA = 0xFF; TRISB = 0xFF; TRISC = 0xFF; TRISD = 0; TRISE = 0x07; LATA = 0; LATB = 0; LATC = 0; LATD = 0; LATE = 0; //-------------------------------------// Clear user RAM // Banks [00 .. 07] ( 8 x 256 = 2048 Bytes ) //-------------------------------------} //**************************************************************************** // Main Program Routine //**************************************************************************** void main() { unsigned char i, ch; Init_Main(); HID_Enable(&userRD_buffer, &userWR_buffer); Delay_ms(1000); Delay_ms(1000); while (1) { k = HID_Read(); 37
i = 0; while (i < k) { ch = userRD_buffer[i]; temp_res = ADC_read(2); PORTD = temp_res>> 2; userWR_buffer[0] = temp_res>> 2; while (!HID_Write(&userWR_buffer, 1)) ; i++; } } HID_Disable(); } //**************************************************************************** Programacion en Labview:
38
Conclusin: Ahora vemos un mejor resultado con el muestreo de nuestros datos adquiridos del potencimetro, eso se debe al protocolo de comunicacin, con esto podemos ver la practicidad del USB.
39
terminal will be re-sent back to user. * Test configuration: MCU: PIC18F4550 http://ww1.microchip.com/downloads/en/DeviceDoc/39632D.pdf Dev.Board: EasyPIC6
http://www.mikroe.com/en/tools/easypic6/ Oscillator: Ext. Modules: HS 8.000 MHz (USB osc. is raised with PLL to 48.000MHz) on-board USB-HID
http://www.mikroe.com/pdf/easypic6/easypic6_manual_v100.pdf#page14 SW: mikroC PRO for PIC http://www.mikroe.com/en/compilers/mikroc/pro/pic/ * NOTES: (*) Be VERY careful about the configuration flags for the 18F4550 - there's so much place for mistake! - Place jumpers J12 in the right position */ unsigned char k; unsigned char userWR_buffer[64], userRD_buffer[64]; unsigned int temp_res; const char *text = "MIKROElektronika Compilers ER \r\n"; //***************************************************************************************** // Main Interrupt Routine //***************************************************************************************** void interrupt() { HID_InterruptProc();
41
} //***************************************************************************************** //***************************************************************************************** // Initialization Routine //***************************************************************************************** void Init_Main() { //-------------------------------------// Disable all interrupts //-------------------------------------INTCON = 0; INTCON2 = 0xF5; INTCON3 = 0xC0; RCON.IPEN = 0; PIE1 = 0; PIE2 = 0; PIR1 = 0; PIR2 = 0; ADCON1 |= 0x00; as digital (0X0F - Valor previo) CMCON |= 7; //-------------------------------------// Ports Configuration //-------------------------------------TRISA = 0xFF; TRISB = 0; TRISC = 0xFF; // Configure all ports with analog function // Disable comparators // Disable Priority Levels on interrupts // Disable GIE, PEIE, TMR0IE,INT0IE,RBIE
42
TRISD = 0; TRISE = 0x07; LATA = 0; LATB = 0; LATC = 0; LATD = 0; LATE = 0; //-------------------------------------// Clear user RAM // Banks [00 .. 07] ( 8 x 256 = 2048 Bytes ) //-------------------------------------} //***************************************************************************************** //***************************************************************************************** // Main Program Routine //***************************************************************************************** void main() { unsigned char i, ch, ch2; Init_Main(); HID_Enable(&userRD_buffer, &userWR_buffer); Delay_ms(1000); Delay_ms(1000) while (1) { k = HID_Read(); i = 0; while (i < k) { ch = userRD_buffer[i]; if (ch == 0X01) { 43
temp_res = ADC_read(2); PORTD = temp_res; userWR_buffer[0] = temp_res; } Delay_ms(7); ch2 = userRD_buffer[i]; if (ch2 == 0x08) { PORTB = temp_res >> 8; userWR_buffer[0] = temp_res >> 8; } while (!HID_Write(&userWR_buffer, 1)) ; i++; } } HID_Disable(); } //***************************************************************************************** Programacin en Labview:
44
Conclusin: La conversin a 10 bits nos da mejor respuesta debido a la resolucin. Lo que se observo en la practica fueron perturbaciones debido al ruido entregado del mismo potencimetro.
45
MCU:
PIC18F4550 http://ww1.microchip.com/downloads/en/DeviceDoc/39632D.pdf
Dev.Board:
EasyPIC6
http://www.mikroe.com/en/tools/easypic6/ Oscillator: Ext. Modules: HS 8.000 MHz (USB osc. is raised with PLL to 48.000MHz) on-board USB-HID
http://www.mikroe.com/pdf/easypic6/easypic6_manual_v100.pdf#page14 SW: mikroC PRO for PIC http://www.mikroe.com/en/compilers/mikroc/pro/pic/ * NOTES: (*) Be VERY careful about the configuration flags for the 18F4550 - there's so much place for mistake! - Place jumpers J12 in the right position */ unsigned char k; unsigned char userWR_buffer[64], userRD_buffer[64]; unsigned int temp_res, temp_res1, temp_res2; const char *text = "MIKROElektronika Compilers ER \r\n"; //***************************************************************************************** // Main Interrupt Routine //***************************************************************************************** void interrupt() { HID_InterruptProc(); } //*****************************************************************************************
47
//***************************************************************************************** // Initialization Routine //***************************************************************************************** void Init_Main() { //-------------------------------------// Disable all interrupts //-------------------------------------INTCON = 0; INTCON2 = 0xF5; INTCON3 = 0xC0; RCON.IPEN = 0; PIE1 = 0; PIE2 = 0; PIR1 = 0; PIR2 = 0; ADCON1 |= 0x00; as digital (0X0F - Valor previo) CMCON |= 7; //-------------------------------------// Ports Configuration //-------------------------------------TRISA = 0xFF; TRISB = 0; TRISC = 0xFF; TRISD = 0; TRISE = 0x07; // Configure all ports with analog function // Disable comparators // Disable Priority Levels on interrupts // Disable GIE, PEIE, TMR0IE,INT0IE,RBIE
48
LATA = 0; LATB = 0; LATC = 0; LATD = 0; LATE = 0; //-------------------------------------// Clear user RAM // Banks [00 .. 07] ( 8 x 256 = 2048 Bytes ) //-------------------------------------} //***************************************************************************************** // Main Program Routine //***************************************************************************************** void main() { unsigned char i, ch, ch2, ch3 ; Init_Main(); HID_Enable(&userRD_buffer, &userWR_buffer); Delay_ms(1000); Delay_ms(1000); while (1) { k = HID_Read(); i = 0; while (i < k) { ch = userRD_buffer[i]; if (ch == 0X01) { temp_res = ADC_read(0); userWR_buffer[0] = temp_res>> 2; } 49
Delay_ms(7); ch2 = userRD_buffer[i]; if (ch2 == 0x08) { temp_res1 = ADC_read(1); userWR_buffer[0] = temp_res1>> 2; } Delay_ms(7); ch3 = userRD_buffer[i]; if (ch3 == 0x0F) { temp_res2 = ADC_read(2); userWR_buffer[0] = temp_res2>> 2; } while (!HID_Write(&userWR_buffer, 1)) ; i++; } } HID_Disable(); } Programacin con labview:
50
51
Conclusin: Podemos ver la cantidad de datos y la velocidad con la cual se puede trabajar con el protocolo USB.
52
53
54
Conclusin: Al llevar a cabo esta prctica podemos ver el cambio entre la seal de entrada en la prctica anterior a la actual esto gracias al filtro. Nos damos cuenta que un filtro no en necesariamente colocar un capacitor y una resistencia o usando opam, sino que tambin lo podemos realizar mediante software.
55
Programacin en Labview:
56
57
Conclusin: Usamos una herramienta de Labview para guardar los datos obtenidos de la medicin, as vamos conociendo mas nuestra interfaz.
58
http://www.mikroe.com/en/tools/easypic6/ Oscillator: Ext. Modules: HS 8.000 MHz (USB osc. is raised with PLL to 48.000MHz) on-board USB-HID
http://www.mikroe.com/pdf/easypic6/easypic6_manual_v100.pdf#page14 SW: mikroC PRO for PIC http://www.mikroe.com/en/compilers/mikroc/pro/pic/ * NOTES: (*) Be VERY careful about the configuration flags for the 18F4550 - there's so much place for mistake! - Place jumpers J12 in the right position */ unsigned char k; unsigned char userWR_buffer[64], userRD_buffer[64]; const char *text = "MIKROElektronika Compilers ER \r\n"; //***************************************************************************************** // Main Interrupt Routine //***************************************************************************************** void interrupt() { HID_InterruptProc(); } //*****************************************************************************************
60
//***************************************************************************************** // Initialization Routine //***************************************************************************************** void Init_Main() { //-------------------------------------// Disable all interrupts //-------------------------------------INTCON = 0; INTCON2 = 0xF5; INTCON3 = 0xC0; RCON.IPEN = 0; PIE1 = 0; PIE2 = 0; PIR1 = 0; PIR2 = 0; ADCON1 |= 0x0F; as digital CMCON |= 7; //-------------------------------------// Ports Configuration //-------------------------------------TRISA = 0xFF; TRISB = 0xFF; TRISC = 0xFF; TRISD = 0; TRISE = 0x07; // Configure all ports with analog function // Disable comparators // Disable Priority Levels on interrupts // Disable GIE, PEIE, TMR0IE,INT0IE,RBIE
61
LATA = 0; LATB = 0; LATC = 0; LATD = 0; LATE = 0; //-------------------------------------// Clear user RAM // Banks [00 .. 07] ( 8 x 256 = 2048 Bytes ) //-------------------------------------} //***************************************************************************************** //***************************************************************************************** // Main Program Routine //***************************************************************************************** void main() { unsigned char i, ch, ch1; Init_Main(); HID_Enable(&userRD_buffer, &userWR_buffer); Delay_ms(1000); Delay_ms(1000); while (1) { k = HID_Read(); i = 0; while (i < k) { ch = userRD_buffer[i]; PORTD = ch; ch1 = PORTB; userWR_buffer[0] = ch1; 62
63
Resultados. Podemos ver lo poderoso que es saber usar una herramienta como el Labview para poder controlar un motor usando la lgica de escalera, claro este gracias a acoplar al pic con un programa en lenguaje c usando mikroc.
64
Prctica 12. Medicin de un potencimetro y de un generador de funciones por medio de la tarjeta USB6008.
Objetivo. Aprender a usar una nueva interfaz para conocer la diferencia de programacin asi como todas las utilidades de la tarjeta. Introduccin. Las tarjetas DAQ NI USB-6008 y NI USB-6009 tienen capacidades multifuncin con ocho canales de entrada analgica 12 14 bits, dos salidas analgicas, 12 lneas E/S digitales y un contador. Ambos dispositivos funcionan con la corriente del bus USB as que no necesitan una fuente de energa externa para trabajar. Incluyen terminales de tornillo para extrables para conectarse por seal directa, una referencia de tensin de abordo para suministrar energa a dispositivos y sensores externos, una capa diseada en cuatro capas para reducir el ruido y aumentar la precisin, as como para proteger contra sobretensin en las lneas de entrada analgica de hasta 35 V. Material: USB-6008 Potencimetro Generador de funciones. Diagrama: Colocaremos la salida del potencimetro a la salida AI0 y lo alimentaremos con la fuente incluida en la tarjeta. El generador de funciones entrara en AI1+ y AI1para usar el modo diferencial.
Programacion en Labview:
65
Conclusion: Conocer las interfaces realizadas por national instruments y ver la diferencia de practicidad entre la daq profesional o una hecha por nosotros.
66
67
Conclusin: Vemos la facilidad de procesar una seal con la ayuda de la tarjeta USB 6008 realizando un frecuencmetro acercndonos al comportamiento de un osciloscopio.
68
69
Conclusin: Vemos la facilidad de hacer un sistema telemtrico usando la interfaz USB 6008 y la herramienta de Labview para censar la temperatura y mandar un correo con los datos obtenidos en la medicin.
70