Vini
-
Posts
2 -
Joined
-
Last visited
Content Type
Forums
Store
Crowdfunding
Applications
Events
Raffles
Community Map
Posts posted by Vini
-
-
Hello,
Interesting topic. I played with a pcDuino3 and the pin LRADC0 and 1 are mapped to A0 and A1. There are other ADCs mapped to the A2 to A5 pins (XP_TP, XN_TP, YP_TP and YN_TP), but I did not play with them yet.
I slightly changed your code to port it to Python 3:
#!/usr/bin/env python3 from time import sleep import os import mmap # Check CPU a20 = "Allwinner sun7i (A20)" in open("/proc/cpuinfo", "r").read() if not a20: exit("This program only works on Allwinner sun7i (A20) cpus.") # LRADC register base address = 0x01C22800 (cfr. A20 manual page 193) LRADC_BASE_ADDRESS = 0x01C22800 """ # LRADC Control Register LRADC_CTRL = LRADC_BASE_ADDRESS + 0x00 # LRADC Interrupt Control Register LRADC_INTC = LRADC_BASE_ADDRESS + 0x04 # LRADC Interrupt Status Register LRADC_INTS = LRADC_BASE_ADDRESS + 0x08 """ # LRADC Data Register 0 LRADC_DATA0 = LRADC_BASE_ADDRESS + 0x0c # LRADC Data Register 1 LRADC_DATA1 = LRADC_BASE_ADDRESS + 0x10 MAP_MASK = mmap.PAGESIZE - 1 try: mem = mmap.mmap(os.open("/dev/mem", os.O_RDWR | os.O_SYNC), mmap.PAGESIZE, mmap.MAP_SHARED, offset=LRADC_BASE_ADDRESS & ~MAP_MASK) # The correct way to do it is to add the 4 bytes together as follow : mem.seek(LRADC_BASE_ADDRESS & MAP_MASK) REGISTERS_CONFIG = bytearray(( # 0111 1001 is for bit 7 to 0 of the first byte (0x01C22800). # Bit 7 / # Bit 6 is LRADC sample hold # Bit 5:4 '11' are for reference voltage to use, where: # 00 ≈ 1.9 V, 01 ≈ 1.8V, 10 ≈ 1.7V, and 11 ≈ 1.6V # Bit 3:2 is the sampling rate, where: # 00 = 250 Hz, 01 = 125 Hz, 10 = 62.5 Hz, and 11 = 32.25 Hz. # Bit 1 / # Bit 0 is to activate the LRADC. 0b01000001, # 0010 0000 is for bit 7 to 0 of the 2nd byte (0x01C22801). # Bit 13 and 12 '10' are for continuous mode. # 1100 0000 is for bit 7 to 0 of the 3rd byte (0x01C22802). 0b00100000, # Bit 23 and 22 '11' are to enable both LRADC0 and LRADC1. 0b11000000, # 1 = 0000 0001 is default value. 0b00000001 ) ) mem.write(REGISTERS_CONFIG) mem.seek(LRADC_BASE_ADDRESS & MAP_MASK) check_register_config = mem.read(4) == REGISTERS_CONFIG print(f"Check LRADC config: {'ok' if check_register_config else 'failed'}") while True: mem.seek(LRADC_DATA0 & MAP_MASK) # should be between 0 and 63 (6 bits) print(f"LRADC0 (A0): {mem.read_byte()}") mem.seek(LRADC_DATA1 & MAP_MASK) # should be between 0 and 63 (6 bits) print(f"LRADC1 (A1): {mem.read_byte()}") sleep(0.2) finally: mem.close()
Reading A20 LRADC0 and LRADC1 values
in Beginners
Posted
I have now had a look at the other ADC. It is quite harder to configure since it has 3 functionalities (CPU temperature sensor, or resistive Touch Panel controller, or single-ended ADC), but I was able to figure it out enough to use it. If you use the ADC, you must interrupt the other functionalities or build a driver to cope with them (temperature sensor and Touch Panel/ADC). Note that I am using Python 3 (because I'm familiar with it) to configure the ADC and read the ADC's values, which is probably very slow. A C/C++ program would be way faster in that regard (e.g., the code used to acquire the CPU temperature: https://github.com/armbian/build/blob/e9fb9542c763a88c8e689c3a14fc135bccea55f1/packages/bsp/sunxi-temp/sunxi_tp_temp.c).
Here is the code for those that it could interest.