Im trying to compile the code from Bjorklund
s "The Theory of Rep-Rate Pattern Generation in the SNS Timing System"
https://ics-web.sns.ornl.gov/timing/Rep-Rate%20Tech%20Note.pdf
and have bad results on output.
Can someone lead me in this?
here is the code:
#include "LiquidCrystal.h"
LiquidCrystal lcd(12,11,5,4,3,2);
int remainder[16];
int count[16];
int divisor;
int i;
int pattern[16];
void setup() {
lcd.begin(16,2);
//lcd.print("ON");
}
void loop() {
compute_bitmap (8,3);
delay(1000);
lcd.clear();
}
void compute_bitmap (int num_slots, int num_pulses)
{
divisor = (num_slots - num_pulses);
remainder[0] = num_pulses;
int newLength;
int level = 0;
int cycleLength = 1;
int remLength = 1;
do {
count[level] = (divisor / remainder[level]);
remainder[level+1] = (divisor % remainder[level]);
divisor = remainder[level];
newLength = (cycleLength * count[level]) + remLength;
remLength = cycleLength;
cycleLength = newLength;
level = level + 1; }
while (remainder[level] > 1);
count[level] = divisor;
if (remainder[level] > 0)
cycleLength = (cycleLength * count[level]) + remLength;
build_string (level);
}
void build_string (int level) {
if (level == -1) {
//append a “0” to the end of the bitmap;
//lcd.print("0"); //try to output on LCD for debug
}
else if (level == -2) {
//append a “1” to the end of the bitmap;
//lcd.print("1"); //try to output on LCD for debug
}
else { for (i=0; i < count[level]; i++)
build_string (level-1);
if (remainder[level] != 0)
build_string (level-2);
}
}