Quantcast
Channel: Cypress Semiconductor - PSoC 4 Architecture
Viewing all articles
Browse latest Browse all 796

Flex Sensor

$
0
0

Hello.
I am currently working on interfacing of flex sensor with the PSOC 4200 but I can't get the analog values(float) to print on the terminal.

Here's the code:

#include <project.h>
#include <stdio.h>
int main()
{

float R_DIV = 47500.0; //47K Ohm approx
float VCC=5.0;
float STRAIGHT_RESISTANCE = 37300.0;
float BEND_RESISTANCE = 90000.0;

uint8 flexADC;
float32 flexV, flexR;
char str[10];
float angle=0.0;

UART_Start();
ADC_Start();

CyGlobalIntEnable;

for(;;)
{
ADC_StartConvert();
ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
flexADC = ADC_GetResult16(0);
flexV = ADC_CountsTo_Volts(0,flexADC);
flexR = R_DIV * (VCC / flexV - 1.0); 
UART_PutString("Resistance in Ohms");
sprintf(str,"%.2f  ",flexR);
UART_PutString("%s\n",str);
angle= (flexR-STRAIGHT_RESISTANCE)*(90.0-0.0)/(BEND_RESISTANCE-STRAIGHT_RESISTANCE)+0.0;
UART_PutString("Bend angle in degrees");
sprintf(str,"%.2f  ",angle);
UART_PutString("%s\n",str);
CyDelay(2000);

}

}


Viewing all articles
Browse latest Browse all 796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>