It is design to pull incoming pulses off its internal ADC. The ADC clock is 18Mhz @ 16bits.
Pins 13,14 and 15 are used... Pin 13 in the pulse collector, 14 and 15 are interrupts..
Details of the build come from here https://forum.pjrc.com/threads/25321-Te ... +analyzer
The code below works and
i have been playing with it. I have overclocked my Teensy to 240Mhz.
I am right now debugging the peak detector/
More coming soon. High voltage is being supplied by the GS-PRO-USB and works well.
Code: Select all
// __MK66FX1M0__ = Teensy 3.6
#ifndef __MK66FX1M0__
#error This code is for Teensy 3.6!
#endif
// Assumes Teensy 3.1
// Result from ADC
int ADC_res;
void setup() {
// Prepare USB connection
Serial.begin(0);
// Prepare output signal
pinMode(13, OUTPUT);
// Prepare reset signal
pinMode(15, OUTPUT);
// Prepare intterrupt signal
pinMode(14, INPUT);
attachInterrupt(14, processData, RISING);
// Configure ADC
/* DEFAULT
0 ADLPC (Low-Power Configuration)
0 ADIV (Clock Divide Select)
0
0 ADLSMP (Sample time configuration)
0 MODE (Conversion mode selection) (00=8/9, 01=12/13, 10=10/11, 11=16/16 bit; diff=0/1)
0
0 ADICLK (Input Clock Select)
0
*/
ADC0_CFG1 = 0b00011000;
/* DEFAULT
0 MUXSEL (ADC Mux Select)
0 ADACKEN (Asynchrononous Clock Output Enable)
0 ADHSC (High-Speed Configuration)
0 ADLSTS (Long Sample Time Select) (00=+20 cycles, 01=+12, 10=+6, 11=+2)
0
*/
ADC0_CFG2 = 0b00000;
/* DEFAULT
0 ADTRG (Conversion Trigger Select)
0 ACFE (Compare Function Enable)
0 ACFGT (Compare Function Greater than Enable)
0 ACREN (Compare Function Range Enable)
0 ACREN (COmpare Function Range Enable)
0 DMAEN (DMA Enable)
0 REFSEL (Voltage Reference Selection) (00=default,01=alternate,10=reserved,11=reserved)
*/
ADC0_SC2 = 0b0000000;
/* DEFAULT
0 CAL (Calibration)
0 CALF (read only)
0 (Reserved)
0
0 ADCO (Continuous Conversion Enable)
0 AVGS (Hardware Average Enable)
0 AVGS (Hardware Average Select) (00=4 times, 01=8, 10=16, 11=32)
0
*/
ADC0_SC3 = 0b10000111;
// Waiting for calibration to finish. The documentation is confused as to what flag to be waiting for (SC3[CAL] on page 663 and SC1n[COCO] on page 687+688).
while (ADC0_SC3 & ADC_SC3_CAL) {}
// Apply calibration data (code from officiel Teensy library)
/* Teensyduino Core Library
* http://www.pjrc.com/teensy/
* Copyright (c) 2013 PJRC.COM, LLC.
\teensy\cores\teensy3\analog.c
*/
uint16_t sum;
sum = ADC0_CLPS + ADC0_CLP4 + ADC0_CLP3 + ADC0_CLP2 + ADC0_CLP1 + ADC0_CLP0;
sum = (sum / 2) | 0x8000;
ADC0_PG = sum;
sum = ADC0_CLMS + ADC0_CLM4 + ADC0_CLM3 + ADC0_CLM2 + ADC0_CLM1 + ADC0_CLM0;
sum = (sum / 2) | 0x8000;
ADC0_MG = sum;
/* End of borrowed code */
}
void loop() {
}
void processData() {
// Wait for signal to reach peak
delayMicroseconds(15);
// DEBUG: Signal HIGH that ADC and then USB will be running
//GPIOC_PDOR |= 1<<5;
// Start ADC
/* DEFAULT
0 AIEN (Interrupt Enable)
0 DIFF (0=single, 1=diff)
1 ADCH (00000=A10 for DIFF=0; 00000=A10+A11 for DIFF=1; See page 98 in documentation)
1
1
1
1
*/
ADC0_SC1A = 0b0000000;
// Wait for ADC
while (!(ADC0_SC1A & ADC_SC1_COCO)) {}
// Retrieve data from ADC
ADC_res = ADC0_RA;
// Send data away
Serial.println( ADC_res );
Serial.send_now();
// Set RESET signal to HIGH for 1 µs
GPIOC_PDOR |= 1; // 1 = 1<<0
delayMicroseconds(1);
// DEBUG: Signal LOW that ADC and USB are done (takes ~40 µs with max cycles and sampling at 16 bit)
// And set RESET signal to LOW
//GPIOC_PDOR &= ~(1<<5 | 1);
GPIOC_PDOR &= ~1;
}
The reset signal opens a MOSFET that short circuits the capacitor holding the signal from the peak detector.
https://imgur.com/a/Qmkuw