Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

complementary PWM signals in Python

Status
Not open for further replies.

borna.barisic

Newbie
Joined
Aug 8, 2014
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,343
Hello, my name is Borna Barisic and i am from Croatia. If you don't mind i have a question about Raspberry Pi's PWM.

I have build a DC step down Buck converter with half H bridge and i am using IR2113 driver.
Schematics for that circle shown in (DC Buck schematic attachment).

I have watched PWM lessons for Raspberry Pi and thanks to them i managed to make a program in Python to generate two PWM signals from Raspberry Pi, but i cant make those PWM signal out of phase.

If i am right, for example, if i put frequency f = 1 Hz that means that time of whole period is T = 1 sec, time half of period is t=0.5 sec. In python program i used a time.sleep(t) function in while loop so when one of PWM signal (in this case buck_PWM_H,representing high signal) already starts, second PWM (buck_PWM_L,representing low sigal) waits for half a period and then starts. Then i would get two signals that would be out of phase (when "H" is 1 "L" is 0).
Well to be honest it did not worked that way.
Just to say regardless of time or frequency those two PWM signals were always in phase.

After that said i was wondering if you could help me by telling me how to generate (with Python code) two complementary PWM signals. I hope that i made myself clear enough for you to understand me. I am sorry for my grammar mistakes.


I will show you my Python code.


Code Python - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import RPi.GPIO as GPIO 
import time 
 
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)[/B]
GPIO.setup(12,GPIO.OUT)
 
f = input ("Frequency: ")                              /here im setting up a frequency of PWM
T = 1/f                                         /i need to find time of a period 
t = T/2                                         /to make signals out of phase i need half period to delay other pwm (at least i thought)
 
buck_PWM_H = GPIO.PWM(12,f)                     /setting pin 12 for output PWM High side 
buck_PWM_L = GPIO.PWM(11,f)                     /setting pin 11 for output PWM Low side (this signal have to be delayed for half a period)
 
buck_PWM_H.start(0)                                     /i have put zero because i want PWM to start when i input variable D
buck_PWM_L.start(0)                                 /same here 
 
while(1):
    D = input("Duty cycle[%]: ")        /In this while loop i wanted to start pwm signals when variable D is known 
    buck_PWM_H.ChangeDutyCycle(D)   /and i put a time.sleep function because i thought it would make two signals 
    time.sleep(t)                       /(buck_PWM_H and buck_PWM_L) out of phase, but i was wrong.
    buck_PWM_L.ChangeDutyCycle(D)       /In case D is 0 then PWM signals are shut down
    if D == 0:
        break
 
buck_PWM_H.stop()
buck_PWM_L.stop()
GPIO.cleanup()



Best regards from Croatia and keep up the good job.
 

Attachments

  • DC Buck schematic attachment.jpg
    DC Buck schematic attachment.jpg
    79.7 KB · Views: 82
Last edited by a moderator:

Hi,

i doubt a Python software PWM with delay() will ever run satisfactory.

Almost any microcontroller/processor has built in PWM, or at least a timer interrupt hardware.


Klaus
 

Thank you for your advice, I am familiar with PWM in PIC microcontrollers, but i was hoping to make 2 complementary PWM signals in python.

Best regards

Borna
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top