Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Shahariar
Published © LGPL

PSoC : Auto Ranging Ohms Meter

Utilizing IDAC to inject current through unknown Resistor & measuring Voltage across it with 12 bit ADC finally Ohms Law to find Resistance.

BeginnerFull instructions provided3 hours3,649
PSoC : Auto Ranging Ohms Meter

Things used in this project

Hardware components

PSoC 4 Prototyping Kit
Cypress PSoC 4 Prototyping Kit
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Hand tools and fabrication machines

Cypress PSOC CReator 3.0

Story

Read more

Custom parts and enclosures

PSoC Project File

PSoC Creator Files

Schematics

PSoC Intern Sch

Inside PSoC Creator

Code

Main C

C/C++
The Auto Ranging part and Display Control
#include <project.h>

int current =0;
int voltage =0;
int resistance=0;
char str_resistance[5];
unsigned int IDAC_Val=0xff;
//Prototype the ISR Handler

CY_ISR_PROTO(RebootISR_Handler);

// Implement ISR
CY_ISR(RebootISR_Handler)
{
    // Enters Bootloader here and shows message
  LCD_Char_ClearDisplay();
    CyGlobalIntDisable;
    LCD_Char_PrintString(" Restarting... ");
    CyDelay(500);
    LCD_Char_ClearDisplay();
    LCD_Char_PrintString("READY to PROGRAM");
    LCD_Char_Position (1,0);
    LCD_Char_PrintString("< Upload Code > ");
    
    // Restart and enter bootloader 
    Bootloadable_Load();

    
}



int main()
{   int c=4095;
    LCD_Char_Start();
  // LCD_Char_LoadCustomFonts();
   
    Reboot_Timer_Start();
    ADC_Start();
    IDAC_Inject_Start();
    

    
    // Enable ISR and clear pending, if any !
    RebootISR_ClearPending();
    RebootISR_StartEx( RebootISR_Handler );
    CyGlobalIntEnable;
 
  
    IDAC_Val=0xff;
     IDAC_Inject_SetValue(IDAC_Val);
    ADC_StartConvert();
    
    LCD_Char_PrintString("PSoC Auto Range");
    LCD_Char_Position(1,0);
    LCD_Char_PrintString("  Ohms Meter  ");
    CyDelay(2000);
    LCD_Char_ClearDisplay();
 
  for(;;)
  {
    IDAC_Val=0xff;
    c=4095;
   
   
    // the following while loop does the AUTO RANGING
while((IDAC_Val>0)&&(c>=4000))
{
    
    IDAC_Val=IDAC_Val-0x01;
    IDAC_Inject_SetValue(IDAC_Val);
    CyDelay(3);
    while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
    c=ADC_GetResult16(0);
   // LCD_Char_ClearDisplay();
    CyDelay(2);
     
   
}
   

if (c<4000)
{
    IDAC_Inject_SetValue(IDAC_Val);
    CyDelay(1);
    // while( ADC_IsEndConversion(ADC_RETURN_STATUS)){}
    //  c=ADC_GetResult16(0);
    current= IDAC_Val*1.2;    // in uAmp
    voltage=c*1000/2;  // in uVolt

     resistance= voltage/current;
    
  //  sprintf(str_resistance,"%f",resistance);
    LCD_Char_ClearDisplay();
    LCD_Char_PrintString("   Resistance");
    LCD_Char_Position(1,3);
  //  LCD_Char_PrintString("in Ohms= ");
    if (resistance<950000)
    {LCD_Char_PrintU32Number(resistance);
    
     LCD_Char_PrintString(" ");
    
     LCD_Char_PutChar(LCD_Char_CUSTOM_0);
    }
    else 
    {
        LCD_Char_ClearDisplay();
        LCD_Char_PrintString("Connect Resistor");
      
    }
     
    CyDelay(300);
    
  
    

  }
 

}


// Num to String
}

Credits

Shahariar

Shahariar

74 projects • 266 followers
"What Kills a 'Great life' is a 'Good Life', which is Living a Life Inside While Loop"

Comments