I'm going to PWM control a servo motor using the RevPi MIO's digital output.
I have a rudimentary question about the RevPi MIO setup, as it was not included in the tutorial.
In the "Value Editor" of PiCtory, the PWM frequency is set to FpwmOut_12, 3, 4.
Should the value set to FpwmOut be the value of x in the formula f=(2*fp)/(1000*(x+1))?
For example, if I want 200Hz in FpwmOut_12, is it correct to set x=299 or input 200(Hz)?
Thank you in advance.
PiCtory settings for MIO pwm output
Re: PiCtory settings for MIO pwm output
Hi Makoto G,
okay lets have a look at the tutorial which I found here:
https://revolutionpi.com/tutorials/digi ... urieren-2/
So here is the formula to set up the PWM well it's software for those who really love working with formulas ... damm I should have done that algebra homework during studying ...
To round it up a MIO PWM 200Hz with 50% duty cycle should be configured using these values:
okay lets have a look at the tutorial which I found here:
https://revolutionpi.com/tutorials/digi ... urieren-2/
So here is the formula to set up the PWM well it's software for those who really love working with formulas ... damm I should have done that algebra homework during studying ...
So if you divide my result by 1000 it equals your value! I hope that this helps for the moment.The possible frequencies follow the formula f=(2*fp)/(1000*(x+1)). fp is 30 MHz for GPO1&2 and 60 MHz for GPO3&4.
This results in maximum frequencies of 60 kHz (GPO1&2) and 120 kHz (GPO3&4). When x_max=65535, minimum frequencie60s of 2 Hz (GPO1&2) and 1 Hz (GPO3&4) are the result.
To round it up a MIO PWM 200Hz with 50% duty cycle should be configured using these values:
- IO_Mode_1 = 5 [Output-Pwm]
- FpwmOut_12 = [299]
- PWM Dutycycle_1 = 500 [50%]
Re: PiCtory settings for MIO pwm output
Thank you for your response.
I configured PiCtory as follows
-IO_Mode_1 = pwmOut
-FpwmOut_12 = 299 [200Hz].
-PWM Dutycycle_1 = 304 [30.4%]
I have an another question.
Maybe I should move it to the RevPiModIO board, but since it's a continuing question, I'll put it here.
I want to use RevPiModIO2 to control the Duty ratio of DigitalOutput_1 of RevPi MIO for servo motor control.
I referred to some threads, but there was no case of MIO module, so I don't know if the python code I wrote is correct.
Since I don't have the equipment to check the PWM waveforms directly, can you please take a look at my python code to see if there are any problems with it?
The python code is given below.
Thank you in advance.
-----------------------------------------------------------------------------------------------------
import revpimodio2
import time
rpi = revpimodio2.RevPiModIO(autorefresh=True)
rpi.io.PwmDutycycle_1.value = int(496)#49.6% duty cycle
rpi.io.DigitalOutput_1.value = int(1)
time.sleep(15)
rpi.io.PwmDutycycle_1.value = int(112)#11.2% duty cycle
rpi.io.DigitalOutput_1.value = int(1)
time.sleep(15)
rpi.io.DigitalOutput_1.value = int(0)
-----------------------------------------------------------------------------------------------------
I configured PiCtory as follows
-IO_Mode_1 = pwmOut
-FpwmOut_12 = 299 [200Hz].
-PWM Dutycycle_1 = 304 [30.4%]
I have an another question.
Maybe I should move it to the RevPiModIO board, but since it's a continuing question, I'll put it here.
I want to use RevPiModIO2 to control the Duty ratio of DigitalOutput_1 of RevPi MIO for servo motor control.
I referred to some threads, but there was no case of MIO module, so I don't know if the python code I wrote is correct.
Since I don't have the equipment to check the PWM waveforms directly, can you please take a look at my python code to see if there are any problems with it?
The python code is given below.
Thank you in advance.
-----------------------------------------------------------------------------------------------------
import revpimodio2
import time
rpi = revpimodio2.RevPiModIO(autorefresh=True)
rpi.io.PwmDutycycle_1.value = int(496)#49.6% duty cycle
rpi.io.DigitalOutput_1.value = int(1)
time.sleep(15)
rpi.io.PwmDutycycle_1.value = int(112)#11.2% duty cycle
rpi.io.DigitalOutput_1.value = int(1)
time.sleep(15)
rpi.io.DigitalOutput_1.value = int(0)
-----------------------------------------------------------------------------------------------------
Re: PiCtory settings for MIO pwm output
Hi Makoto,
I have looked at your code. I have made some changes, but I don't know if the code does what you want to test correctly.
In general, you need to consider whether you want a cyclic (classic in automation) or an event-based program. The simplest is cyclic:
I have looked at your code. I have made some changes, but I don't know if the code does what you want to test correctly.
In general, you need to consider whether you want a cyclic (classic in automation) or an event-based program. The simplest is cyclic:
Code: Select all
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import revpimodio2
def main(ct: revpimodio2.Cycletools) -> None:
ct.io.PwmDutycycle_1.value = 496
ct.io.DigitalOutput_1.value = True
ct.io.PwmDutycycle_1.value = 112
ct.io.DigitalOutput_1.value = True
ct.io.DigitalOutput_1.value = False
# Start the cycle program, which will run every 50 milliseconds
revpimodio2.run_plc(main)
- RevPiModIO
- KUNBUS
- Posts: 327
- Joined: 20 Jan 2017, 08:44
- Contact:
Re: PiCtory settings for MIO pwm output
Hi Makoto!
In general your Python code is okay. Just add the rpi.exit() at the end to be sure all IOs are set as you want - Especially the .value = int(0)
So This program will set the Dudycycle to 496, set the DigitalOutput_1 to True, waits 15 seconds, set DutyCycle to 112, keep DigitalOutput_1 at True, waits 15 seconds, set DigitalOutput_1 to False, exit program.
Sven
In general your Python code is okay. Just add the rpi.exit() at the end to be sure all IOs are set as you want - Especially the .value = int(0)
Code: Select all
import revpimodio2
import time
rpi = revpimodio2.RevPiModIO(autorefresh=True)
rpi.io.PwmDutycycle_1.value = int(496) #49.6% duty cycle
rpi.io.DigitalOutput_1.value = True
time.sleep(15)
rpi.io.PwmDutycycle_1.value = int(112) #11.2% duty cycle
rpi.io.DigitalOutput_1.value = True
time.sleep(15)
rpi.io.DigitalOutput_1.value = False
# Make sure to write all output values before program ends
rpi.exit()
Sven
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!