Another quick update. Finally printed updated box with T-Glase. Took a few attempts to get it to stick to plate of 3d printer...
It may not look as clean as black, but what is fun is how it works with light. That is I propped the older board into it and you can see how the neopixel changes the box:
Code wise, I verified that the new boards TFT backlight support is working. That is I can now control the brightness of the backlight. I have it dim down every 10 seconds until a minimum and go back to full brightness if I touch the display.
Also started playing again with the Analog Input from the current sensors. Up till now I have been using an Interval timer to do the sensor reading. Each interval I read in the previous values for two Analog Reads, and then issue the start of the other two... But was wondering about trying DMA instead. So I tried the ADC ringBufferDMA test, I edited it to use one of the Analog pins I was using and it did not appear to work (I verified that the pin I choose to test was on ADC0 as the test was setup...
Also I really did not need ring buffer as I just want to read in so many samples at some interval. In my case thought if the Interval was set to (60*50), that would give me at 60hz AC, 50 samples per cycle, which should be sufficient. And if I read 100 samples, that should give me two complete cycles... I thought I could try something like this, and then alternate between the two pins on each ADC...
So I hacked up a test app, that so far just tries one of the 4, using DMA and PDB... Still needs cleaning up.
Code:
#include <ADC.h>
#include <DMAChannel.h>
#define BUFFER_SIZE 100
ADC adc;
volatile DMAMEM uint16_t adc0_buf[BUFFER_SIZE]; // buffer 1...
volatile uint8_t adc0_busy = 0;
DMAChannel adc0_dma;
extern void adc0_dma_isr(void);
void setup() {
while (!Serial && millis() < 3000) ;
Serial.begin(115200);
Serial.println("Test DMA Analog Read");
// Initialize the
adc.setAveraging(4);
adc.setResolution(12);
adc.setConversionSpeed(ADC_CONVERSION_SPEED::MED_SPEED, ADC_0); // change the conversion speed
adc.setSamplingSpeed(ADC_SAMPLING_SPEED::MED_SPEED, ADC_0); // change the sampling speed
// Lets setup Analog 0 dma
adc0_dma.source((volatile uint16_t&)ADC0_RA);
adc0_dma.destinationBuffer(adc0_buf, sizeof(adc0_buf));
adc0_dma.triggerAtHardwareEvent (DMAMUX_SOURCE_ADC0);
adc0_dma.interruptAtCompletion();
adc0_dma.disableOnCompletion();
adc0_dma.attachInterrupt(&adc0_dma_isr);
NVIC_DISABLE_IRQ(IRQ_PDB); // we don't want or need the PDB interrupt
Serial.printf("First Read of A14: %d\n", adc.analogRead(A14));
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Enter any key to run sample");
while (Serial.read() == -1) ;
while (Serial.read() != -1) ;
Serial.println("Start Sample");
uint32_t start_time = millis();
adc0_busy = 1;
memset((void*)adc0_buf, 0, sizeof(adc0_buf));
adc0_dma.enable();
adc.enableDMA(ADC_0);
adc.adc0->startPDB(60 * 50);
adc0_dma.enable();
while (adc0_busy) ;
adc.adc0->stopPDB();
Serial.printf("Sample completed: %d\n", millis()-start_time);
for (int i = 0; i < BUFFER_SIZE; i++) {
Serial.printf("%4u ", adc0_buf[i]);
if ((i % 20) == 19) Serial.println();
}
Serial.println();
}
void adc0_dma_isr(void)
{
adc0_busy = false;
adc0_dma.clearInterrupt();
adc0_dma.clearComplete();
}
But it does show some promise. That is I a sensor setup on power cord that I have a solder station plugged into.
If I run the sample and power turned off:
Code:
Enter any key to run sample
Start Sample
Sample completed: 33
2025 2025 2025 2026 2027 2025 2027 2027 2026 2025 2025 2025 2027 2024 2025 2025 2027 2024 2025 2026
2026 2025 2026 2026 2024 2025 2027 2026 2026 2023 2025 2025 2026 2024 2025 2025 2024 2024 2025 2024
2024 2025 2025 2025 2025 2024 2026 2025 2025 2024 2026 2025 2025 2025 2025 2025 2026 2025 2025 2025
2024 2025 2025 2025 2025 2026 2025 2025 2024 2025 2025 2024 2024 2026 2025 2024 2024 2027 2026 2026
2024 2024 2025 2025 2024 2025 2025 2025 2024 2025 2024 2025 2025 2025 2025 2026 2024 2025 2025 2024
Now with station turned on:
Code:
Enter any key to run sample
Start Sample
Sample completed: 33
1986 1986 1989 1991 1991 1986 1992 1996 1999 2006 2012 2019 2029 2034 2039 2046 2051 2054 2056 2059
2063 2062 2063 2064 2067 2065 2062 2062 2061 2058 2060 2057 2055 2052 2047 2040 2033 2024 2017 2009
2005 1999 1996 1992 1987 1985 1985 1984 1987 1986 1984 1987 1989 1990 1992 1992 1992 1998 1997 2006
2011 2019 2029 2035 2041 2046 2052 2055 2057 2060 2061 2063 2064 2063 2064 2065 2063 2061 2061 2060
2059 2058 2056 2052 2048 2041 2033 2026 2016 2010 2007 2000 1996 1991 1988 1986 1986 1986 1986 1986
Still a few more things to try with sample code here:
a) Detect if power is on/off OR how much power: Could do simple test that if the code looks pretty flat (no highs or lows) off or (max-min) > threshold ON... Or could do some form of RMS calculation...
b) Setup to read both ADCs at the same time...
c) cleanup - Don't like I am simply using straight analogRead to prime the register for correct channel....
d) Setup to alternate between two groups. Read group 1 in, initiate group 2, process group 1 data...
Or just continue the old way...