Comments (2)
Hi @snagaitsev
It seems that you didn't use the higher uS resolution (default is mS) causing the counter to be imperfect.
Try to add
#define USING_MICROS_RESOLUTION true
before
#include "Teensy_Slow_PWM.h"
such as in your modified code
/*
Slow PWM test
*/
#define USING_MICROS_RESOLUTION true
#include "Teensy_Slow_PWM.h"
#define HW_TIMER_INTERVAL_MS 0.01f
#define HW_TIMER_INTERVAL_FREQ 100000L
#define PIN_COUNT 16
int ssr0 = 3;
int ssr1 = 2;
int ssr2 = 5;
int ssr3 = 4;
int ssr4 = 7;
int ssr5 = 6;
int ssr6 = 9;
int ssr7 = 8;
int ssr8 = 11;
int ssr9 = 10;
int ssr10 = 14;
int ssr11 = 12;
int ssr12 = 18;
int ssr13 = 15;
int ssr14 = 22;
int ssr15 = 19;
// these are in ssr order
int pins[] = {
3,
2,
5,
4,
7,
6,
9,
8,
11,
10,
14,
12,
18,
15,
22,
19
};
// Init Teensy timer TEENSY_TIMER_1
TeensyTimer ITimer(TEENSY_TIMER_1);
// Init Teensy_SLOW_PWM, each can service 16 different ISR-based PWM channels
Teensy_SLOW_PWM ISR_PWM;
void TimerHandler()
{
ISR_PWM.run();
}
int channels[PIN_COUNT];
float dutyCycles[PIN_COUNT];
float freq = 50.0f;
// the setup routine runs once when you press reset:
void setup()
{
Serial.begin(115200);
// Must be after attachInterrupt()
#if 0
// initialize the digital pin as an output.
for (int i = 0; i < PIN_COUNT; i++)
{
pinMode(pins[i], OUTPUT);
dutyCycles[i] = 0.0f;
channels[i] = ISR_PWM.setPWM(pins[i], freq, dutyCycles[i]);
}
#endif
if (ITimer.attachInterrupt(HW_TIMER_INTERVAL_FREQ, TimerHandler))
{
Serial.println("Timer is good");
}
else
{
Serial.println("Timer is bad");
}
// initialize the digital pin as an output.
for (int i = 0; i < PIN_COUNT; i++)
{
pinMode(pins[i], OUTPUT);
dutyCycles[i] = 50.0f;
channels[i] = ISR_PWM.setPWM(pins[i], freq, dutyCycles[i]);
}
// Display 50% for 5s
delay(5000);
for (int i = 0; i < PIN_COUNT; i++)
{
pinMode(pins[i], OUTPUT);
dutyCycles[i] = 0.0;
ISR_PWM.modifyPWMChannel(channels[i], pins[i], freq, dutyCycles[i]);
}
}
bool dutySwitch = false;
// the loop routine runs over and over again forever:
void loop()
{
delay(2000);
}
from teensy_slow_pwm.
from teensy_slow_pwm.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from teensy_slow_pwm.