Skip to content

Commit 7f1731c

Browse files
author
jonnew
committed
Modifed RHD2000 interface to allow configuration of sync signal
- Sync signal, wired to BNC out with the update rhd2000.bit, can be set to a multiple of the sample clk period using the RHD2000Editor - This commit corresponds to this pull request: open-ephys/rhythm#11
1 parent a23cc9d commit 7f1731c

9 files changed

Lines changed: 138 additions & 21 deletions

File tree

Builds/Linux/build/rhd2000.bit

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

Resources/Bitfiles/rhd2000.bit

0 Bytes
Binary file not shown.

Source/Processors/DataThreads/RHD2000Editor.cpp

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,15 @@ RHD2000Editor::RHD2000Editor(GenericProcessor* parentNode,
631631
// add HW audio parameter selection
632632
audioInterface = new AudioInterface(board, this);
633633
addAndMakeVisible(audioInterface);
634-
audioInterface->setBounds(175, 65, 65, 50);
634+
audioInterface->setBounds(179, 58, 70, 50);
635635

636+
clockInterface = new ClockDivideInterface(board, this);
637+
addAndMakeVisible(clockInterface);
638+
clockInterface->setBounds(179, 82, 70, 50);
636639

637640
adcButton = new UtilityButton("ADC 1-8", Font("Small Text", 13, Font::plain));
638641
adcButton->setRadius(3.0f);
639-
adcButton->setBounds(175,100,65,18);
642+
adcButton->setBounds(179,108,70,18);
640643
adcButton->addListener(this);
641644
adcButton->setClickingTogglesState(true);
642645
adcButton->setTooltip("Enable/disable ADC channels");
@@ -742,7 +745,7 @@ void RHD2000Editor::handleAsyncUpdate()
742745

743746
String path(CoreServices::RecordNode::getRecordingPath().getFullPathName()
744747
+ File::separatorString + "impedance_measurement.xml");
745-
std::cout << "Saving impedance measurements in " << path << std::endl;
748+
std::cout << "Saving impedance measurements in " << path << "\n";
746749
File file(path);
747750

748751
if (!file.getParentDirectory().exists())
@@ -840,17 +843,17 @@ void RHD2000Editor::buttonEvent(Button* button)
840843
{
841844
board->enableAdcs(button->getToggleState());
842845
// board->updateChannelNames();
843-
std::cout << "ADC Button toggled" << std::endl;
846+
std::cout << "ADC Button toggled" << "\n";
844847
CoreServices::updateSignalChain(this);
845-
std::cout << "Editor visible." << std::endl;
848+
std::cout << "Editor visible." << "\n";
846849
}
847850
else if (button == dacTTLButton)
848851
{
849852
board->setTTLoutputMode(dacTTLButton->getToggleState());
850853
}
851854
else if (button == dspoffsetButton && !acquisitionIsActive)
852855
{
853-
std::cout << "DSP offset " << button->getToggleState() << std::endl;
856+
std::cout << "DSP offset " << button->getToggleState() << "\n";
854857
board->setDSPOffset(button->getToggleState());
855858
}
856859
else if (button == ledButton)
@@ -1027,8 +1030,8 @@ void BandwidthInterface::labelTextChanged(Label* label)
10271030

10281031
actualUpperBandwidth = board->setUpperBandwidth(requestedValue);
10291032

1030-
std::cout << "Setting Upper Bandwidth to " << requestedValue << std::endl;
1031-
std::cout << "Actual Upper Bandwidth: " << actualUpperBandwidth << std::endl;
1033+
std::cout << "Setting Upper Bandwidth to " << requestedValue << "\n";
1034+
std::cout << "Actual Upper Bandwidth: " << actualUpperBandwidth << "\n";
10321035
label->setText(String(round(actualUpperBandwidth*10.f)/10.f), dontSendNotification);
10331036

10341037
}
@@ -1049,8 +1052,8 @@ void BandwidthInterface::labelTextChanged(Label* label)
10491052

10501053
actualLowerBandwidth = board->setLowerBandwidth(requestedValue);
10511054

1052-
std::cout << "Setting Lower Bandwidth to " << requestedValue << std::endl;
1053-
std::cout << "Actual Lower Bandwidth: " << actualLowerBandwidth << std::endl;
1055+
std::cout << "Setting Lower Bandwidth to " << requestedValue << "\n";
1056+
std::cout << "Actual Lower Bandwidth: " << actualLowerBandwidth << "\n";
10541057

10551058
label->setText(String(round(actualLowerBandwidth*10.f)/10.f), dontSendNotification);
10561059
}
@@ -1157,7 +1160,7 @@ void SampleRateInterface::comboBoxChanged(ComboBox* cb)
11571160
{
11581161
board->setSampleRate(cb->getSelectedId()-1);
11591162

1160-
std::cout << "Setting sample rate to index " << cb->getSelectedId()-1 << std::endl;
1163+
std::cout << "Setting sample rate to index " << cb->getSelectedId()-1 << "\n";
11611164

11621165
CoreServices::updateSignalChain(editor);
11631166
}
@@ -1286,15 +1289,15 @@ void HeadstageOptionsInterface::buttonClicked(Button* button)
12861289
if (!(editor->acquisitionIsActive) && board->foundInputSource())
12871290
{
12881291

1289-
//std::cout << "Acquisition is not active" << std::endl;
1292+
//std::cout << "Acquisition is not active" << "\n";
12901293
if ((button == hsButton1) && (board->getChannelsInHeadstage(hsNumber1) == 32))
12911294
{
12921295
if (channelsOnHs1 == 32)
12931296
channelsOnHs1 = 16;
12941297
else
12951298
channelsOnHs1 = 32;
12961299

1297-
//std::cout << "HS1 has " << channelsOnHs1 << " channels." << std::endl;
1300+
//std::cout << "HS1 has " << channelsOnHs1 << " channels." << "\n";
12981301

12991302
hsButton1->setLabel(String(channelsOnHs1));
13001303
board->setNumChannels(hsNumber1, channelsOnHs1);
@@ -1390,7 +1393,7 @@ void AudioInterface::labelTextChanged(Label* label)
13901393

13911394
actualNoiseSlicerLevel = board->setNoiseSlicerLevel(requestedValue);
13921395

1393-
std::cout << "Setting Noise Slicer Level to " << requestedValue << std::endl;
1396+
std::cout << "Setting Noise Slicer Level to " << requestedValue << "\n";
13941397
label->setText(String((roundFloatToInt)(actualNoiseSlicerLevel)), dontSendNotification);
13951398

13961399
}
@@ -1424,16 +1427,66 @@ void AudioInterface::paint(Graphics& g)
14241427
{
14251428

14261429
g.setColour(Colours::darkgrey);
1427-
14281430
g.setFont(Font("Small Text",9,Font::plain));
1429-
14301431
g.drawText(name, 0, 0, 200, 15, Justification::left, false);
1431-
14321432
g.drawText("Level: ", 0, 10, 200, 20, Justification::left, false);
1433+
}
1434+
1435+
1436+
// Clock Divider options
1437+
ClockDivideInterface::ClockDivideInterface(RHD2000Thread* board_,
1438+
RHD2000Editor* editor_) :
1439+
board(board_)
1440+
, editor(editor_)
1441+
1442+
{
1443+
divideRatioSelection = new Label("Clock Divider", lastDivideRatioString);
1444+
divideRatioSelection->setEditable(true,false,false);
1445+
divideRatioSelection->addListener(this);
1446+
divideRatioSelection->setBounds(30,10,30,20);
1447+
divideRatioSelection->setColour(Label::textColourId, Colours::darkgrey);
1448+
addAndMakeVisible(divideRatioSelection);
1449+
}
1450+
1451+
void ClockDivideInterface::labelTextChanged(Label* label)
1452+
{
1453+
if (board->foundInputSource())
1454+
{
1455+
if (label == divideRatioSelection)
1456+
{
1457+
Value val = label->getTextValue();
1458+
int requestedValue = int(val.getValue());
1459+
1460+
if (requestedValue < 1 || requestedValue > 65534)
1461+
{
1462+
CoreServices::sendStatusMessage("Value must be between 1 and 65534.");
1463+
label->setText(lastDivideRatioString, dontSendNotification);
1464+
return;
1465+
}
1466+
1467+
actualDivideRatio = board->setClockDivider(requestedValue);
1468+
lastDivideRatioString = String(actualDivideRatio);
14331469

1470+
std::cout << "Setting clock divide ratio to " << actualDivideRatio << "\n";
1471+
label->setText(lastDivideRatioString, dontSendNotification);
1472+
}
1473+
}
14341474
}
14351475

1476+
void ClockDivideInterface::setClockDivideRatio(int value)
1477+
{
1478+
actualDivideRatio = board->setClockDivider(value);
1479+
divideRatioSelection->setText(String(actualDivideRatio), dontSendNotification);
1480+
}
14361481

1482+
void ClockDivideInterface::paint(Graphics& g)
1483+
{
1484+
1485+
g.setColour(Colours::darkgrey);
1486+
g.setFont(Font("Small Text",9,Font::plain));
1487+
g.drawText(name, 0, 0, 200, 15, Justification::left, false);
1488+
g.drawText("Level: ", 0, 10, 200, 20, Justification::left, false);
1489+
}
14371490

14381491
// DSP Options --------------------------------------------------------------------
14391492

@@ -1472,8 +1525,8 @@ void DSPInterface::labelTextChanged(Label* label)
14721525

14731526
actualDspCutoffFreq = board->setDspCutoffFreq(requestedValue);
14741527

1475-
std::cout << "Setting DSP Cutoff Freq to " << requestedValue << std::endl;
1476-
std::cout << "Actual DSP Cutoff Freq: " << actualDspCutoffFreq << std::endl;
1528+
std::cout << "Setting DSP Cutoff Freq to " << requestedValue << "\n";
1529+
std::cout << "Actual DSP Cutoff Freq: " << actualDspCutoffFreq << "\n";
14771530
label->setText(String(round(actualDspCutoffFreq*10.f)/10.f), dontSendNotification);
14781531

14791532
}

Source/Processors/DataThreads/RHD2000Editor.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class SampleRateInterface;
3535
class BandwidthInterface;
3636
class DSPInterface;
3737
class AudioInterface;
38+
class ClockDivideInterface;
3839
class RHD2000Thread;
3940

4041
class UtilityButton;
@@ -199,6 +200,7 @@ class RHD2000Editor : public VisualizerEditor, public ComboBox::Listener, public
199200
ScopedPointer<DSPInterface> dspInterface;
200201

201202
ScopedPointer<AudioInterface> audioInterface;
203+
ScopedPointer<ClockDivideInterface> clockInterface;
202204

203205
ScopedPointer<UtilityButton> rescanButton,dacTTLButton;
204206
ScopedPointer<UtilityButton> adcButton;
@@ -371,5 +373,28 @@ class AudioInterface : public Component,
371373

372374
};
373375

376+
class ClockDivideInterface : public Component,
377+
public Label::Listener
378+
{
379+
public:
380+
ClockDivideInterface(RHD2000Thread*, RHD2000Editor*);
381+
382+
void paint(Graphics& g);
383+
void labelTextChanged(Label* te);
384+
385+
void setClockDivideRatio(int value);
386+
int getClockDivideRatio() const { return actualDivideRatio; };
374387

388+
private:
389+
390+
String name {"Clock Divider"};
391+
String lastDivideRatioString {"1"};
392+
393+
RHD2000Thread * board;
394+
RHD2000Editor * editor;
395+
396+
ScopedPointer<Label> divideRatioSelection;
397+
int actualDivideRatio {1};
398+
399+
};
375400
#endif // __RHD2000EDITOR_H_2AD3C591__

Source/Processors/DataThreads/RHD2000Thread.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,32 @@ void RHD2000Thread::enableBoardLeds(bool enable)
18211821
evalBoard->enableBoardLeds(enable);
18221822
}
18231823

1824+
int RHD2000Thread::setClockDivider(int divide_ratio)
1825+
{
1826+
// TODO: only allow if not running?
1827+
//if (isAcquisitionActive())
1828+
//
1829+
uint16_t N;
1830+
1831+
// Divide ratio should be 1 or an even number
1832+
if (divide_ratio != 1 && divide_ratio % 2)
1833+
divide_ratio--;
1834+
1835+
// Format the divide ratio from its true value to the
1836+
// format required by the firmware
1837+
// Ratio N
1838+
// 1 0
1839+
// >=2 Ratio/2
1840+
if (divide_ratio == 1)
1841+
N = 0;
1842+
else
1843+
N = static_cast<uint16_t>(divide_ratio/2);
1844+
1845+
evalBoard->setClockDivider(N);
1846+
1847+
return divide_ratio;
1848+
}
1849+
18241850
void RHD2000Thread::runImpedanceTest(ImpedanceData* data)
18251851
{
18261852
impedanceThread->stopThreadSafely();
@@ -2449,4 +2475,4 @@ void RHDImpedanceMeasure::restoreFPGA()
24492475
{
24502476
board->evalBoard->enableExternalFastSettle(true);
24512477
}
2452-
}
2478+
}

Source/Processors/DataThreads/RHD2000Thread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class RHD2000Thread : public DataThread, public Timer
130130

131131
void runImpedanceTest(ImpedanceData* data);
132132
void enableBoardLeds(bool enable);
133+
int setClockDivider(int divide_ratio);
133134

134135
private:
135136

Source/Processors/DataThreads/rhythm-api/rhd2000evalboard.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,17 @@ void Rhd2000EvalBoard::enableBoardLeds(bool enable)
16671667
dev->ActivateTriggerIn(TrigInOpenEphys, 0);
16681668
}
16691669

1670+
// Ratio divide_factor
1671+
// 1 0
1672+
// >=2 Ratio/2
1673+
void Rhd2000EvalBoard::setClockDivider(uint16_t divide_factor)
1674+
{
1675+
1676+
dev->SetWireInValue(WireInMultiUse, divide_factor);
1677+
dev->UpdateWireIns();
1678+
dev->ActivateTriggerIn(TrigInOpenEphys, 1);
1679+
}
1680+
16701681
bool Rhd2000EvalBoard::isUSB3()
16711682
{
16721683
return usb3;
@@ -1676,4 +1687,4 @@ void Rhd2000EvalBoard::printFIFOmetrics()
16761687
{
16771688
dev->UpdateWireOuts();
16781689
std::cout << "In FIFO: " << dev->GetWireOutValue(0x28) << " DDR: " << dev->GetWireOutValue(0x2a) << " Out FIFO: " << dev->GetWireOutValue(0x29) << std::endl;
1679-
}
1690+
}

Source/Processors/DataThreads/rhythm-api/rhd2000evalboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class Rhd2000EvalBoard
166166
void resetFpga();
167167
bool isStreamEnabled(int streamIndex);
168168
void enableBoardLeds(bool enable);
169+
void setClockDivider(uint16_t divide_factor);
169170
bool isUSB3();
170171
void printFIFOmetrics();
171172
bool readRawDataBlock(unsigned char** bufferPtr, int nSamples = -1);

0 commit comments

Comments
 (0)