Code Monkey home page Code Monkey logo

softpwm's People

Contributors

bhagman avatar paulstoffregen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

softpwm's Issues

LED doesn't go off entirely!

even if I set the PWM to 255 the LED doesn't go off entirely. Its always lighting a bit! What can be the reason? I used a sink configuration with the ATMEGA GPIO to GND.
img_20180607_155247

No compatible with ATMEGA4809 based boards (NANO_EVERY, etc.)

The library works with Arduino Nano and Teensy (AVR/ARM) but not with EVERY boards (MEGAAVR).
When compiling, following error is given...

In file included from Arduino\libraries\SoftPWM\SoftPWM.cpp:44:0:
Arduino\libraries\SoftPWM\SoftPWM.cpp: In function 'void SoftPWMBegin(uint8_t)':
Arduino\libraries\SoftPWM\SoftPWM_timer.h:39:3: error: 'TIFR2' was not declared in this scope
TIFR2 = (1 << TOV2); /* clear interrupt flag */ \

SoftPWMServo.h: No such file or directory

Arduino: 1.8.12 (Mac OS X), Board: "ChipKit uC32"

RoomControlCode:2:10: fatal error: SoftPWMServo.h: No such file or directory
#include <SoftPWMServo.h>
^~~~~~~~~~~~~~~~
compilation terminated.
exit status 1
SoftPWMServo.h: No such file or directory

Change PWM frequency

Hi there!
Is there an option to increase the frequency of the PWM signal? I'm trying to control small DC motors using this library, but there are significant vibrations going on to the motor with using the PWM. I suppose it is cause of the low frequency of the PWM signal. If yes, how can I do that?

Multiple Pins from one call

I would like to activate multiple pins at once using soft pwm...

maybe the ability to pass an array instead of a single value?

Would this be possible?

millis() stops working when using more than 4 LEDs with SoftPWM

Hi Brett
I like your SoftPWM-library for arduino a lot. Just today I found out, that millis() stops working, as soon as more than 4 LEDs are controlled using our library. I wasn't able to find a solution to that problem. Do you have an idea?
Best regards,
Dani

I used your example-code (), which uses 8 LEDs:
When checking with the serial monitor, I get constantly

26
26
26

Here is the code that doesn't work:

#include <SoftPWM.h>

#define DELAY 100
uint8_t leds[8] = {11,12,13,18,17,16,15,10};

void setup()
{
  Serial.begin(57600);
  SoftPWMBegin();

  for (int i = 0; i < 8; i++)
    SoftPWMSet(leds[i], 0);

  SoftPWMSetFadeTime(ALL, 50, 400);
}

void loop()
{
  int i;
  Serial.println(millis());
  for (i = 0; i < 7; i++)
  {
    SoftPWMSet(leds[i+1], 255);
    SoftPWMSet(leds[i], 0);
    delay(DELAY);
  }

  delay(400);

  for (i = 7; i > 0; i--)
  {
    SoftPWMSet(leds[i-1], 255);
    SoftPWMSet(leds[i], 0);
    delay(DELAY);
  }
  delay(400);
}

As soon as I change the code, so that it uses only 4 LEDs, it works as expected:

3014
5851
8695

Here is the code that works:

#include <SoftPWM.h>

#define DELAY 100
uint8_t leds[8] = {11,12,13,18,17,16,15,10};

void setup()
{
  Serial.begin(57600);
  SoftPWMBegin();

  for (int i = 0; i < 4; i++)
    SoftPWMSet(leds[i], 0);

  SoftPWMSetFadeTime(ALL, 50, 400);
}

void loop()
{
  int i;
  Serial.println(millis());
  for (i = 0; i < 3; i++)
  {
    SoftPWMSet(leds[i+1], 255);
    SoftPWMSet(leds[i], 0);
    delay(DELAY);
  }

  delay(400);

  for (i = 3; i > 0; i--)
  {
    SoftPWMSet(leds[i-1], 255);
    SoftPWMSet(leds[i], 0);
    delay(DELAY);
  }
  delay(400);
}

on is not on, i.e pwm of 255 have a short period of 0

"on" is not fully "on", i.e. pwm of 255 have a short period of 0

This is how i patched it to work for my application (DC motor - h-bridge with "break" and "coast" ):
Note: My "h-bridge" ic require "full width high" for a "break" and "full width low" for a "coast"

What I did is:

  1. Reset high and low when "++_isr_softcount == 0"
  2. Skip "hit width" validation test for "checkval == 0" and "checkval == 255"

see the modified interrupt function below:

{
  uint8_t i;
  int16_t newvalue;
  int16_t direction;

  if (++_isr_softcount == 0)
  {
    // set all channels high - let's start again
    // and accept new checkvals
    for (i = 0; i < SOFTPWM_MAXCHANNELS; i++)
    {
      if (_softpwm_channels[i].fadeuprate > 0 || _softpwm_channels[i].fadedownrate > 0)
      {
        // we want to fade to the new value
        direction = _softpwm_channels[i].pwmvalue - _softpwm_channels[i].checkval;

        // we will default to jumping to the new value
        newvalue = _softpwm_channels[i].pwmvalue;

        if (direction > 0 && _softpwm_channels[i].fadeuprate > 0)
        {
          newvalue = _softpwm_channels[i].checkval + _softpwm_channels[i].fadeuprate;
          if (newvalue > _softpwm_channels[i].pwmvalue)
            newvalue = _softpwm_channels[i].pwmvalue;
        }
        else if (direction < 0 && _softpwm_channels[i].fadedownrate > 0)
        {
          newvalue = _softpwm_channels[i].checkval - _softpwm_channels[i].fadedownrate;
          if (newvalue < _softpwm_channels[i].pwmvalue)
            newvalue = _softpwm_channels[i].pwmvalue;
        }

        _softpwm_channels[i].checkval = newvalue;
      }
      else // just set the channel to the new value
        _softpwm_channels[i].checkval = _softpwm_channels[i].pwmvalue;

      // now set the pin low (checkval == 0x00) otherwise high 
      if (_softpwm_channels[i].checkval == 0x00)
      {
        if (_softpwm_channels[i].polarity == SOFTPWM_NORMAL)
          *_softpwm_channels[i].outport &= ~(_softpwm_channels[i].pinmask);
        else
          *_softpwm_channels[i].outport |= _softpwm_channels[i].pinmask;
      }
      else
      {
        if (_softpwm_channels[i].polarity == SOFTPWM_NORMAL)
          *_softpwm_channels[i].outport |= _softpwm_channels[i].pinmask;
        else
          *_softpwm_channels[i].outport &= ~(_softpwm_channels[i].pinmask);
      }
    }
  }

  for (i = 0; i < SOFTPWM_MAXCHANNELS; i++)
  {
    if (_softpwm_channels[i].pin >= 0) // if it's a valid pin
    {
      // skip hit on checkval 0 and 255
      if (_softpwm_channels[i].checkval != 0x00 && _softpwm_channels[i].checkval != 0xFF)
      {
        if (_softpwm_channels[i].checkval == _isr_softcount) // if we have hit the width
        {
          // turn off the channel
          if (_softpwm_channels[i].polarity == SOFTPWM_NORMAL)
            *_softpwm_channels[i].outport &= ~(_softpwm_channels[i].pinmask);
          else
            *_softpwm_channels[i].outport |= _softpwm_channels[i].pinmask;
        }
      }
    }
  }
}

SoftPWM does not work with IRremote library?

I wanted to use the library in a sketch including the IRremote library. Both librarys dont anymore as soon as they are enabled using irrecv.enableIRIn(); respectively SoftPWMBegin();.

I can assume some reasons for that behavior, but I am devinitely not able to tear down the exact reason.

Pins don't go HIGH anymore

PWM 255 as well as digitalWrite(PIN,HIGH) isn't HIGH any more.
Now there is a PWM spike on the signal. Seems that PWM 254 is the maximum HIGH level now.
LOW Level works (as mentioned within the README.md "True zero level, i.e. off == off").
HIGH Level is not mentioned :-)
I really appreciate the purpose of this library.

No longer viable

The lib compiles fine on Arduino CREATE but fails to upload.
It is NOT a CREATE problem but appears to be with the samples.

More than 20 pins on Mega2560

Hello,

Would it be possible to control more than 20 pins (I'd need 24 pins) on Mega2560?
I don't have it yet so I can't test, just want to know if possible and how.

Thanks!

SoftPWM_Wiring_HeartBeat

suggested add:

byte WLED = 13;

else you get:

Arduino: 1.8.5 (Linux), Board: "Arduino Nano, ATmega328P"

/home/pi/Arduino/libraries/SoftPWM/examples/SoftPWM_Wiring_HeartBeat/SoftPWM_Wiring_HeartBeat.pde: In function 'void setup()':
SoftPWM_Wiring_HeartBeat:8: error: 'WLED' was not declared in this scope
SoftPWMSet(WLED, 0);
^
/home/pi/Arduino/libraries/SoftPWM/examples/SoftPWM_Wiring_HeartBeat/SoftPWM_Wiring_HeartBeat.pde: In function 'void loop()':
SoftPWM_Wiring_HeartBeat:18: error: 'WLED' was not declared in this scope
SoftPWMSet(WLED, 255);
^
exit status 1
'WLED' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.