Things are looking very good indeed, except for speed of course. I've implemented:
- node structs
- function pointers and pointer lookup
- matrix array calculation
- DAC output to 14 bit SPI DAC (MAX544
- input buffer reading and outputbuffer writing
In addition I've coded the following node functions:
- Sum
- Invert
- Invert each side (positive stays positive etc)
- Ramp (but without proper interval calculation)
- Delay line (allows loops in network)
- Input
- Output
Next up should be
- Timers for constant output to DAC
- SPI input for controllers (but that is not possible without a second SPI module)
- JSON parsing
- Table lookup for tuning and exponentialization.
Here is the first output from the OMM - the frequency is too low to get a good image on the scope:
A few specifics on the SPI and the DAC:
The DAC accepts a maximum SPI speed of 10MHz. In the tests I did, I ran the SPI at F_osc/4, which means 5MHz when the oscillator frequency is 20MHz. I achieved what I think is a sample rate of about 89kHz but that is without any calculations between samples. In practice then, it seems the maximum DAC rate is slightly less than 180kHz when running the SPI clock at 10MHz (from the PIC that is, it is entirely possible that you can achieve higher speeds otherwise).
Here is the code for the DAC tryout:
void writeToDac(){ | |
unsigned int dacout; | |
/**** DAC ****/ | |
SPI1_Init(); | |
TRISC = 0; //trisc as output | |
LATC.B0 = 1; | |
dacout=0; | |
// The following code runs at about 89kHz. | |
while(1){ | |
LATC.B0 = 0; //must write directly to latch (didn't work with PORTC.B0!) | |
SPI1_write(hi(dacout)); | |
SPI1_write(lo(dacout) & 0b11111100); | |
LATC.B0 = 1; //latches values in DAC. | |
dacout += 2048; | |
} | |
} |
The first time I got the DAC working it looked like this:
The visible steps are because I chose to use only 32 steps to speed things up and to see what is happening. After removing all delays and maximizing the speed it looks like this:
Here is the SPI clock btw:
No comments:
Post a Comment