Advertisement
Sirallens

Untitled

Dec 8th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.81 KB | None | 0 0
  1. case COMMAND_GET_TRANSISTOR_TYPE:
  2.             {
  3.                       uint16_t vd1;
  4.                       uint16_t vd2;
  5.                       uint16_t Vdx_jfet;
  6.                       uint16_t Vdy_jfet;
  7.                      
  8.                       unsigned char TransType;
  9.                       if(!HIDTxHandleBusy(USBInHandle))
  10.                     {
  11.                         //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.
  12.                         //Some demo boards, like the PIC18F87J50 FS USB Plug-In Module board, do not have a potentiometer (when used stand alone).
  13.                         //This function call will still measure the analog voltage on the I/O pin however.  To make the demo more interesting, it
  14.                         //is suggested that an external adjustable analog voltage should be applied to this pin.
  15.                         // 1v = nivel 205  
  16.                        
  17.                           // dar 0v al pin 2
  18.                          
  19.                               Voltaje_Pin2 = 0;
  20.                           __delay_ms(3000);
  21.                          
  22.                                
  23.                          
  24.                           if(ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VS) > 205)  //if true, it will be whether a P type, a not functioning or Jfet
  25.                           {
  26.                               //dar 5V al pin2
  27.                              
  28.                               Vdx_jfet = ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VS);
  29.                              
  30.                               Voltaje_Pin2 = Encendido_5v;
  31.                               __delay_ms(3000);
  32.                              
  33.                               if(ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VS) > 205)  //Si verdadero, Transitor no funiona o Jfet, si Falso, Tipo P
  34.                               {
  35.                                   Vdy_jfet = ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VS);
  36.                                  
  37.                                   if(Vdy_jfet >= Vdx_jfet)  //N_Type or malfunctionning
  38.                                   {
  39.                                     __delay_ms(3000);
  40.                                     vd1 = ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VG1);
  41.                                     __delay_ms(5);
  42.                                     vd2 = ADC_Read10bit (ADC_CHANNEL_ID_TRANS_VG2);
  43.                                    
  44.                                       if((vd1 - vd2) <= 35 || vd1 == vd2) // Malfunctioning
  45.                                       {
  46.                                           //Malfunctioning
  47.                                           TransType = 0x02;
  48.                                       }
  49.                                      
  50.                                       else  // N Type or not functioning
  51.                                       {
  52.                                         Voltaje_Pin2 = 0;
  53.                                         __delay_ms(1500);
  54.  
  55.                                        
  56.                                         vd1 = ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VG1);
  57.                                         __delay_ms(5);
  58.                                         vd2 = ADC_Read10bit (ADC_CHANNEL_ID_TRANS_VG2);
  59.  
  60.                                         if((vd1 - vd2) <= 35 || vd1 == vd2) // N JFET - If there is not Current
  61.                                         {
  62.                                             TransType = 0x07;
  63.                                         }                                
  64.                                          
  65.                                         else  // Malfunctioning - If there is current
  66.                                         {
  67.                                            
  68.                                             TransType = 0x02;
  69.                                         }
  70.                                          
  71.                                       } // N Type or not functioning Else
  72.                                      
  73.                                      
  74.                                   }
  75.                                  
  76.                                   else // P_Type or Malfunctioning
  77.                                   {
  78.                                     __delay_ms(3000);
  79.                                     vd1 = ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VG1);
  80.                                     __delay_ms(5);
  81.                                     vd2 = ADC_Read10bit (ADC_CHANNEL_ID_TRANS_VG2);
  82.                                    
  83.                                     if((vd1 - vd2) <= 35 || vd1 == vd2)
  84.                                     {
  85.                                         //PJFET
  86.  
  87.                                         TransType = 0x08;
  88.                                     }
  89.  
  90.                                     else
  91.                                     {
  92.                                         //Malfunctioning
  93.                                         TransType = 0x02;
  94.                                     }
  95.                                   } //p_Type or malfunctioning Else
  96.                                
  97.                               }  //Transistor no funciona o JFET  "IF"
  98.                              
  99.                               else    //Tipo P
  100.                               {
  101.                                  
  102.                                 Voltaje_Pin2 = 0;
  103.                                 __delay_ms(3000);
  104.                                 vd1 = ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VG1);
  105.                                 __delay_ms(5);
  106.                                 vd2 = ADC_Read10bit (ADC_CHANNEL_ID_TRANS_VG2);
  107.                                
  108.                                 if((vd2 - vd1) >= 614 ) // Si verdadero, transistor PMOS, si Falso,  transistor PBJT
  109.                                 {
  110.                                     TransType = 0x04;  //PMOS
  111.                                    
  112.                                 }
  113.                                 else
  114.                                 {
  115.                                     TransType = 0x06;   // PBJT
  116.                                    
  117.                                 }
  118.                                
  119.                                
  120.                               } // Tipo P "else"
  121.                              
  122.                           }
  123.                          
  124.                           else   // N o malFunciona
  125.                           {
  126.                              
  127.                               Voltaje_Pin2 = Encendido_5v;    //dar 5V al pin2
  128.                              
  129.                               __delay_ms(3000);
  130.                              
  131.                               if(ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VS) > 205)  //Si verdadero, Tipo N, Falso -> MalFuncionamiento
  132.                               {
  133.                                 vd1 = ADC_Read10bit(ADC_CHANNEL_ID_TRANS_VG1);
  134.                                __delay_us(5);
  135.                                 vd2 = ADC_Read10bit (ADC_CHANNEL_ID_TRANS_VG2);
  136.                                
  137.                                 if((vd1 - vd2) <= 35 || vd1 == vd2) // Si verdadero, transistor N-BJT, si Falso,  transistor NMOS
  138.                                 {
  139.                                     TransType = 0x05;   // NMOS
  140.                                     Voltaje_Pin2 = 0;
  141.                                 }
  142.                                 else
  143.                                 {
  144.                                     TransType = 0x03;     // NBJT
  145.                                     Voltaje_Pin2 = 0;
  146.                                 }
  147.                               }
  148.                              
  149.                               else
  150.                               {
  151.                                
  152.                                   TransType = 0x02;  // Mal Funcionamiento
  153.                                   Voltaje_Pin2 = 0;
  154.                                
  155.                               }
  156.                              
  157.                              
  158.                              
  159.                              
  160.                              
  161.                           }
  162.                          
  163.                          
  164.                                                  
  165.                         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.
  166.                         ToSendDataBuffer[1] = TransType; //LSB
  167.                        
  168.  
  169.                         //Prepare the USB module to send the data packet to the host
  170.                         USBInHandle = HIDTxPacket(CUSTOM_DEVICE_HID_EP, (uint8_t*)&ToSendDataBuffer[0],64);
  171.                     }
  172.                            
  173.             }
  174.                 break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement