disco_dave
New Member
Hi there
I am using a PIC 16F877A as an A/D converter to allow me to get two analog voltages in from a sensor into a PC. The sensor I am using measures the angle of tilt on two axis's. The sensor has been tested and is working correctly. The voltage received out from the sensor is as follows: (There are two output voltages one for each axis)
If the sensor is flat then 2.5v is outputted.
If the sensor moves towards 90 degrees in one direction a max of 3.5v is measured at 90 degrees.
If the sensor moves in the other direction by 90 degrees a minimum of 1.5v is measured at 90 degrees.
It outputs 2.5v when flat and then changes around this value to indicate what angle it is measuring.
I have set the PIC up to convert one of these voltages and output the data then hand shake out this data. Then to measure the other voltage on another of the A/D inputs and convert this to and handshake this out to the PC. The program then loops around continuously. The data is hand shake out of the PIC and into the PC.
The A/D conversion process works fine when the range is between 2.5v and 3.5v. (This is a "negative angle" once translated in my software on the PC)
However when the sensor tilts in the opposite direction (range = 1.5v to 2.5v) the values received from the PIC's A/D conversion jump in large steps. The values of the angles after the PC has computed the angles are as follows - 0 degrees, 7 degrees, 14 degrees, 28 degrees and about 56 degrees. The values listed do occur roughly when the angle occurs, in between these values the previous angle is held on the outputs. ie the ouput is step like. Because the sensor gives a linear response it would mean that the A/D value also increases in these large values which I have checked to be true.
The PIC does no work on the values it receives from the A/D process this is done in the PC. I am sure that this is something to do with the PIC as the raw data received into the PC changes is these large steps. ie before any work is done on the data to get the angle from the digital value received in. I have tried using another 16F877A PIC but still got this problem. I checked the sensor and tried changing it for another of the same type. I therefore am sure that the problem lies with the code in the PIC. I have read and reread many times the datasheet and cannot see where the problem is. As you can tell the values received in error double in value each time. I am using the full 10 bits of A/D in my design. I have also attached the code I am using. The sensor I am using is ADXL203 from Analog Devices.
I guess that the A/D is perhaps loosing one of the bits somewhere which could be why the value is doubling each time.
I am using a PIC 16F877A as an A/D converter to allow me to get two analog voltages in from a sensor into a PC. The sensor I am using measures the angle of tilt on two axis's. The sensor has been tested and is working correctly. The voltage received out from the sensor is as follows: (There are two output voltages one for each axis)
If the sensor is flat then 2.5v is outputted.
If the sensor moves towards 90 degrees in one direction a max of 3.5v is measured at 90 degrees.
If the sensor moves in the other direction by 90 degrees a minimum of 1.5v is measured at 90 degrees.
It outputs 2.5v when flat and then changes around this value to indicate what angle it is measuring.
I have set the PIC up to convert one of these voltages and output the data then hand shake out this data. Then to measure the other voltage on another of the A/D inputs and convert this to and handshake this out to the PC. The program then loops around continuously. The data is hand shake out of the PIC and into the PC.
The A/D conversion process works fine when the range is between 2.5v and 3.5v. (This is a "negative angle" once translated in my software on the PC)
However when the sensor tilts in the opposite direction (range = 1.5v to 2.5v) the values received from the PIC's A/D conversion jump in large steps. The values of the angles after the PC has computed the angles are as follows - 0 degrees, 7 degrees, 14 degrees, 28 degrees and about 56 degrees. The values listed do occur roughly when the angle occurs, in between these values the previous angle is held on the outputs. ie the ouput is step like. Because the sensor gives a linear response it would mean that the A/D value also increases in these large values which I have checked to be true.
The PIC does no work on the values it receives from the A/D process this is done in the PC. I am sure that this is something to do with the PIC as the raw data received into the PC changes is these large steps. ie before any work is done on the data to get the angle from the digital value received in. I have tried using another 16F877A PIC but still got this problem. I checked the sensor and tried changing it for another of the same type. I therefore am sure that the problem lies with the code in the PIC. I have read and reread many times the datasheet and cannot see where the problem is. As you can tell the values received in error double in value each time. I am using the full 10 bits of A/D in my design. I have also attached the code I am using. The sensor I am using is ADXL203 from Analog Devices.
I guess that the A/D is perhaps loosing one of the bits somewhere which could be why the value is doubling each time.