Maximum number of PWM or how to get more

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.
clack
Posts: 20
Joined: Sat May 03, 2014 11:09 am

Re: Maximum number of PWM or how to get more

Post by clack » Tue Feb 03, 2015 11:51 am

Hey, I have written this function, is this what you were suggesting? am I going to run into any difficulties with this? its quite cool ive never used a microcontroller with a DAC.

Code: Select all

def pwmDAC(val,freq,pin):
	buf = bytearray(255) 
	dac = DAC(pin) 
	for i in range(len(buf)):
		if i <= val:
			buf[i] = 255
		else:
			buf[i] = 0
	dac.write_timed(buf,freq * len(buf), mode=DAC.CIRCULAR)	

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Maximum number of PWM or how to get more

Post by dhylands » Tue Feb 03, 2015 3:27 pm

That looks right. The real test is whether it looks right on a logic analyzer.

User avatar
polygontwist
Posts: 36
Joined: Sat Jun 28, 2014 4:54 pm
Location: Germany, Rostock
Contact:

Re: Maximum number of PWM or how to get more

Post by polygontwist » Tue Feb 03, 2015 5:36 pm

"to get more"
with the TLC5940NT 16 x PWM-Cannel
My Projekt on http://fritzing.org/projects/tlc5940nt (wireing)
Source for Arduino: http://playground.arduino.cc/learning/TLC5940

clack
Posts: 20
Joined: Sat May 03, 2014 11:09 am

Re: Maximum number of PWM or how to get more

Post by clack » Thu Feb 05, 2015 3:23 pm

thanks, it works well ( after a bit of messing around making a proper function ). I can call the same frequency on all pins except the blue LED as it is fixed? will show code when i get it on github!

I am driving the LED's with motor drivers as it was economical plus I can configure them to run common anode or cathode LED's

Image

When I unplug the USB ( and it is connected to 5v on Vin ) though it is does not boot? , am I connecting to a pin that stops it booting up? or is there somthing I should be connecting or programming to make main.py run?

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: Maximum number of PWM or how to get more

Post by kfricke » Thu Feb 05, 2015 3:49 pm

Cool stuff but how about something like WS2812 RGB LEDs? Is far simpler imho!

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: Maximum number of PWM or how to get more

Post by kfricke » Thu Feb 05, 2015 3:52 pm

Oh, and btw: don't drink that much coke ;-)

clack
Posts: 20
Joined: Sat May 03, 2014 11:09 am

Re: Maximum number of PWM or how to get more

Post by clack » Thu Feb 05, 2015 4:11 pm

kfricke wrote:Cool stuff but how about something like WS2812 RGB LEDs? Is far simpler imho!
It is and I use them, but in this context it will not work as it is for an artist who makes sounds with the PWM signals, it is vital I can get audio from the R G and B plus I need to be able to set the pitch of the pwm. Each channel drives a short piece of LED strip. Also the WS2812 is not good over long lengths. Ideally I would make each led with a custom serial ( midi or DMX ) receiver but this is much simpler practically.

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: Maximum number of PWM or how to get more

Post by kfricke » Thu Feb 05, 2015 4:28 pm

Ok, the context makes it reasonable. Before i did assume all you want to do is light 8 RGB LEDs.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Maximum number of PWM or how to get more

Post by dhylands » Thu Feb 05, 2015 6:49 pm

clack wrote: When I unplug the USB ( and it is connected to 5v on Vin ) though it is does not boot? , am I connecting to a pin that stops it booting up? or is there somthing I should be connecting or programming to make main.py run?
There are a bunch of pins that need to be in a particular state when booting, since the chip supports bootloading over a number of interfaces.
See Page 13 and start reading the section starting at page 47 of this document: http://www.st.com/web/en/resource/techn ... 167594.pdf

There is also a note in the top right corner of the schematic: https://github.com/micropython/pyboard/ ... YBv10b.pdf

You can also use the function: pyb.repl_uart to get a REPL on one of the UARTS (you would put this in your boot.py). So you could try booting the pyboard in isloation and see if there are any errors shown, and gradually add LEDs until it fails.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Maximum number of PWM or how to get more

Post by Damien » Fri Feb 06, 2015 1:04 am

clack wrote: I can call the same frequency on all pins except the blue LED as it is fixed?
I can change the timer code so it allows you to control timer 3. If you don't need usb then it's not a problem changing the frequency of this timer. If you don't want to wait for a code change you can access the timer registers using the stm module.
When I unplug the USB ( and it is connected to 5v on Vin ) though it is does not boot?
Do the pyboard leds light up in any way? Did you check voltage level on VIN and 3V3? Did you try pressing RST button? :) If it boots via usb then is should boot fine without usb.

Post Reply