I'm doing a project that can draw an analog clock on the XY mode of an oscilloscope using the Atmega88-20PU with the default clock frequency of 1MHz. To display the image I use a PWM signal applied to a low-pass filter (working as a DAC) for channels 1 and 2 of the oscilloscope.
The problem I'm facing is that, even though the PWM signals are being generated correctly, the output of the low-pass filter isn't working correctly. Just for testing purposes, I tried drawing a simple rectangle (4 vertices) but it only displays 1 vertex.
My intuition tells me that the problem might be that the clock frequency is too low, or that the values of the RC low-pass filter are not the most appropriate (R = 4.7KOhm, C = 100nF).
After some research, I found another similar project where the creator used the same RC values, but the code was running on a 16MHz µC (https://www.youtube.com/watch?v=nlCADL5_g-I).
Here is some of my code:
void Clock::display() volatile { for(uint8_t i = 0; i < 4; i++) { display_point(points[i]); _delay_us(point_delay); } } void Clock::display_point(Point point) volatile { OCR2A = point.x; OCR2B = point.y; } void Clock::calc_points() volatile { points = (Point *) malloc(4 * sizeof(Point)); points[0].x = 20; points[0].y = 20; points[1].x = 100; points[1].y = 20; points[2].x = 100; points[2].y = 200; points[3].x = 20; points[3].y = 200; } clock.display() is called every frame of the main loop.
clock.calc_points() is called every 1 second (on an ISR).
EDIT #1: I have already slowly tested the code and the PWMs generate correctly accordingly to the points I tell it to run. Therefore the problem must only be on the low-pass filter.
EDIT #2: The frequency of the PWM waves is f_clk / 256 = 3.9 kHz. What should be the value of the cutoff frequency of the filter?
EDIT #3: I added a 20 MHz crystal oscillator (PWM frequency of 78 kHz) and changed the filter to have a cutoff frequency of about 200 Hz and got the following output (channel 1 shows one of the PWM outputs and channel 2 shows the filter of that same PWM):



points? If that is called every second, where is itfreed \$\endgroup\$new []anddelete []too if you're writing c++ \$\endgroup\$