ADC is working, atleast for a 1 Hz sine wave…

[ Thiyagarajan’s e2e code ]

Using GPAIN0 (channel 1)

Capture

The signal generator doesn’t work single ended. Need both GPAIN0 and GND. Also, negative voltages just get clipped (a fine diode in the system!)

Now to figure out a way for actually sampling at the rates the SAR ADC is capable of. These samples are way too slow because I’m printing to console. fprintf() doesn’t seem to work. DMA events are probably the way to go, and we have to use the LCD on the board!

#include <usbstk5515.h>
#include <stdio.h>
#include <sar.h> //defines the register addresses (pointer stuff!)

void adc_init2() {
	*SARCTRL= 0
			| ( 0 << 15 ) 	// ADC conversion start (0 is no conversion)
			| ( 1 << 12 ) 	// select Channel 1 (try 0, 2, and 4)
			| ( 0 << 11 )	// 0 - Normal mode, 1 - multi channel mode
			| ( 0 << 10 ); 	// back to back conversions

	*SARCLKCTRL = 149; 		// 1Mhz Clock

	*SARPINCTRL = 0
			| ( 1 << 14 ) 	// 12-15 always of data register
			| ( 1 << 13 ) 	// power up bias
			| ( 1 << 12 ) 	// analog power to sar
			| ( 1 << 8 ) 	// Ref V set to VDD_ANA (not bandgap)
			| ( 1 << 1 ); 	// 1: ch0 grounded , 0 ch0 is not grounded GNDON

	*SARGPOCTRL = 0; /*
		        | ( 1 << 3 ) // GPAIN3 Driven high
			| ( 1 << 2 ) // GPAIN2 Driven high
			| ( 1 << 1 ) // GPAIN1 Driven high
			| ( 1 << 0 ); // GPAIN0 Driven high
		 */
}

void main (void)
 {
	int i;

	USBSTK5515_init();
	adc_init2();

	*SARCTRL |= 0x8000; // start ADC conversion

	for(i=0;i<=100000;i++) {
		//printf("we see...");
		if((*SARDATA & 0x8000)==1){
			printf("ADCbusy: %d\n", 0x8000 & *SARDATA);
		} else printf("%d\n", 0x3FF & *SARDATA); //DATA is bits 0-9
	}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s