Simple library to use the TI ADC0848 with the MBED Ports Library. This Library can be used either in polling or interrupt modes.

Files at this revision

API Documentation at this revision

Comitter:
mr63
Date:
Mon Oct 07 21:49:38 2013 +0000
Commit message:
Simple library to use the TI ADC0848 with the MBED Ports Library. This Library can be used either in polling or interrupt modes.

Changed in this revision

ADC0848.cpp Show annotated file Show diff for this revision Revisions of this file
ADC0848.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r a76d9079d07b ADC0848.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADC0848.cpp	Mon Oct 07 21:49:38 2013 +0000
@@ -0,0 +1,93 @@
+#include "ADC0848.h"
+
+
+unsigned char A2DValue[8] = {0,0,0,0,0,0,0,0};
+
+//ADC0848 Class Constructor for polling A2D using int ADC0848::Poll_A2D(unsigned char Channel)
+ADC0848::ADC0848(PinName pin1, PinName pin2, PinName pin3, PinName pin4, PinName pin5, PinName pin6, PinName pin7, PinName pin8, PinName pin9, PinName pin10, PinName pin11) 
+								:_DataBus(pin1,pin2,pin3,pin4,pin5,pin6,pin7,pin8), _WR(pin9), _RD(pin10),_intS(NC),_intP(pin11)
+{
+	_WR = 1;
+	_RD = 1;
+  _intP.mode(PullUp);	
+	_scan = false;
+}
+//ADC0848 Class Constructor for scanning all channels of continues using interrupts A2D vales can be using int ADC0848::GetA2D(unsigned char Channel)
+//char ADC0848::Start_Scan() must be called to start a conversion
+ADC0848::ADC0848(PinName pin1, PinName pin2, PinName pin3, PinName pin4, PinName pin5, PinName pin6, PinName pin7, PinName pin8, PinName pin9, PinName pin10, PinName pin11,bool Scan) 
+								:_DataBus(pin1,pin2,pin3,pin4,pin5,pin6,pin7,pin8), _WR(pin9), _RD(pin10),_intS(pin11),_intP(NC), _scan(Scan)
+{
+	_WR = 1;
+	_RD = 1;
+  _intS.mode(PullUp);
+	_intS.fall_add(this,&ADC0848::DIGI_IO_ISR);		
+}
+
+
+void ADC0848::DIGI_IO_ISR() // ISR used if in scanning mode to scan the 8 channels of the ADC  The values are stored in unsigned char A2DValue[8]
+{
+	static unsigned char channel_num=0;
+  _DataBus.input();
+	_RD = 0;
+	A2DValue[channel_num] = _DataBus;
+	_RD = 1;
+	channel_num++;
+	if(channel_num > 7)
+		 channel_num=0;
+	_DataBus.output();
+	_DataBus=0x08 | channel_num;
+	_WR = 0;
+	_WR = 1;
+}
+
+int ADC0848::Start_Scan()  
+{
+ if(_scan)
+ {
+	_DataBus.output(); //start 1st conversion 
+	_DataBus=0x08;
+	_WR = 0;
+	_WR = 1;
+	return(1);
+ }
+ else
+ {
+	return(-1);
+ }
+}
+
+int ADC0848::GetA2D(unsigned char Channel)  //Returns the Value of the the channel requested when in scanning mode.  If not in scanning mode the function returns -1
+{
+		if(_scan)
+		{
+	   return((int)A2DValue[Channel]);
+		}
+		else
+		{
+			return(-1);
+		}
+}
+
+int ADC0848::Poll_A2D(unsigned char Channel) //Returns the Value of the the channel requested when in polling mode.  If not in polling mode the function returns -1
+{
+	if(!_scan)
+	{
+		char data;
+		_DataBus.output();
+		_DataBus=0x08 | Channel;
+		_WR = 0;
+		_WR = 1;
+		while(_intP);
+		_DataBus.input();
+		_RD = 0;
+		data = _DataBus;
+		_RD = 1;
+		return ((int)data);
+	}
+	else
+	{
+		return(-1);
+	}
+}
+
+
diff -r 000000000000 -r a76d9079d07b ADC0848.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADC0848.h	Mon Oct 07 21:49:38 2013 +0000
@@ -0,0 +1,36 @@
+#include "mbed.h"
+
+
+class ADC0848 {
+public:					//Strobe			//CLK					//Data
+ 
+ ADC0848(PinName pin1, PinName pin2, PinName pin3, PinName pin4, PinName pin5, PinName pin6, PinName pin7, PinName pin8, PinName pin9, PinName pin10, PinName pin11);
+ ADC0848(PinName pin1, PinName pin2, PinName pin3, PinName pin4, PinName pin5, PinName pin6, PinName pin7, PinName pin8, PinName pin9, PinName pin10, PinName pin11 , bool Scan); 
+
+	int Start_Scan();
+	int GetA2D(unsigned char Channel);
+	int Poll_A2D(unsigned char Channel);
+
+
+private:
+
+	BusInOut _DataBus;
+  DigitalOut 		_WR;
+	DigitalOut 		_RD;
+  InterruptIn  _intS;
+	DigitalIn _intP;
+  bool _scan;
+
+	 	void DIGI_IO_ISR(void);
+
+
+};
+
+ 
+
+
+
+
+
+
+
diff -r 000000000000 -r a76d9079d07b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Oct 07 21:49:38 2013 +0000
@@ -0,0 +1,32 @@
+#include "mbed.h"
+#include "ADC0848.h"
+
+Serial pc(USBTX, USBRX); // tx, rx
+//ADC0848 A2D(p13,p14,p15,p16,p17,p18,p19,p20,p12,p10,p11);//using polling constructor
+ADC0848 A2D(p13,p14,p15,p16,p17,p18,p19,p20,p12,p10,p11,true);//using scanning constructor
+int main()
+{
+	A2D.Start_Scan();
+	while(1)
+	{
+// 		pc.printf("Value0= %u\n",A2D.Poll_A2D(0));
+// 		pc.printf("Value1= %u\n",A2D.Poll_A2D(1));
+// 		pc.printf("Value2= %u\n",A2D.Poll_A2D(2));
+// 		pc.printf("Value3= %u\n",A2D.Poll_A2D(3));
+// 		pc.printf("Value4= %u\n",A2D.Poll_A2D(4));
+//  	pc.printf("Value5= %u\n",A2D.Poll_A2D(5));
+//    pc.printf("Value6= %u\n",A2D.Poll_A2D(6));
+//  	pc.printf("Value7= %u\n",A2D.Poll_A2D(7));
+		pc.printf("Value0= %u\n",A2D.GetA2D(0));
+		pc.printf("Value1= %u\n",A2D.GetA2D(1));
+		pc.printf("Value2= %u\n",A2D.GetA2D(2));
+		pc.printf("Value3= %u\n",A2D.GetA2D(3));
+		pc.printf("Value4= %u\n",A2D.GetA2D(4));
+ 		pc.printf("Value5= %u\n",A2D.GetA2D(5));
+ 		pc.printf("Value6= %u\n",A2D.GetA2D(6));
+ 		pc.printf("Value7= %u\n",A2D.GetA2D(7));
+ 		wait(1);
+	}
+}
+
+