36 lines
1.3 KiB
C++
36 lines
1.3 KiB
C++
//
|
|
//Abel: at 120bpm the actual output is 119.3bpm (47.7Hz). Does this depend on each individual power supply? Would it be possible to calibrate 120bpm to 48Hz?
|
|
//
|
|
// in theory it should be 600000 / (120 * 24) = 208.333(3). 20.8ms should result in 48.076923076923
|
|
#include <FixedPoints.h>
|
|
#include <FixedPointsCommon.h>
|
|
|
|
|
|
//uint16_t pulsePeriod; //useful range of 0 to 65,535 ((2^16) - 1).
|
|
UFixed<7, 9> bpm = 120; //0-255
|
|
|
|
#define PPQN 24
|
|
#define PULSE_LENGTH 120 //1/10ms resolution. 12ms was failing at 1ms resolution at higher bpm. 60000/200/24 = 12.5 the max pulse length at 1ms resolution for 200bpm is 11ms
|
|
#define MAXBPM 200 //250 at 24ppqn with 5ms pulse will be 50/50 square wave
|
|
#define MINBPM 20
|
|
|
|
void setup() {
|
|
Serial.begin(19200);
|
|
int pulsePeriod = 600000 / (bpm.getInteger() * PPQN);
|
|
Serial.print("original uint16_t: ");
|
|
Serial.println(pulsePeriod);
|
|
float floatperiod = 600000 / ((float)bpm * (float)PPQN);
|
|
Serial.print("float: ");
|
|
Serial.println(floatperiod);
|
|
// fpperiod = 600000 / (bpm * PPQN);
|
|
//Serial.print("UQ8x8: ");
|
|
//Serial.println((float)fpperiod);
|
|
UFixed<7, 9> fpperiodplus = 600000 / (bpm * PPQN);
|
|
Serial.print("UQ7x9: ");
|
|
Serial.println((float)fpperiodplus);
|
|
}
|
|
|
|
void loop() {
|
|
// put your main code here, to run repeatedly:
|
|
|
|
} |