// Start converting the enabled channels void AnalogInStartConversion(uint32_t channels) { #if SAM3XA || SAM4S // Clear out any existing conversion complete bits in the status register for (uint32_t chan = 0; chan < 16; ++chan) { if ((adc_get_status(ADC) & (1 << chan)) != 0) { (void)adc_get_channel_value(ADC, static_cast<adc_channel_num_t>(chan)); } } adc_start(ADC); #elif SAM4E channels &= activeChannels; if ((channels & 0x0000FFFF) != 0) { StartConversion(AFEC0); } if ((channels & 0xFFFF0000) != 0) { StartConversion(AFEC1); } #elif SAME70 channels &= activeChannels; if ((channels & 0x000003FF) != 0) { StartConversion(AFEC0); } if ((channels & 0x003FF800) != 0) { StartConversion(AFEC1); } #endif }
bool DS1820Sensor::Update(unsigned long clock) { if (!m_initialized) { return false; } if (clock < m_conversion_start_clock) { // overflow of clock m_conversion_start_clock = 0; } unsigned long delta = clock - m_conversion_start_clock; if (!m_converting) { // we're not converting, and it is time to start m_converting = true; m_conversion_start_clock = clock; StartConversion(); } else if (m_converting && (clock - m_conversion_start_clock) >= 1000) { // we're converting and it is time to fetch m_converting = false; if (FetchConversion()) { m_temp_is_valid = true; } else { m_temp_is_valid = false; } return true; } else { // we're either in the middle of a conversion, or it is too soon to start // the next cycle. } return false; }
void Adc_t::StartMeasurement() { while(BitIsSet(ADC1->CR, ADC_CR_ADSTP)); // Wait until stop is completed // DMA dmaStreamSetMemory0(ADC_DMA, IBuf); dmaStreamSetTransactionSize(ADC_DMA, ADC_SEQ_LEN); dmaStreamSetMode(ADC_DMA, ADC_DMA_MODE); dmaStreamEnable(ADC_DMA); // ADC StartConversion(); }
void Adc_t::StartMeasurement() { // DMA dmaStreamSetMemory0(ADC_DMA, IBuf); dmaStreamSetTransactionSize(ADC_DMA, ADC_SEQ_LEN); dmaStreamSetMode(ADC_DMA, ADC_DMA_MODE); dmaStreamEnable(ADC_DMA); // ADC ADC1->CR1 = ADC_CR1_SCAN; ADC1->CR2 = ADC_CR2_DMA | ADC_CR2_ADON; StartConversion(); }
void Adc_t::Measure(Thread *PThread, eventmask_t Evt) { IPThread = PThread; IEvt = Evt; // DMA dmaStreamSetMemory0(ADC_DMA, Result); dmaStreamSetTransactionSize(ADC_DMA, ADC_BUF_SZ); dmaStreamSetMode(ADC_DMA, ADC_DMA_MODE); dmaStreamEnable(ADC_DMA); // ADC ADC1->CR1 = ADC_CR1_SCAN; ADC1->CR2 = ADC_CR2_DMA | ADC_CR2_ADON; StartConversion(); }
void Adc_t::Measure() { // DMA dmaStreamSetMemory0(ADC_DMA, Result); dmaStreamSetTransactionSize(ADC_DMA, ADC_BUF_SZ); dmaStreamSetMode(ADC_DMA, ADC_DMA_MODE); dmaStreamEnable(ADC_DMA); // ADC ADC1->CR1 = ADC_CR1_SCAN; ADC1->CR2 = ADC_CR2_DMA | ADC_CR2_ADON; chSysLock(); PAdcThread = chThdSelf(); StartConversion(); chSchGoSleepS(THD_STATE_SUSPENDED); chSysUnlock(); ADC1->CR2 = 0; }
void Adc_t::StartMeasurement() { // Stop ADC if(IsEnabled()) { SET_BIT(ADC1->CR, ADC_CR_ADSTP); // Stop any ongoing conversion while(READ_BIT(ADC1->CR, ADC_CR_ADSTP) != 0); // Let it to complete Disable(); while(IsEnabled()); // Let it to complete } Calibrate(); __NOP(); __NOP(); __NOP(); __NOP(); // ADEN bit cannot be set during ADCAL=1 and 4 ADC clock cycle after the ADCAL bit is cleared by hardware(end of the calibration). // Start ADC SET_BIT(ADC1->ISR, ADC_ISR_ADRDY); // Clear ADRDY bit by writing 1 to it SET_BIT(ADC1->CR, ADC_CR_ADEN); // Enable ADC while(READ_BIT(ADC1->ISR, ADC_ISR_ADRDY) == 0); // Let it to complete // Setup oversampler #if ADC_OVERSAMPLING_RATIO == 1 ADC1->CFGR2 = 0; // Oversampler disabled #elif ADC_OVERSAMPLING_RATIO == 2 ADC1->CFGR2 = (0b0001 << 5) | (0b000 << 2) | ADC_CFGR2_ROVSE; #elif ADC_OVERSAMPLING_RATIO == 4 ADC1->CFGR2 = (0b0010 << 5) | (0b001 << 2) | ADC_CFGR2_ROVSE; #elif ADC_OVERSAMPLING_RATIO == 8 ADC1->CFGR2 = (0b0011 << 5) | (0b010 << 2) | ADC_CFGR2_ROVSE; #elif ADC_OVERSAMPLING_RATIO == 16 ADC1->CFGR2 = (0b0100 << 5) | (0b011 << 2) | ADC_CFGR2_ROVSE; #elif ADC_OVERSAMPLING_RATIO == 32 ADC1->CFGR2 = (0b0101 << 5) | (0b100 << 2) | ADC_CFGR2_ROVSE; #elif ADC_OVERSAMPLING_RATIO == 64 ADC1->CFGR2 = (0b0110 << 5) | (0b101 << 2) | ADC_CFGR2_ROVSE; #elif ADC_OVERSAMPLING_RATIO == 128 ADC1->CFGR2 = (0b0111 << 5) | (0b110 << 2) | ADC_CFGR2_ROVSE; #elif ADC_OVERSAMPLING_RATIO == 256 ADC1->CFGR2 = (0b1000 << 5) | (0b111 << 2) | ADC_CFGR2_ROVSE; #endif // Setup ADC. Do not set OVRMOD bit as it breaks sequence in case of DMA SET_BIT(ADC1->CFGR, ADC_CFGR_DMAEN); // Enable DMA // DMA dmaStreamSetMemory0(ADC_DMA, IBuf); dmaStreamSetTransactionSize(ADC_DMA, ADC_SEQ_LEN); dmaStreamSetMode(ADC_DMA, ADC_DMA_MODE); dmaStreamEnable(ADC_DMA); // ADC StartConversion(); }
UI_BDF2EDFwindow::UI_BDF2EDFwindow(QWidget *w_parent) { mainwindow = (UI_Mainwindow *)w_parent; recent_opendir = mainwindow->recent_opendir; recent_savedir = mainwindow->recent_savedir; myobjectDialog = new QDialog; myobjectDialog->setMinimumSize(600, 526); myobjectDialog->setMaximumSize(600, 526); myobjectDialog->setWindowTitle("BDF+ to EDF+ converter"); myobjectDialog->setModal(true); myobjectDialog->setAttribute(Qt::WA_DeleteOnClose, true); label1 = new QLabel(myobjectDialog); label1->setGeometry(20, 20, 560, 25); label2 = new QLabel(myobjectDialog); label2->setGeometry(440, 196, 100, 25); label2->setText("High-pass filter"); label3 = new QLabel(myobjectDialog); label3->setGeometry(440, 300, 100, 25); label3->setText("Divider"); SignalsTablewidget = new QTableWidget(myobjectDialog); SignalsTablewidget->setGeometry(20, 66, 400, 380); SignalsTablewidget->setSelectionMode(QAbstractItemView::NoSelection); SignalsTablewidget->setColumnCount(3); SignalsTablewidget->setColumnWidth(0, 140); SignalsTablewidget->setColumnWidth(1, 100); SignalsTablewidget->setColumnWidth(2, 100); QStringList horizontallabels; horizontallabels += "Label"; horizontallabels += "HighPassFilter"; horizontallabels += "Divider"; SignalsTablewidget->setHorizontalHeaderLabels(horizontallabels); spinBox1 = new QDoubleSpinBox(myobjectDialog); spinBox1->setGeometry(440, 232, 100, 25); spinBox1->setDecimals(3); spinBox1->setSuffix(" Hz"); spinBox1->setRange(0.001, 100.0); spinBox1->setValue(0.1); spinBox2 = new QDoubleSpinBox(myobjectDialog); spinBox2->setGeometry(440, 336, 100, 25); spinBox2->setDecimals(3); spinBox2->setRange(1.0, 256.0); spinBox2->setValue(1.0); pushButton1 = new QPushButton(myobjectDialog); pushButton1->setGeometry(20, 476, 100, 25); pushButton1->setText("Select File"); pushButton2 = new QPushButton(myobjectDialog); pushButton2->setGeometry(480, 476, 100, 25); pushButton2->setText("Close"); pushButton3 = new QPushButton(myobjectDialog); pushButton3->setGeometry(200, 476, 100, 25); pushButton3->setText("Convert"); pushButton3->setEnabled(false); pushButton4 = new QPushButton(myobjectDialog); pushButton4->setGeometry(440, 66, 140, 25); pushButton4->setText("Select all signals"); pushButton4->setEnabled(false); pushButton5 = new QPushButton(myobjectDialog); pushButton5->setGeometry(440, 118, 140, 25); pushButton5->setText("Deselect all signals"); pushButton5->setEnabled(false); QObject::connect(pushButton1, SIGNAL(clicked()), this, SLOT(SelectFileButton())); QObject::connect(pushButton2, SIGNAL(clicked()), myobjectDialog, SLOT(close())); QObject::connect(pushButton3, SIGNAL(clicked()), this, SLOT(StartConversion())); QObject::connect(pushButton4, SIGNAL(clicked()), this, SLOT(Select_all_signals())); QObject::connect(pushButton5, SIGNAL(clicked()), this, SLOT(Deselect_all_signals())); QObject::connect(spinBox1, SIGNAL(valueChanged(double)), this, SLOT(spinbox1_changed(double))); QObject::connect(spinBox2, SIGNAL(valueChanged(double)), this, SLOT(spinbox2_changed(double))); QObject::connect(myobjectDialog, SIGNAL(destroyed()), this, SLOT(free_edfheader())); edfhdr = NULL; inputfile = NULL; outputfile = NULL; inputpath[0] = 0; myobjectDialog->exec(); }
UI_ReduceSignalsWindow::UI_ReduceSignalsWindow(QWidget *w_parent) { mainwindow = (UI_Mainwindow *)w_parent; recent_savedir = mainwindow->recent_savedir; myobjectDialog = new QDialog; myobjectDialog->setMinimumSize(715, 578); myobjectDialog->setMaximumSize(715, 578); myobjectDialog->setWindowTitle("Reduce signals and/or duration"); myobjectDialog->setModal(true); myobjectDialog->setAttribute(Qt::WA_DeleteOnClose, true); label1 = new QLabel(myobjectDialog); label1->setGeometry(20, 20, 685, 25); label2 = new QLabel(myobjectDialog); label2->setGeometry(485, 359, 100, 25); label2->setText("from datarecord"); label2->setEnabled(false); label3 = new QLabel(myobjectDialog); label3->setGeometry(485, 424, 100, 25); label3->setText("to datarecord"); label3->setEnabled(false); label4 = new QLabel(myobjectDialog); label4->setGeometry(605, 332, 100, 25); label4->setEnabled(false); label5 = new QLabel(myobjectDialog); label5->setGeometry(605, 397, 100, 25); label5->setEnabled(false); label6 = new QLabel(myobjectDialog); label6->setGeometry(445, 232, 140, 25); label6->setText("Anti-aliasing filter order"); radioButton1 = new QRadioButton("whole duration", myobjectDialog); radioButton1->setGeometry(485, 299, 100, 25); radioButton1->setChecked(true); radioButton1->setEnabled(false); radioButton2 = new QRadioButton("selection", myobjectDialog); radioButton2->setGeometry(485, 324, 100, 25); radioButton2->setEnabled(false); spinBox1 = new QSpinBox(myobjectDialog); spinBox1->setGeometry(485, 384, 100, 25); spinBox1->setRange(1, 2147483647); spinBox1->setValue(1); spinBox1->setEnabled(false); spinBox2 = new QSpinBox(myobjectDialog); spinBox2->setGeometry(485, 449, 100, 25); spinBox2->setRange(1, 2147483647); spinBox2->setValue(2147483647); spinBox2->setEnabled(false); spinBox3 = new QSpinBox(myobjectDialog); spinBox3->setGeometry(595, 170, 100, 25); spinBox3->setRange(1, 100000); spinBox3->setValue(1); spinBox3->setEnabled(false); spinBox4 = new QSpinBox(myobjectDialog); spinBox4->setGeometry(595, 232, 100, 25); spinBox4->setRange(1, REDUCER_MAX_AA_FILTERS + 1); spinBox4->setValue(REDUCER_MAX_AA_FILTERS + 1); spinBox4->setEnabled(false); SignalsTablewidget = new QTableWidget(myobjectDialog); SignalsTablewidget->setGeometry(20, 66, 405, 432); SignalsTablewidget->setSelectionMode(QAbstractItemView::NoSelection); SignalsTablewidget->setColumnCount(2); SignalsTablewidget->setColumnWidth(0, 180); SignalsTablewidget->setColumnWidth(1, 180); QStringList horizontallabels; horizontallabels += "Label"; horizontallabels += "Samplerate divider"; SignalsTablewidget->setHorizontalHeaderLabels(horizontallabels); pushButton1 = new QPushButton(myobjectDialog); pushButton1->setGeometry(20, 528, 100, 25); pushButton1->setText("Select File"); pushButton2 = new QPushButton(myobjectDialog); pushButton2->setGeometry(575, 528, 100, 25); pushButton2->setText("Close"); pushButton3 = new QPushButton(myobjectDialog); pushButton3->setGeometry(200, 528, 100, 25); pushButton3->setText("Reduce"); pushButton3->setEnabled(false); pushButton4 = new QPushButton(myobjectDialog); pushButton4->setGeometry(445, 66, 140, 25); pushButton4->setText("Select all signals"); pushButton4->setEnabled(false); pushButton5 = new QPushButton(myobjectDialog); pushButton5->setGeometry(445, 118, 140, 25); pushButton5->setText("Deselect all signals"); pushButton5->setEnabled(false); pushButton6 = new QPushButton(myobjectDialog); pushButton6->setGeometry(445, 170, 140, 25); pushButton6->setText("Set samplerate divider:"); pushButton6->setEnabled(false); QObject::connect(pushButton1, SIGNAL(clicked()), this, SLOT(SelectFileButton())); QObject::connect(pushButton2, SIGNAL(clicked()), myobjectDialog, SLOT(close())); QObject::connect(pushButton3, SIGNAL(clicked()), this, SLOT(StartConversion())); QObject::connect(pushButton4, SIGNAL(clicked()), this, SLOT(Select_all_signals())); QObject::connect(pushButton5, SIGNAL(clicked()), this, SLOT(Deselect_all_signals())); QObject::connect(pushButton6, SIGNAL(clicked()), this, SLOT(Set_SRdivider_all_signals())); QObject::connect(spinBox1, SIGNAL(valueChanged(int)), this, SLOT(spinBox1changed(int))); QObject::connect(spinBox2, SIGNAL(valueChanged(int)), this, SLOT(spinBox2changed(int))); QObject::connect(radioButton1, SIGNAL(toggled(bool)), this, SLOT(radioButton1Toggled(bool))); QObject::connect(radioButton2, SIGNAL(toggled(bool)), this, SLOT(radioButton2Toggled(bool))); edfhdr = NULL; inputfile = NULL; outputfile = NULL; file_num = -1; inputpath[0] = 0; myobjectDialog->exec(); }