Again, some sample waveforms. First, a sine wave at 10kHz. Because of how I implemented it, using delay_microseconds, the fastest sine wave I could get with a non-zero delay was 32kHz. Removing the delay statement altogether got it to 153kHz.
You can see it is starting to round off, presumably due to capacitance. At 300kHz, this is more pronounced:
Finally, I took out all the delays and output only the top 3 bits, to see how fast I could drive it. The waveform is pretty nasty...
... but it is at around 25MHz.
For the next step, I want to use the 32 bit port, but more especially to use the real power of the XMOS chip, but setting precise times for setting the values on the ports.
The code:
#include <math.h> #include <xs1.h> // Ports for top 4, middle 4 and lowest bits. port top4 = XS1_PORT_4C; port mid4 = XS1_PORT_4D; port bot1 = XS1_PORT_4E; int max_value = 511; double freq = 300000; // Approximate #define NSAMPLES 64 int samples[NSAMPLES]; #define PI 3.14156 void set(int value) { top4 <: ((value >> 5) & 0x0f); //mid4 <: ((value >> 1) & 0x0f); //bot1 <: (value & 0x01); } int main(void) { #if 0 // Sampled waveform for (int i = 0; i < NSAMPLES; ++i) { // Triangle // samples[i] = (max_value * i)/NSAMPLES; // Sine samples[i] = (short)(max_value * (1 + sin((float)i * 2 * PI / NSAMPLES))/2); } int delay_us = (int)((1000000.0/freq)/NSAMPLES); #else // Square wave //int delay_us = (int)((1000000.0/freq)/2); #endif while (1) { #if 0 // Sampled waveforms for (int i = 0; i < NSAMPLES; ++i) { set(samples[i]); delay_microseconds(delay_us); } #else // Square wave //set(0); top4 <: 0; //delay_microseconds(delay_us); top4 <: 0xf; //set(511); //delay_microseconds(delay_us); #endif } return 0; }
No comments:
Post a Comment