elcojacobs / shiftpwm Goto Github PK
View Code? Open in Web Editor NEWArduino Library for software PWM with shift registers
License: MIT License
Arduino Library for software PWM with shift registers
License: MIT License
Hello,
I have spent some time making this work with teensy 3.0, but my efforts were mostly specific to my application, so I pretty much implemented only what I needed.
There are however some pointers I can give you from what I found.
It looks to me like what you do with pins_arduino_compile_time.h
is already accomplished with the teensy 3.0, but I am not sure, so in my implementation I simply used digitalWrite for the latch pin. The clock speed is so much higher on the teensy 3.0 I don't think it matters much.
The most important part is of course the interrupt handler, which is mostly identical other than the add_one_pin_to_byte
macro, which is as follows.
#define add_one_pin_to_byte(sendInt, thres, ptr) { \
unsigned char val = *ptr; \
asm volatile("cmp %0, %1" :: "r" (thres), "r" (val) :); \
asm volatile("rrx %0, %1" : "=r" (sendInt) : "r" (sendInt) :); \
}
the ARM RRX function works on a 32bit register, so you must pass it an unsigned int for sendInt, and then shift it right 24bits after you add all the bits to send.
for the interrupt timer you use IntervalTimer
m_timer = new IntervalTimer();
period = 1000000.0 / (ledFrequency * maxBrightness);
m_timer.begin(myHandlerFunction, period);
with 3 registers at 100hz pwm frequency with 255 maximum brightness, these are my results.
Load of interrupt: 0.3640691
Clock cycles per interrupt: 685.31
Interrupt frequency: 25500.00 Hz
PWM frequency: 99.61 Hz
This is without the chips actually connected (by boards are being fabricated now), so I suspect much of that is waiting for SPI to timeout in the read loop?
If I don't actually send the values over SPI it drops to Load of interrupt: 0.1692283
If you would like to see my code I will gladly post it somewhere, but it is teensy 3.0 specific.
Hi, I was wondering if this is possible to have the schematic file of this image http://www.elcojacobs.com/wp-content/uploads/2012/08/shiftpwm_74hc595_RGB.png. I want to make a board that include the shifts registrer.
Thanks
I'm trying to change the latch pin to digital pin 12 on arduino uno. It doesn't work. I tried use default 8, also 9, 10. They all worked. Just pin 12 doesn't work. Do you know why? Thanks.
const int ShiftPWM_latchPin=12;
Hi, i would like to know if its possible to get this library to work with the attiny.
Someone tried before, but it doesn't work and they cannot maintain it anymore.
I would think it is possible , but the code that takes care of serial communications needs to be replaced as the attiny doesn't have hardware serial.
this are the errors that i get when trying to compile :
In file included from \arduino-1.0.6\libraries\ShiftPWM-master/ShiftPWM.h:25,
from ShiftPWM_RGB_Example.ino:35:
/pins_arduino_compile_time.h:318: error: 'PORTC' was not declared in this scope
pins_arduino_compile_time.h:319: error: 'PORTD' was not declared in this scope
In file included from ShiftPWM_RGB_Example.ino:35:
ShiftPWM.h:57: error: 'MOSI' was not declared in this scope
ShiftPWM.h:57: error: 'SCK' was not declared in this scope
ShiftPWM.h: In function 'void ShiftPWM_handleInterrupt()':
ShiftPWM.h:131: error: 'SPDR' was not declared in this scope
ShiftPWM.h:147: error: 'SPSR' was not declared in this scope
ShiftPWM.h:147: error: 'SPIF' was not declared in this scope
ShiftPWM.h:153: error: 'SPSR' was not declared in this scope
ShiftPWM.h:153: error: 'SPIF' was not declared in this scope
would be really great to get matrix functionality ported here or have the matrix version updated.. really lookinf for a non-blocking version of matrix
HI , I am trying to really micronise RGB led circuits ,
Using the the new tiny zero , for >>>> led jewelry ,
Tried compiling sketch for tiny zero , but no luck , any chance if this being compatible with new tiny zero : ? )
USing smd 74HC595 plus smd resistor , got a good magnifying Glass light :)
I am hoping to add/combine my-sensors gesture Sensor to turn leds on and off ,
With a small 433mz transmitter for switching RF unit on/off two
I have 3 74HC595s controlling SIX(yes six, because I don't like to use the one pin on the other side of the chip)common cathode RGB LEDs with frequency set to 240(anything lower was just flickering so much I could not look at the LEDs)... First two registers flicker the LEDs at about 15Hz and the third one is fine fading the green but not blue and red(I will upload image of my PCB in Fritzing later)... Using timer2 just makes it worse or not working at all, using balance load slows the flicker to about 3/4 of the speed.
Thanks for making this great library.
What would I need to do to make it work with the HV5523 which has 32 outputs; i.e. needs 32 bit data shifted out?
Thanks for any advice.
On your webpage you link to https://github.com/elcojacobs/ShiftPWM/downloads for downloads, there are none on that adress.
I understand if you don't have the time to update the links but please at least upload README.md to your repo with instructions on how to compile this.
when I am changing the maxBrightness variable (and uploading the code to my arduino, of course) nothing happens, the LEDs are full brightness still.
Hi,
there seems to have incompatibility between Software serial communcation and ShiftPWM. I can't receive anything from the serial software if this line (and of course all the rest needed for ShiftPWM) is there: ShiftPWM.Start(pwmFrequency,maxBrightness);.
Any solution ? I really need both of them.
Thanks
William
My library is a very useful timing library that can time multiple steps (or sequence code). It is also my first library. Can you guys take a look at it and give me some feedback?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.