frame

Setting ADC sampling frequency doesn't work

Hello,

I need to set my sampling frequency of the ADC in Particle Photon and I have written the following code:
import streams
import adc
import timers

sampling_freq = 48000
sampling_time = 0.05 # [s] sampling time
inputAnalog = A0 # define the analog pin for reading the value
samples_len = int(sampling_freq*sampling_time)

# reload the driver with a custom sampling frequency
adc.done(ADC0)
adc.init(ADC0, samples_per_second=sampling_freq)

streams.serial()

pinMode(inputAnalog,INPUT_ANALOG)

pinMode(LED0,OUTPUT)

for i in range(2):
sleep(1000) # wait for a second
digitalWrite(LED0, HIGH) # turn the LED ON by setting the voltage HIGH
sleep(1000) # wait for a second
digitalWrite(LED0, LOW) # turn the LED OFF by setting the voltage LOW

print("\rEntering loop")
timer = timers.timer()
timer.start()

while True:

timer.reset()
samples = adc.read(inputAnalog, samples_len) # get Raw values (0-4095)
t1 = timer.get()
samples = None
print("\r\tAcquired samples! t=",t1,"ms\r\t")
sleep(1000)
but the printed value of t1 is 2 ms, instead of the expected 50 ms, so it seems like the sampling frequency is around 1.2 MHz, which is nowhere near what I need.. As far as I can see I've done everything according to the docs. Am I missing something or is there some trick to this?
Thanks in advance for the help.










Comments

  • edited July 7
    Hi findal,

    Thanks for reporting this issue; we succeed to replicate the problem and we are investigating and working to fix it.

    Stay tuned for updates :)
    Matteo Cipriani
    Zerynth Support Team
  • Hi findal,

    Zerynth r2.0.9 is out.
    Now ADC sampling frequency can be properly set.
    We tested your script in our Particle Photon and all works fine.

    :)
    Matteo Cipriani
    Zerynth Support Team
  • findal Member
    Hello,

    Frequency setting works for me as well! Thanks for the assistance.

    Regards
Sign In or Register to comment.

ZERYNTH Community

@ 2016 Zerynth.com, all rights reserved.