Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case COMMAND_GET_TRANSISTOR_TYPE:
- {
- uint16_t vd1;
- uint16_t vd2;
- uint16_t Vdx_jfet;
- uint16_t Vdy_jfet;
- unsigned char TransType;
- if(!HIDTxHandleBusy(USBInHandle))
- {
- //Use ADC to read the I/O pin voltage. See the relevant HardwareProfile - xxxxx.h file for the I/O pin that it will measure.
- //Some demo boards, like the PIC18F87J50 FS USB Plug-In Module board, do not have a potentiometer (when used stand alone).
- //This function call will still measure the analog voltage on the I/O pin however. To make the demo more interesting, it
- //is suggested that an external adjustable analog voltage should be applied to this pin.
- // 1v = nivel 205
- // dar 0v al pin 2
- Voltaje_Pin2 = 0;
- __delay_ms(3000);
- if(ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VS) > 205) //if true, it will be whether a P type, a not functioning or Jfet
- {
- //dar 5V al pin2
- Vdx_jfet = ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VS);
- Voltaje_Pin2 = Encendido_5v;
- __delay_ms(3000);
- if(ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VS) > 205) //Si verdadero, Transitor no funiona o Jfet, si Falso, Tipo P
- {
- Vdy_jfet = ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VS);
- if(Vdy_jfet >= Vdx_jfet) //N_Type or malfunctionning
- {
- __delay_ms(3000);
- vd1 = ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VG1);
- __delay_ms(5);
- vd2 = ADC_Read10bit (ADC_CHANNEL_ID_TRANS_VG2);
- if((vd1 - vd2) <= 35 || vd1 == vd2) // Malfunctioning
- {
- //Malfunctioning
- TransType = 0x02;
- }
- else // N Type or not functioning
- {
- Voltaje_Pin2 = 0;
- __delay_ms(1500);
- vd1 = ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VG1);
- __delay_ms(5);
- vd2 = ADC_Read10bit (ADC_CHANNEL_ID_TRANS_VG2);
- if((vd1 - vd2) <= 35 || vd1 == vd2) // N JFET - If there is not Current
- {
- TransType = 0x07;
- }
- else // Malfunctioning - If there is current
- {
- TransType = 0x02;
- }
- } // N Type or not functioning Else
- }
- else // P_Type or Malfunctioning
- {
- __delay_ms(3000);
- vd1 = ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VG1);
- __delay_ms(5);
- vd2 = ADC_Read10bit (ADC_CHANNEL_ID_TRANS_VG2);
- if((vd1 - vd2) <= 35 || vd1 == vd2)
- {
- //PJFET
- TransType = 0x08;
- }
- else
- {
- //Malfunctioning
- TransType = 0x02;
- }
- } //p_Type or malfunctioning Else
- } //Transistor no funciona o JFET "IF"
- else //Tipo P
- {
- Voltaje_Pin2 = 0;
- __delay_ms(3000);
- vd1 = ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VG1);
- __delay_ms(5);
- vd2 = ADC_Read10bit (ADC_CHANNEL_ID_TRANS_VG2);
- if((vd2 - vd1) >= 614 ) // Si verdadero, transistor PMOS, si Falso, transistor PBJT
- {
- TransType = 0x04; //PMOS
- }
- else
- {
- TransType = 0x06; // PBJT
- }
- } // Tipo P "else"
- }
- else // N o malFunciona
- {
- Voltaje_Pin2 = Encendido_5v; //dar 5V al pin2
- __delay_ms(3000);
- if(ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VS) > 205) //Si verdadero, Tipo N, Falso -> MalFuncionamiento
- {
- vd1 = ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VG1);
- __delay_us(5);
- vd2 = ADC_Read10bit (ADC_CHANNEL_ID_TRANS_VG2);
- if((vd1 - vd2) <= 35 || vd1 == vd2) // Si verdadero, transistor N-BJT, si Falso, transistor NMOS
- {
- TransType = 0x05; // NMOS
- Voltaje_Pin2 = 0;
- }
- else
- {
- TransType = 0x03; // NBJT
- Voltaje_Pin2 = 0;
- }
- }
- else
- {
- TransType = 0x02; // Mal Funcionamiento
- Voltaje_Pin2 = 0;
- }
- }
- ToSendDataBuffer[0] = 0x37; //Echo back to the host the command we are fulfilling in the first uint8_t. In this case, the Read POT (analog voltage) command.
- ToSendDataBuffer[1] = TransType; //LSB
- //Prepare the USB module to send the data packet to the host
- USBInHandle = HIDTxPacket(CUSTOM_DEVICE_HID_EP, (uint8_t*)&ToSendDataBuffer[0],64);
- }
- }
- break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement