Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:88f8e80dc5fd, committed 2014-03-19
- Comitter:
- leysenkobe
- Date:
- Wed Mar 19 10:29:32 2014 +0000
- Child:
- 1:d8a3df4b70f6
- Commit message:
- version 0.1
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ADC.cpp Wed Mar 19 10:29:32 2014 +0000
@@ -0,0 +1,174 @@
+#include "ADC.h"
+#include "mbed.h"
+#include "stdint.h"
+
+Serial bb(USBTX, USBRX);
+
+DigitalIn busy(p26);
+DigitalIn sdout(p22);
+DigitalOut cnvst(p27);
+DigitalOut sdclk(p21);
+
+DigitalOut scin(p23);
+DigitalOut sccs(p25);
+DigitalOut scclk(p24);
+
+ADC::ADC(void)
+{
+ bb.baud(115200);
+
+ this->BIPOLAR = true;
+ this->TEN = true;
+ this->PD = false;
+ this->IMPULSE = true;
+ this->WARP = true;
+ this->OB_2C = true;
+
+ sccs = 1;
+ this->setADC();
+}
+
+ADC::~ADC(void)
+{
+}
+
+//GETTERS
+uint16_t ADC::measure(void)
+{
+ //Hier gaan we de data uitlezen...
+ uint16_t data;
+
+ //1. new data conversion
+ cnvst = 0;
+ wait_us(1);
+
+ //2. nakijken of busy 0 is, of wachten tot hij 0 is.
+ while(busy == 1);
+ cnvst = 1;
+
+ //3. eerste byte vullen
+ for (int i = 15; i >= 8; i--)
+ {
+ sdclk = 1;
+ wait_us(1);
+
+ data |= sdout <<i;
+ sdclk = 0;
+ wait_us(1);
+ }
+
+ //4. tweede byte vullen
+ for (int i = 7; i >= 0; i--)
+ {
+ sdclk = 1;
+ wait_us(1);
+
+ data |= sdout <<i;
+ sdclk = 0;
+ wait_us(1);
+ }
+ return(data);
+}
+bool ADC::getBIPOLAR(void)
+{
+ return(this->BIPOLAR);
+}
+bool ADC::getTEN(void)
+{
+ return(this->TEN);
+}
+bool ADC::getPD(void)
+{
+ return(this->PD);
+}
+bool ADC::getIMPULSE(void)
+{
+ return(this->IMPULSE);
+}
+bool ADC::getWARP(void)
+{
+ return(this->WARP);
+}
+bool ADC::getOB_2C(void)
+{
+ return(this->OB_2C);
+}
+
+
+//SETTERS
+void ADC::setBIPOLAR(bool bipolar)
+{
+ this->BIPOLAR = bipolar;
+ this->setADC();
+}
+void ADC::setTEN(bool ten)
+{
+ this->TEN = ten;
+ this->setADC();
+}
+void ADC::setPD(bool pd)
+{
+ this->PD = pd;
+ this->setADC();
+}
+void ADC::setIMPULSE(bool impulse)
+{
+ this->IMPULSE = impulse;
+ this->setADC();
+}
+void ADC::setWARP(bool warp)
+{
+ this->WARP = warp;
+ this->setADC();
+}
+void ADC::setOB_2C(bool ob_2c)
+{
+ this->OB_2C = ob_2c;
+ this->setADC();
+}
+
+
+//privates
+void ADC::setADC(void)
+{
+ //onze data opmaken
+ char data = 0;
+ data |= this->BIPOLAR << 7;
+ data |= this->TEN << 6;
+ data |= this->PD << 5;
+ data |= this->IMPULSE << 4;
+ data |= this->WARP << 3;
+ data |= this->OB_2C << 2;
+ data |= 0 << 1;
+ data |= 0 << 0;
+
+ //Timing diagrama uitvoeren
+ scclk = 0;
+ //1. SCCS LAAG MAKEN
+ sccs = 0;
+ wait_us(1);
+
+ //2. STARTBIT VERZENDEN
+ scin=1;
+ scclk = 1;
+ wait_us(1);
+
+ scclk = 0;
+ wait_us(1);
+
+ //3. onze data verwerken
+ for (int i = 7; i >= 0; i--)
+ {
+ scin = (data >> i) & 1;
+ scclk = 1;
+ wait_us(1);
+
+ scclk = 0;
+ wait_us(1);
+ }
+
+ //4. SCCS HOOG MAKEN
+ sccs = 1;
+ scclk = 0;
+ wait_us(1);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ADC.h Wed Mar 19 10:29:32 2014 +0000
@@ -0,0 +1,38 @@
+#ifndef ADC_H
+#define ADC_H
+
+#include "stdint.h"
+
+class ADC
+{
+private:
+ bool BIPOLAR;
+ bool TEN;
+ bool PD;
+ bool IMPULSE;
+ bool WARP;
+ bool OB_2C;
+
+ void setADC();
+public:
+ ADC(void);
+ ~ADC(void);
+
+ //GETTERS
+ uint16_t measure(void);
+ bool getBIPOLAR(void);
+ bool getTEN(void);
+ bool getPD(void);
+ bool getIMPULSE(void);
+ bool getWARP(void);
+ bool getOB_2C(void);
+
+ //SETTERS
+ void setBIPOLAR(bool bipolar);
+ void setTEN(bool ten);
+ void setPD(bool pd);
+ void setIMPULSE(bool impulse);
+ void setWARP(bool warp);
+ void setOB_2C(bool ob_2c);
+};
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Amplifier.cpp Wed Mar 19 10:29:32 2014 +0000
@@ -0,0 +1,66 @@
+#include "Amplifier.h"
+#include "mbed.h"
+
+DigitalOut a1(p8);
+DigitalOut a0(p9);
+
+//Constructor & Destructor
+Amplifier::Amplifier(void)
+{
+ enable = false;
+ setAmplification(1);
+}
+Amplifier::~Amplifier(void)
+{
+}
+
+//GETTERS
+bool Amplifier::Enabled(void)
+{
+ return(enable);
+}
+int Amplifier::getAmplification(void)
+{
+ return(amplification);
+}
+
+//SETTERS
+void Amplifier::Enable(void)
+{
+ enable = true;
+}
+void Amplifier::Disable(void)
+{
+ enable = false;
+}
+void Amplifier::setAmplification(int newAmplification)
+{
+ if(newAmplification==1 || newAmplification==10 || newAmplification==100 || newAmplification==1000)
+ {
+ amplification = newAmplification;
+
+ switch (newAmplification)
+ {
+ case 1:
+ a1 = 0;
+ a0 = 0;
+ break;
+ case 10:
+ a1 = 0;
+ a0 = 1;
+ break;
+ case 100:
+ a1 = 1;
+ a0 = 0;
+ break;
+ case 1000:
+ a1 = 1;
+ a0 = 1;
+ break;
+ default:
+ a1 = 0;
+ a0 = 0;
+ break;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Amplifier.h Wed Mar 19 10:29:32 2014 +0000
@@ -0,0 +1,23 @@
+#ifndef AMPLIFIER_H
+#define AMPLIFIER_H
+
+class Amplifier
+{
+private:
+ bool enable;
+ int amplification;
+
+public:
+ Amplifier(void);
+ ~Amplifier(void);
+
+ //GETTERS
+ bool Enabled(void);
+ int getAmplification(void);
+
+ //SETTERS
+ void setAmplification(int newAmplification);
+ void Enable(void);
+ void Disable(void);
+};
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Channel.cpp Wed Mar 19 10:29:32 2014 +0000
@@ -0,0 +1,38 @@
+#include "Channel.h"
+
+//Constructor & Destructor
+Channel::Channel(void)
+{
+ amplification = 1; //standaard heeft het kanaal een gain van 1
+ enable = false; //standaard staat het kanaal uitgeschakeld of disabled
+}
+Channel::~Channel(void)
+{
+}
+
+//GETTERS
+bool Channel::Enabled(void)
+{
+ return(enable);
+}
+int Channel::getAmplification(void)
+{
+ return(amplification);
+}
+
+//SETTERS
+void Channel::Enable(void)
+{
+ enable = true;
+}
+void Channel::Disable(void)
+{
+ enable = false;
+}
+void Channel::setAmplification(int newAmplification)
+{
+ if(newAmplification==1 || newAmplification==10 || newAmplification==100 || newAmplification==1000)
+ {
+ amplification = newAmplification;
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Channel.h Wed Mar 19 10:29:32 2014 +0000
@@ -0,0 +1,23 @@
+#ifndef CHANNEL_H
+#define CHANNEL_H
+
+class Channel
+{
+private:
+ bool enable; //enables or disables the channel
+ int amplification; //the amlification of this channel
+
+public:
+ Channel(void);
+ ~Channel(void);
+
+ //GETTERS
+ bool Enabled(void);
+ int getAmplification(void);
+
+ //SETTERS
+ void setAmplification(int newAmplification);
+ void Enable(void);
+ void Disable(void);
+};
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DAQ.cpp Wed Mar 19 10:29:32 2014 +0000
@@ -0,0 +1,103 @@
+#include "DAQ.h"
+#include "mbed.h"
+
+//Constructor en Destructor
+DAQ::DAQ(void)
+{
+ this->channels = new Channel*[16];
+ this->multiplexer = new Multiplexer();
+ this->amplifier = new Amplifier();
+ this->adc = new ADC();
+ this->initialized = false;
+
+ for (int i = 0; i < 16; i++)
+ {
+ channels[i] = new Channel();
+ }
+}
+DAQ::~DAQ(void)
+{
+ for (int i = 0; i < 16; i++)
+ {
+ delete channels[i];
+ }
+ delete [] channels;
+ delete multiplexer;
+ delete amplifier;
+ delete adc;
+}
+
+//GETTERS
+Measurement* DAQ::measure(void)
+{
+ Measurement *measurement = new Measurement();
+ for (int i = 0; i < 16; i++)
+ {
+ if(channels[i]->Enabled())
+ {
+ //amplifier op de juiste waarde zetten
+ amplifier->setAmplification(channels[i]->getAmplification());
+ wait_us(1);
+
+ //multiplexer aanzetten
+ multiplexer->Enable();
+ wait_us(1);
+
+ //ADC uitlezen
+ measurement->Enable(i);
+ measurement->setPunt(i,adc->measure());
+ wait_us(1);
+
+ //multiplexer uitzetten
+ multiplexer->Disable();
+ }
+ }
+ return measurement;
+}
+int DAQ::getChannelGain(int channel)
+{
+ if(channel>=0 && channel<16)
+ {
+ return(channels[channel]->getAmplification());
+ }
+ return -1;
+}
+bool DAQ::ChannelEnabled(int channel)
+{
+ if(channel>=0 && channel<16)
+ {
+ return(channels[channel]->Enabled());
+ }
+ return false;
+}
+bool DAQ::Initialized(void)
+{
+ return(initialized);
+}
+
+//SETTERS
+void DAQ::setChannelGain(int channel,int gain)
+{
+ if(channel>=0 && channel<16)
+ {
+ channels[channel]->setAmplification(gain);
+ }
+}
+void DAQ::enableChannel(int channel)
+{
+ if(channel>=0 && channel<16)
+ {
+ channels[channel]->Enable();
+ }
+}
+void DAQ::disableChannel(int channel)
+{
+ if(channel>=0 && channel<16)
+ {
+ channels[channel]->Disable();
+ }
+}
+void DAQ::setInitialized(bool init)
+{
+ initialized = init;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DAQ.h Wed Mar 19 10:29:32 2014 +0000
@@ -0,0 +1,38 @@
+#ifndef DAQ_H
+#define DAQ_H
+
+//INCLUDES
+#include "Channel.h"
+#include "Multiplexer.h"
+#include "Amplifier.h"
+#include "ADC.h"
+#include "Measurement.h"
+
+
+class DAQ
+{
+private:
+ Channel **channels;
+ Multiplexer *multiplexer;
+ Amplifier *amplifier;
+ ADC *adc;
+ bool initialized;
+
+public:
+ DAQ(void);
+ ~DAQ(void);
+
+ //GETTERS
+ Measurement* measure(void);
+ int getChannelGain(int channel);
+ bool ChannelEnabled(int channel);
+ bool Initialized(void);
+
+ //SETTERS
+ void setChannelGain(int channel,int gain);
+ void enableChannel(int channel);
+ void disableChannel(int channel);
+ void setInitialized(bool init);
+
+};
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Measurement.cpp Wed Mar 19 10:29:32 2014 +0000
@@ -0,0 +1,60 @@
+#include "Measurement.h"
+
+Measurement::Measurement(void)
+{
+ this->punten = new int[16];
+ this->puntEnabled = new bool[16];
+
+ for (int i = 0; i < 16; i++)
+ {
+ this->punten[i] = 0;
+ this->puntEnabled[i] = false;
+ }
+}
+
+Measurement::~Measurement(void)
+{
+ delete [] punten;
+ delete [] puntEnabled;
+}
+
+//GETTERS
+int Measurement::getPunt(int channel)
+{
+ if(channel>=0 && channel<16)
+ {
+ return(this->punten[channel]);
+ }
+ return(-1);
+}
+bool Measurement::Enabled(int channel)
+{
+ if(channel>=0 && channel<16)
+ {
+ return(this->puntEnabled[channel]);
+ }
+ return(false);
+}
+
+//SETTERS
+void Measurement::setPunt(int channel,int punt)
+{
+ if(channel>=0 && channel<16)
+ {
+ this->punten[channel] = punt;
+ }
+}
+void Measurement::Enable(int channel)
+{
+ if(channel>=0 && channel<16)
+ {
+ this->puntEnabled[channel] = true;
+ }
+}
+void Measurement::Disable(int channel)
+{
+ if(channel>=0 && channel<16)
+ {
+ this->puntEnabled[channel] = false;
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Measurement.h Wed Mar 19 10:29:32 2014 +0000
@@ -0,0 +1,23 @@
+#ifndef MEASUREMENT_H
+#define MEASUREMENT_H
+
+class Measurement
+{
+private:
+ int *punten;
+ bool *puntEnabled;
+
+public:
+ Measurement(void);
+ ~Measurement(void);
+
+ //GETTERS
+ int getPunt(int channel);
+ bool Enabled(int channel);
+
+ //SETTERS
+ void setPunt(int channel,int punt);
+ void Enable(int channel);
+ void Disable(int channel);
+};
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Multiplexer.cpp Wed Mar 19 10:29:32 2014 +0000
@@ -0,0 +1,95 @@
+#include "Multiplexer.h"
+#include "mbed.h"
+
+DigitalOut sync(p5);
+DigitalOut sclk_mux(p6);
+DigitalOut din(p7);
+
+#define ENABLE 7
+#define CSA 6
+#define CSB 5
+#define UNUSED_BIT 4
+#define A3 3
+#define A2 2
+#define A1 1
+#define A0 0
+
+//Constructor & Destructor
+Multiplexer::Multiplexer(void)
+{
+ sclk_mux = 0;
+ sync = 1;
+ din = 0;
+
+ enable = false;
+ channel = 0;
+}
+Multiplexer::~Multiplexer(void)
+{
+}
+
+//GETTERS
+bool Multiplexer::Enabled(void)
+{
+ return(enable);
+}
+int Multiplexer::getChannel(void)
+{
+ return(channel);
+}
+
+//SETTERS
+void Multiplexer::Enable(void)
+{
+ enable = true;
+ Update();
+}
+void Multiplexer::Disable(void)
+{
+ enable = false;
+ Update();
+}
+void Multiplexer::setChannel(int newChannel)
+{
+ if(newChannel>=0 && newChannel<16)
+ {
+ channel = newChannel;
+ Update();
+ }
+}
+
+//updater
+void Multiplexer::Update(void)
+{
+
+ //onze data opmaken
+ char data = 0;
+ data |= !enable << ENABLE;
+ data |= 0 << CSA;
+ data |= 0 << CSB;
+ data |= 1 << UNUSED_BIT;
+ data |= channel;
+
+ //Timing diagrama uitvoeren
+ sclk_mux = 1;
+ wait_us(1);
+
+ sclk_mux = 0;
+ wait_us(1);
+
+ sync = 0;
+ for (int i = 7; i >= 0; i--)
+ {
+ sclk_mux = 1;
+ din = (data >> i) & 1;
+ wait_us(1);
+
+ sclk_mux = 0;
+ wait_us(1);
+ }
+
+ //terug standaard waarden
+ sclk_mux = 0;
+ sync = 1;
+ din = 0;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Multiplexer.h Wed Mar 19 10:29:32 2014 +0000
@@ -0,0 +1,25 @@
+#ifndef MULTIPLEXER_H
+#define MULTIPLEXER_H
+
+class Multiplexer
+{
+private:
+ bool enable;
+ int channel;
+
+ //Update the multiplexer
+ void Update(void);
+public:
+ Multiplexer(void);
+ ~Multiplexer(void);
+
+ //GETTERS
+ bool Enabled(void);
+ int getChannel(void);
+
+ //SETTERS
+ void setChannel(int newChannel);
+ void Enable(void);
+ void Disable(void);
+};
+#endif
\ No newline at end of file