Rationalise the external clock compilation.

48kHz
Jonathan Naylor 2016-03-27 11:16:54 +01:00
parent 591ed534b5
commit e6f86052cc
2 changed files with 16 additions and 15 deletions

View File

@ -20,9 +20,13 @@
#define CONFIG_H
// Allow for the use of high quality external clock oscillators
// There is one entry for 12 MHz and another for 14.4 MHz
// #define EXTERNAL_OSC_12_MHZ
// #define EXTERNAL_OSC_14_4_MHZ
// The number is the frequency of the oscillator in Hertz.
// For 12 MHz
// #define EXTERNAL_OSC 12000000
// For 14.4 MHz
// #define EXTERNAL_OSC 14400000
// For 19.2 MHz
// #define EXTERNAL_OSC 19200000
// Allow the use of the COS line to lockout the modem
// #define USE_COS_AS_LOCKOUT

21
IO.cpp
View File

@ -162,10 +162,10 @@ void CIO::start()
ADC->ADC_COR = 0x00000000; // All offsets off
ADC->ADC_MR = (ADC->ADC_MR & 0xFFFFFFF0) | (1 << 1) | ADC_MR_TRGEN; // 1 = trig source TIO from TC0
#if defined(EXTERNAL_OSC_12_MHZ) || defined(EXTERNAL_OSC_14_4_MHZ)
#if defined(EXTERNAL_OSC)
// Set up the external clock input on PA4 = AI5
REG_PIOA_ODR = 0x10; // Set Pin As Input
REG_PIOA_PDR = 0x10; // Disable PIO A Bit 4
REG_PIOA_ODR = 0x10; // Set pin as input
REG_PIOA_PDR = 0x10; // Disable PIO A bit 4
REG_PIOA_ABSR &= ~0x10; // Select A peripheral = TCLK1 Input
#endif
@ -175,8 +175,8 @@ void CIO::start()
t->TC_CCR = TC_CCR_CLKDIS; // Disable internal clocking while setup regs
t->TC_IDR = 0xFFFFFFFF; // Disable interrupts
t->TC_SR; // Read int status reg to clear pending
#if defined(EXTERNAL_OSC_12_MHZ) || defined(EXTERNAL_OSC_14_4_MHZ)
t->TC_CMR = TC_CMR_TCCLKS_XC1 | // Use XC1 = TCLK1 External clock
#if defined(EXTERNAL_OSC)
t->TC_CMR = TC_CMR_TCCLKS_XC1 | // Use XC1 = TCLK1 external clock
#else
t->TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1 | // Use TCLK1 (prescale by 2, = 42MHz)
#endif
@ -185,14 +185,11 @@ void CIO::start()
TC_CMR_EEVT_XC0 | // Set external events from XC0 (this setup TIOB as output)
TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_CLEAR |
TC_CMR_BCPB_CLEAR | TC_CMR_BCPC_CLEAR;
#if defined(EXTERNAL_OSC_14_4_MHZ)
t->TC_RC = 600; // Counter resets on RC, so sets period in terms of 14.4MHz External clock
t->TC_RA = 300; // Roughly square wave
#elif defined(EXTERNAL_OSC_12_MHZ)
t->TC_RC = 500; // Counter resets on RC, so sets period in terms of 12MHz External clock
t->TC_RA = 250; // Roughly square wave
#if defined(EXTERNAL_OSC)
t->TC_RC = EXTERNAL_OSC / 24000; // Counter resets on RC, so sets period in terms of the external clock
t->TC_RA = EXTERNAL_OSC / 48000; // Roughly square wave
#else
t->TC_RC = 1750; // Counter resets on RC, so sets period in terms of 42MHz Internal clock
t->TC_RC = 1750; // Counter resets on RC, so sets period in terms of 42MHz internal clock
t->TC_RA = 880; // Roughly square wave
#endif
t->TC_CMR = (t->TC_CMR & 0xFFF0FFFF) | TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_SET; // Set clear and set from RA and RC compares