added ITimer2 for FSK

pull/206/head
alanbjohnston 3 years ago committed by GitHub
parent 3d77b0e3b0
commit 4dc8a9cd90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2115,28 +2115,12 @@ void config_radio()
// start_pwm(); // start_pwm();
// start_isr(); // start_isr();
clockgen.setClockBPSK(); clockgen.setClockBPSK();
if (ITimer0.setInterval(delay_time - 32, TimerHandler0))
{
if (debug_mode)
Serial.print(F("Reseting ITimer0 OK, micros() = ")); Serial.println(micros());
}
else
Serial.println(F("Can't reset ITimer0. Select another Timer, freq. or timer"));
transmit_on(); transmit_on();
} }
if ((mode == FSK)) // || (mode == SSTV)) if ((mode == FSK)) // || (mode == SSTV))
// start_isr(); // start_isr();
clockgen.setClockFSK(); clockgen.setClockFSK();
if (ITimer0.setInterval(delay_time - 32, TimerHandler0))
{
if (debug_mode)
Serial.print(F("Reseting ITimer0 OK, micros() = ")); Serial.println(micros());
}
else
Serial.println(F("Can't reset ITimer0. Select another Timer, freq. or timer"));
transmit_on(); transmit_on();
} }
@ -3450,13 +3434,12 @@ bool TimerHandler0(struct repeating_timer *t) {
// digitalWrite(STEM_LED_GREEN, !green_led_counter++); // digitalWrite(STEM_LED_GREEN, !green_led_counter++);
if ((mode == BPSK) || (mode == FSK)) { // only do this if BPSK mode. Should turn off timer interrupt when not BPSK in future if (mode == BPSK) { // only do this if BPSK mode. Should turn off timer interrupt when not BPSK in future
// Serial.print("l1 "); // Serial.print("l1 ");
// Serial.print(wav_position); // Serial.print(wav_position);
// Serial.print(" "); // Serial.print(" ");
while ((micros() - micro_timer2) < delay_time) { } while ((micros() - micro_timer2) < delay_time) { }
if (mode == BPSK) busy_wait_at_least_cycles(51); // 300 ns
busy_wait_at_least_cycles(51); // 300 ns
// if ((micros() - micro_timer2) > 834) // if ((micros() - micro_timer2) > 834)
// Serial.println(micros() - micro_timer2); // Serial.println(micros() - micro_timer2);
micro_timer2 = micros(); micro_timer2 = micros();
@ -3475,24 +3458,64 @@ bool TimerHandler0(struct repeating_timer *t) {
// Serial.print("_"); // Serial.print("_");
// clockgen.enableOutputOnly(0); // clockgen.enableOutputOnly(0);
} }
if (wav_position > bufLen) { // 300) {
wav_position = wav_position % bufLen;
// Serial.print("\nR");
// Serial.print(" ");
// Serial.println(millis());
/**/
// if ((micros() - micro_timer)/bufLen > (delay_time + 10)) {
if (bufLen != 0) {
Serial.print("R0 Microseconds: ");
Serial.println((float)(micros() - micro_timer)/(float)bufLen);
}
// }
micro_timer = micros();
/**/
} else {
// Serial.print("R' Microseconds: ");
// Serial.println(micros() - micro_timer2);
// while ((micros() - micro_timer2) < 832) { }
// micro_timer2 = micros();
}
}
/* /*
tx_bit = (buffer[wav_position] > 0) ? HIGH: LOW; if (digitalRead(MAIN_PB_PIN) == PRESSED) // pushbutton is pressed
process_pushbutton();
if (BOOTSEL) // boot selector button is pressed on Pico
process_bootsel();
*/
digitalWrite(AUDIO_OUT_PIN, tx_bit); return true;
}
tx_bit = (buffer[wav_position++] > 0) ? true: false; bool TimerHandler2(struct repeating_timer *t) {
*/
/* // digitalWrite(STEM_LED_GREEN, !green_led_counter++);
if (tx_bit)
Serial.print("-"); if (mode == FSK) { // only do this if BPSK mode. Should turn off timer interrupt when not BPSK in future
else // Serial.print("l1 ");
Serial.print("_"); // Serial.print(wav_position);
*/ // Serial.print(" ");
/* while ((micros() - micro_timer2) < delay_time) { }
pwm_config_set_output_polarity( &config, tx_bit, tx_bit); // if ((micros() - micro_timer2) > 834)
pwm_init(bpsk_pin_slice, &config, true); // Serial.println(micros() - micro_timer2);
pwm_set_gpio_level(BPSK_PWM_PIN, (config.top + 1) * 0.5); micro_timer2 = micros();
*/ if (buffer[wav_position++] > 0) {
// digitalWrite(BPSK_CONTROL_B, LOW);
digitalWrite(BPSK_CONTROL_B, LOW);
// delayMicroseconds(10);
digitalWrite(BPSK_CONTROL_A, HIGH);
// Serial.print("-");
// clockgen.enableOutputOnly(1);
} else {
// digitalWrite(BPSK_CONTROL_A, LOW);
digitalWrite(BPSK_CONTROL_A, LOW);
// delayMicroseconds(10);
digitalWrite(BPSK_CONTROL_B, HIGH);
// Serial.print("_");
// clockgen.enableOutputOnly(0);
}
if (wav_position > bufLen) { // 300) { if (wav_position > bufLen) { // 300) {
wav_position = wav_position % bufLen; wav_position = wav_position % bufLen;
// Serial.print("\nR"); // Serial.print("\nR");
@ -3501,7 +3524,7 @@ bool TimerHandler0(struct repeating_timer *t) {
/**/ /**/
// if ((micros() - micro_timer)/bufLen > (delay_time + 10)) { // if ((micros() - micro_timer)/bufLen > (delay_time + 10)) {
if (bufLen != 0) { if (bufLen != 0) {
Serial.print("R Microseconds: "); Serial.print("R2 Microseconds: ");
Serial.println((float)(micros() - micro_timer)/(float)bufLen); Serial.println((float)(micros() - micro_timer)/(float)bufLen);
} }
// } // }
@ -3536,12 +3559,7 @@ void start_isr() {
digitalWrite(BPSK_CONTROL_A, LOW); // start with off digitalWrite(BPSK_CONTROL_A, LOW); // start with off
digitalWrite(BPSK_CONTROL_B, LOW); digitalWrite(BPSK_CONTROL_B, LOW);
// if (ITimer0.attachInterruptInterval(833, TimerHandler0)) if (ITimer0.attachInterruptInterval(833 - 32, TimerHandler0))
// if (ITimer0.attachInterruptInterval(804, TimerHandler0))
// if (ITimer0.attachInterruptInterval(800, TimerHandler0)) // was 800 // was was 828 (841) and 828
if (ITimer0.attachInterruptInterval(delay_time - 32, TimerHandler0)) // was 800 // was was 828 (841) and 828
// if (ITimer0.attachInterruptInterval(1667, TimerHandler0))
{ {
if (debug_mode) if (debug_mode)
Serial.print(F("Starting ITimer0 OK, micros() = ")); Serial.println(micros()); Serial.print(F("Starting ITimer0 OK, micros() = ")); Serial.println(micros());
@ -3550,10 +3568,22 @@ void start_isr() {
else else
Serial.println(F("Can't set ITimer0. Select another Timer, freq. or timer")); Serial.println(F("Can't set ITimer0. Select another Timer, freq. or timer"));
Serial.println("Starting ISR for FSK");
if (ITimer2.attachInterruptInterval(5000 - 32, TimerHandler2))
// if (ITimer0.attachInterruptInterval(1667, TimerHandler0))
{
if (debug_mode)
Serial.print(F("Starting ITimer2 OK, micros() = ")); Serial.println(micros());
timer2_on = true;
}
else
Serial.println(F("Can't set ITimer2. Select another Timer, freq. or timer"));
} else { } else {
// ITimer0.restartTimer(); // ITimer0.restartTimer();
// Serial.println("Restarting ITimer0 for BPSK"); // Serial.println("Restarting ITimer0 for BPSK");
Serial.println("Don't restart ITimer0 for BPSK"); Serial.println("Don't restart ITimer0 for BPSK and ITimer2 for FSK");
} }
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.