hello,
I am using a raspberry pi to read the period from the ADE7753 (register 0x27) in python. I am having trouble, i get an output but do not know how to convert it to the right frequency. any help would be appreciated. below is my code and the output:
---code---
import time
import spidev
import sys
spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz = 62500
spi.mode = 0b01
if len(sys.argv) > 1:
register = int(sys.argv[1], 16)
else:
register = 0x27
result = spi.xfer2([register, 0x00, 0x00, 0x00])[1:]
print "reading register {}:".format(hex(register))
print [bin(x) for x in result]
print [hex(x) for x in result]
print result[0]
print result[1]
print result[2]
period = 256*result[1]+result[2]
period = period * 1.0
print "period" ,period
freq = 1 / period
print "freqeuncy", freq
print "done"
spi.close()
---result---
reading register 0x27:
['0b11101', '0b110000', '0b0']
['0x1d', '0x30', '0x0']
29
48
0
period 12288.0
freqeuncy 8.13802083333e-05
done