Hello Everyone
Im an arduino/teensy beginer. I wanted to run a simple signal smoothing algorithm (https://github.com/asheeshr/Microsmooth/blob/master/README.md) on the Teensy 3.6 and output it using the built in DAC. Unfortunately I just get a consistent 3.3V on the DAC pins. Is this the DAC being saturated by the values Im trying to feed into it? If yes how do I adjust ADC values so that they are in range for the DAC? If Im doing something else wrong please let me know.
(I can serial print the signal from the ADC so I now the input an smoothing should be working)
My Code:
#include <microsmooth.h>
#include <ADC.h>
const int readPin = A0; // ADC0
ADC *adc = new ADC(); // adc object
uint16_t *history;
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
pinMode(readPin, INPUT);
//pinMode(A22, OUTPUT);
//pinMode(A21, OUTPUT);
analogWriteResolution(12);
Serial.begin(9600);
adc->setAveraging(16); // set number of averages
adc->setResolution(16); // set bits of resolution
adc->setConversionSpeed(ADC_CONVERSION_SPEED::MED_SPEED); // change the conversion speed
// it can be any of the ADC_MED_SPEED enum: VERY_LOW_SPEED, LOW_SPEED, MED_SPEED, HIGH_SPEED or VERY_HIGH_SPEED
adc->setSamplingSpeed(ADC_SAMPLING_SPEED::MED_SPEED); // change the sampling speed
adc->startContinuous(readPin, ADC_0);
history = ms_init(EMA);
if(history == NULL) Serial.println("No memory");
delay(1);
}
int value = 0;
void loop()
{
value = (uint16_t)adc->analogReadContinuous(ADC_0);
int processed_value = ema_filter(value, history);
analogWrite(A22, value);
analogWrite(A21, processed_value);
}
Im an arduino/teensy beginer. I wanted to run a simple signal smoothing algorithm (https://github.com/asheeshr/Microsmooth/blob/master/README.md) on the Teensy 3.6 and output it using the built in DAC. Unfortunately I just get a consistent 3.3V on the DAC pins. Is this the DAC being saturated by the values Im trying to feed into it? If yes how do I adjust ADC values so that they are in range for the DAC? If Im doing something else wrong please let me know.
(I can serial print the signal from the ADC so I now the input an smoothing should be working)
My Code:
#include <microsmooth.h>
#include <ADC.h>
const int readPin = A0; // ADC0
ADC *adc = new ADC(); // adc object
uint16_t *history;
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
pinMode(readPin, INPUT);
//pinMode(A22, OUTPUT);
//pinMode(A21, OUTPUT);
analogWriteResolution(12);
Serial.begin(9600);
adc->setAveraging(16); // set number of averages
adc->setResolution(16); // set bits of resolution
adc->setConversionSpeed(ADC_CONVERSION_SPEED::MED_SPEED); // change the conversion speed
// it can be any of the ADC_MED_SPEED enum: VERY_LOW_SPEED, LOW_SPEED, MED_SPEED, HIGH_SPEED or VERY_HIGH_SPEED
adc->setSamplingSpeed(ADC_SAMPLING_SPEED::MED_SPEED); // change the sampling speed
adc->startContinuous(readPin, ADC_0);
history = ms_init(EMA);
if(history == NULL) Serial.println("No memory");
delay(1);
}
int value = 0;
void loop()
{
value = (uint16_t)adc->analogReadContinuous(ADC_0);
int processed_value = ema_filter(value, history);
analogWrite(A22, value);
analogWrite(A21, processed_value);
}