Hello everyone.
I am working on a teensy 3.6 based oscilloscope. I know that it will be limited but in the near time I am not going to need anything more than the 1MHz range.
I already got a working code, which gives about 800KSps:
(problematic serial function in the bottom)
With arduino's serial monitor the output is a fast sequence of mirrored ????? symbols. (the ADC input is tied to 3.3V)
However when I started working on a PC plotting software (in C#) the output was this sequence:
255
0
255
0
255
and so on...
After getting tired of programming by myself, I turned to a free, open source software called SerialPlot.
The result there is the same:
If I tie the ADC input to 0V the output is jumping between 0 and 1 (no caps used, so I know it's okay that I get 1).
Same thing happens with a 1/2 voltage divider, output is changing between 0 and ~127.
The SerialPlot software settings are:
- No parity
- 8 bits
- 1 stop bit
- No Flow Control
Encoding:
Simple Binary
- N.O. Channels: 1
- Number type: uint8
- Endianness: Little Endian
Do you know what the problem could be? Encoding incompatibility? bad sketch code?
Thanks in Advance,
128ITSH
I am working on a teensy 3.6 based oscilloscope. I know that it will be limited but in the near time I am not going to need anything more than the 1MHz range.
I already got a working code, which gives about 800KSps:
(problematic serial function in the bottom)
Code:
//This sketch is a try to see how many samples can get transmitted from the teensy in one second
//samples are running for one second, then stopped and number of samples is printed
#include "ADC.h"
#include "RingBufferDMA.h"
const int readPin = A9;
ADC *adc = new ADC(); // adc object
//dma buffer size. above this seem to have problems with the serial monitor.
const int buffer_size = 256;
//dma buffer
DMAMEM static volatile int16_t __attribute__((aligned(buffer_size + 0))) buffer1[buffer_size];
// use dma with ADC0
RingBufferDMA *dmaBuffer = new RingBufferDMA(buffer1, buffer_size, ADC_0);
//timing variables
bool _start1 = false;
unsigned long beforeMillis = 0;
const unsigned long interval1 = 1000;
long nSamples = 0;
void setup() {
pinMode(readPin, INPUT); //pin 23 single ended
Serial.begin(2000000);
//ADC0
adc->setAveraging(1); // default is 4, we want as fast as possible
adc->setResolution(8); // set bits of resolution
adc->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_HIGH_SPEED);
//library docs say ADC_CONVERSION_SPEED::VERY_HIGH_SPEED is out of specs. use HIGH_SPEED instead for safer operation
adc->setConversionSpeed(ADC_CONVERSION_SPEED::HIGH_SPEED);
// enable DMA
adc->enableDMA(ADC_0);
dmaBuffer->start(&dmaBuffer_isr);
while(!Serial.available()){}
delay(100);
adc->startContinuous(readPin);
beforeMillis = millis();
_start1 = true;
}
//loop only checks if 1 second elapsed from the start, if yes, set _start1 false and stop the adc convertion
void loop()
{
if (_start1)
{
unsigned long _now = millis();
if (_now - beforeMillis > interval1)
{
adc->stopContinuous(); //stop converting
_start1 = false;
Serial.println(""); //print results
Serial.println("ended");
Serial.print("Samples: ");
Serial.println(nSamples);
}
}
}
void dmaBuffer_isr() //called everytime the buffer is full
{
if(Serial.availableForWrite())
{
Serial.write((uint8_t *)buffer1, buffer_size);
nSamples= nSamples+buffer_size;
}
dmaBuffer->dmaChannel->clearInterrupt();
}
With arduino's serial monitor the output is a fast sequence of mirrored ????? symbols. (the ADC input is tied to 3.3V)
However when I started working on a PC plotting software (in C#) the output was this sequence:
255
0
255
0
255
and so on...
After getting tired of programming by myself, I turned to a free, open source software called SerialPlot.
The result there is the same:
If I tie the ADC input to 0V the output is jumping between 0 and 1 (no caps used, so I know it's okay that I get 1).
Same thing happens with a 1/2 voltage divider, output is changing between 0 and ~127.
The SerialPlot software settings are:
- No parity
- 8 bits
- 1 stop bit
- No Flow Control
Encoding:
Simple Binary
- N.O. Channels: 1
- Number type: uint8
- Endianness: Little Endian
Do you know what the problem could be? Encoding incompatibility? bad sketch code?
Thanks in Advance,
128ITSH