mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added small programming to compute ws2811 timing
Former-commit-id: 3f62bca1476b1cba17946c309482e595f68c1698
This commit is contained in:
parent
01b5dcdd5c
commit
4a494e53e9
@ -49,6 +49,8 @@ add_executable(spidev_test spidev_test.c)
|
||||
|
||||
add_executable(gpio2spi switchPinCtrl.c)
|
||||
|
||||
add_executable(determineWs2811Timing DetermineWs2811Timing.cpp)
|
||||
|
||||
add_executable(test_rs232highspeed
|
||||
TestRs232HighSpeed.cpp
|
||||
../libsrc/leddevice/LedRs232Device.cpp
|
||||
|
60
test/DetermineWs2811Timing.cpp
Normal file
60
test/DetermineWs2811Timing.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
|
||||
// STl includes
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
bool requiredTiming(const int tHigh_ns, const int tLow_ns, const int error_ns, const int nrBits)
|
||||
{
|
||||
std::cout << "=== " << nrBits << " bits case ===== " << std::endl;
|
||||
double bitLength_ns = (tHigh_ns + tLow_ns)/double(nrBits);
|
||||
double baudrate_Hz = 1.0 / bitLength_ns * 1e9;
|
||||
std::cout << "Required bit length: " << bitLength_ns << "ns => baudrate = " << baudrate_Hz << std::endl;
|
||||
|
||||
double highBitsExact = tHigh_ns/bitLength_ns;
|
||||
int highBits = std::round(highBitsExact);
|
||||
double lowBitsExact = tLow_ns/bitLength_ns;
|
||||
int lowBits = std::round(lowBitsExact);
|
||||
std::cout << "Bit division: high=" << highBits << "(" << highBitsExact << "); low=" << lowBits << "(" << lowBitsExact << ")" << std::endl;
|
||||
|
||||
double highBitsError = std::fabs(highBitsExact - highBits);
|
||||
double lowBitsError = std::fabs(highBitsExact - highBits);
|
||||
double highError_ns = highBitsError * bitLength_ns;
|
||||
double lowError_ns = lowBitsError * bitLength_ns;
|
||||
|
||||
if (highError_ns > error_ns || lowError_ns > error_ns)
|
||||
{
|
||||
std::cerr << "Timing error outside specs: " << highError_ns << "; " << lowError_ns << " > " << error_ns << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Timing within margins: " << highError_ns << "; " << lowError_ns << " < " << error_ns << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// 10bits
|
||||
requiredTiming(400, 850, 150, 10); // Zero
|
||||
requiredTiming(800, 450, 150, 10); // One
|
||||
|
||||
// 6bits
|
||||
requiredTiming(400, 850, 150, 6); // Zero
|
||||
requiredTiming(800, 450, 150, 6); // One
|
||||
|
||||
// 5bits
|
||||
requiredTiming(400, 850, 150, 5); // Zero
|
||||
requiredTiming(800, 450, 150, 5); // One
|
||||
|
||||
// 4bits
|
||||
requiredTiming(400, 850, 150, 4); // Zero
|
||||
requiredTiming(800, 450, 150, 4); // One
|
||||
|
||||
// 3bits
|
||||
requiredTiming(400, 850, 150, 3); // Zero
|
||||
requiredTiming(800, 450, 150, 3); // One
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user