Skip to content

Commit

Permalink
i did this ages ago
Browse files Browse the repository at this point in the history
sig gen now outputs correct hi-frq signal
  • Loading branch information
H3wastooshort committed Aug 30, 2024
1 parent 274655e commit d73f11c
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions firmware/BikeUSBv2_test_generator/BikeUSBv2_test_generator.ino
Original file line number Diff line number Diff line change
@@ -1,26 +1,53 @@
void setup() {
Serial.begin(115200);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);


noInterrupts();
// Clear registers
TCCR2A = 0;
TCCR2B = 0;
TCNT2 = 0;

// 10000 Hz (16000000/((24+1)*64))
OCR2A = 24;
// CTC
TCCR2A |= (1 << WGM21);
// Prescaler 64
TCCR2B |= (1 << CS22);
// Output Compare Match A Interrupt Enable
TIMSK2 |= (1 << OCIE2A);
interrupts();
}

uint16_t divider = 9999;
uint16_t counter = 0;
bool state = 0;
ISR(TIMER2_COMPA_vect) {
counter++;
if (counter > divider) {
digitalWrite(7, state);
digitalWrite(6, !state);
state ^= 1;
counter = 0;
}
}

union {
uint16_t i;
uint8_t b[sizeof(i)];
} val;

uint16_t t = 100;

void loop() {
val.i = analogRead(A0);
Serial.write(val.b, sizeof(val.b));

digitalWrite(7, (millis() % t) > (t / 2));

if (Serial.available()) {
switch (Serial.read()) {
case 't':
case 'F':
delay(100);
t = Serial.parseInt();
divider = Serial.parseInt();
break;
case 'i': analogReference(INTERNAL);
case 'd': analogReference(DEFAULT);
Expand Down

0 comments on commit d73f11c

Please sign in to comment.