Data type conversion with adc

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Le fond du garage
Posts: 9
Joined: Mon Dec 21, 2020 6:38 pm

Re: Data type conversion with adc

Post by Le fond du garage » Sat Feb 06, 2021 9:41 am

an example for schedule

Code: Select all

import schedule
import time

def job():
    print("I'm working...")

schedule.every(10).minutes.do(job)
schedule.every().hour.do(job)
schedule.every().day.at("10:30").do(job)
schedule.every().monday.do(job)
schedule.every().wednesday.at("13:15").do(job)

while True:
    schedule.run_pending()
    time.sleep(1)
and do bind with irq use this

Code: Select all

def hard_irq(arg):
    micropython.schudule(soft_irq, arg)
    
    

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

schedule library

Post by pythoncoder » Sun Feb 07, 2021 8:06 am

I produced a "micro" version of schedule using uasyncio here.
Peter Hinch
Index to my micropython libraries.

javiojeda
Posts: 4
Joined: Wed Feb 03, 2021 2:16 pm

Re: Data type conversion with adc

Post by javiojeda » Fri Feb 12, 2021 12:43 pm

Thank you for your advices.

I found an "off road" solution.

Code: Select all


# main.py -- put your code here!

from pyb import Timer, Pin, ADC, DAC

tim = Timer(1, freq=1000) # Définition du timer 1 à la fréquence 1000Hz

tick = 0
echeance = 1

def correction():
    # ADC conversion
    # Control equations
    # DAC conversion
    
def gestion_echantillon(timer):
    global tick
    tick += 1
    
# Fonction qui se déclenche à chaque fois que le timer finit sa boucle
tim.callback(gestion_echantillon)

while True:
    
    if tick == echeance:
        echeance +=1
        correction()
        
    	if tick == 2**24: # Set to init position
        	echeance = 1
       		tick = 0
This method works experimentally. Between two output, I measured 1ms (+- few micro-seconds).

I think it is not the best micropythonic way of coding but it works for me.

Post Reply