I write a simple project to test the function. And I attached the test project in attachment.
After review your codes, I think you should wait for the ending of the convert of ADC, then start to read the result.
while(0u != ADC_IsEndConversion(CY_SAR_RETURN_STATUS))
I don't use the continuous mode, use single mode.
Thank you for your response, Lingling. I can't seem to open this project file. Can you recommend the version of IDE you used to develop this? I'm also having trouble referencing the CY_SAR_RETURN_STATUS definition.
I am currently using PSoC Creator 4.2 with the CY8C4127LQI-BL453 chip.
As my understanding, it could be use this way to test the VDD:
But I can't understand why do you want to test the Analog High Z? In addition, I think it is unreasonable to say that the Analog high z is equal to vdd/2.
Why don't you use the voltage divider to test the voltage?
1 of 1 people found this helpful
The resistive pull up/down drive mode does not imply a Vdd/2 potential divider at the pin. It only means that both logic low and logic high are resistive (not strong). Since only one logic can be driven at any point of time(either logic high or low), only one resistor appears at any point of time, and the other resistor is floating. During logic HIGH is, only the upper PMOS is ON and the lower NMOS is OFF in the pin driver. Similarly, during logic LOW, the PMOS is OFF and NMOS is ON.
However, your requirement (of detecting a logic HIGH/LOW/Hi-Z) can be met by dynamically changing the pin output drive(logic HIGH/LOW) and reading the pin status(or ADC value) twice.
If the pin is left Hi-Z externally, then the pin status(or ADC value) will change based on the logic driven from inside PSoC.
If the pin is at logic high/low externally, then the pin status(or ADC value) will stay the same(as the externally driven logic) irrespective of whether logic high or low is driven from inside PSoC(because the external strong drive overrides the internal resistive drive). Thereby the 3 states (logic HIGH/LOW/Hi-Z) of the pin can be detected.
Since only logic low/high has to be read for this technique, reading Pin status is sufficient and ADC value is not necessary.
Configure the pin as shown in image:
- Keep the drive mode as resistive pull up/down.
- Check both digital input and output check boxes.
- Uncheck the HW connection, so that pin drive logic can be dynamically changed in firmware.
- First drive the pin logic High (using Pin_Write()), and read the pin status(using Pin_Read()).
- Then drive the pin logic Low and read the pin again.
If the pin status reads high both times, it implies pin is at logic HIGH externally.
If the pin status reads low both times, it implies pin is at logic LOW externally.
If the pin status reads high when written high and low when written low, it implies pin is at Hi-Z externally.