Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RBComb Temperature Control
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pascal Engeler
RBComb Temperature Control
Commits
1fb740df
Commit
1fb740df
authored
2 years ago
by
Pascal Engeler
Browse files
Options
Downloads
Patches
Plain Diff
More resilient communication, more different modes, fixed filter selection bug
parent
aa7fb1f8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
firmware/noise_sampling/noise_sampling.ino
+28
-13
28 additions, 13 deletions
firmware/noise_sampling/noise_sampling.ino
with
28 additions
and
13 deletions
firmware/noise_sampling/noise_sampling.ino
+
28
−
13
View file @
1fb740df
#include
<SPI.h>
#include
<SPI.h>
#include
<algorithm>
//std::min
#include
<algorithm>
//std::min
#define SPIRATE 84000000/32
//#define SPIRATE 84000000/128
#define nCS 46
#define nCS 46
...
@@ -19,7 +22,7 @@
...
@@ -19,7 +22,7 @@
//REG_STATUS BITS
//REG_STATUS BITS
//REG_ADC_CONTROL BITS
//REG_ADC_CONTROL BITS
#define POWER_MODE_FULLPOWER 0b000000001
0
000000
#define POWER_MODE_FULLPOWER 0b000000001
1
000000
#define CLK_SEL_INTERNALANDPIN 0b0000000000000001
#define CLK_SEL_INTERNALANDPIN 0b0000000000000001
#define REF_EN 0b0000000100000000
#define REF_EN 0b0000000100000000
//REG_DATA BITS
//REG_DATA BITS
...
@@ -28,11 +31,16 @@
...
@@ -28,11 +31,16 @@
//REG_CONFIG_0 BITS
//REG_CONFIG_0 BITS
#define CONFIG_SETTING 0b0000000111110000
#define CONFIG_SETTING 0b0000000111110000
//REG_FILTER_0 BITS
//REG_FILTER_0 BITS
#define FILTER_SETTING 0b000000000000011111111111
#define FILTER_SETTING_2047 0b000000000000011111111111
#define FILTER_SETTING_120 0b000000000000000001111000
#define FILTER_SETTING_15 0b000000000000000000001111
#define FILTER_SETTING_8 0b000000000000000000001000
#define FILTER_SETTING_4 0b000000000000000000000100
#define FILTER_SETTING_1 0b000000000000000000000001
void
reset_comm
(){
void
reset_comm
(){
SPI
.
beginTransaction
(
SPISettings
(
84000000
/
128
,
MSBFIRST
,
SPI_MODE3
));
SPI
.
beginTransaction
(
SPISettings
(
SPIRATE
,
MSBFIRST
,
SPI_MODE3
));
for
(
unsigned
i
=
0
;
i
<
8
;
++
i
){
for
(
unsigned
i
=
0
;
i
<
8
;
++
i
){
SPI
.
transfer
(
0xFF
);
SPI
.
transfer
(
0xFF
);
}
}
...
@@ -50,7 +58,7 @@ void SPIwrite(T data, uint8_t reg){
...
@@ -50,7 +58,7 @@ void SPIwrite(T data, uint8_t reg){
wrbuf
[
num_bytes
-
i
]
=
data
&
0xFF
;
wrbuf
[
num_bytes
-
i
]
=
data
&
0xFF
;
data
>>=
8
;
data
>>=
8
;
}
}
SPI
.
beginTransaction
(
SPISettings
(
84000000
/
128
,
MSBFIRST
,
SPI_MODE3
));
SPI
.
beginTransaction
(
SPISettings
(
SPIRATE
,
MSBFIRST
,
SPI_MODE3
));
SPI
.
transfer
(
wrbuf
,
num_bytes
+
1
);
SPI
.
transfer
(
wrbuf
,
num_bytes
+
1
);
SPI
.
endTransaction
();
SPI
.
endTransaction
();
}
}
...
@@ -62,7 +70,7 @@ void SPIread(T& data, uint8_t reg){
...
@@ -62,7 +70,7 @@ void SPIread(T& data, uint8_t reg){
//set up write command
//set up write command
rdbuf
[
0
]
=
reg
|
REG_READ
;
rdbuf
[
0
]
=
reg
|
REG_READ
;
uint8_t
num_bytes
=
std
::
min
(
sizeof
(
data
),
3u
);
uint8_t
num_bytes
=
std
::
min
(
sizeof
(
data
),
3u
);
SPI
.
beginTransaction
(
SPISettings
(
84000000
/
128
,
MSBFIRST
,
SPI_MODE3
));
SPI
.
beginTransaction
(
SPISettings
(
SPIRATE
,
MSBFIRST
,
SPI_MODE3
));
SPI
.
transfer
(
rdbuf
,
num_bytes
+
1
);
SPI
.
transfer
(
rdbuf
,
num_bytes
+
1
);
SPI
.
endTransaction
();
SPI
.
endTransaction
();
for
(
unsigned
i
=
1
;
i
<=
num_bytes
;
++
i
){
for
(
unsigned
i
=
1
;
i
<=
num_bytes
;
++
i
){
...
@@ -79,8 +87,8 @@ void setup_adc(){
...
@@ -79,8 +87,8 @@ void setup_adc(){
data16
=
CONFIG_SETTING
;
data16
=
CONFIG_SETTING
;
SPIwrite
(
data16
,
REG_CONFIG_0
);
SPIwrite
(
data16
,
REG_CONFIG_0
);
//FILTER
//FILTER
data
16
=
FILTER_SETTING
;
uint32_t
data
32
=
FILTER_SETTING
_2047
;
SPIwrite
(
data
16
,
REG_FILTER_0
);
SPIwrite
(
data
32
,
REG_FILTER_0
);
//CHANNEL
//CHANNEL
data16
=
CHANNEL_SETTING
;
data16
=
CHANNEL_SETTING
;
SPIwrite
(
data16
,
REG_CHANNEL_0
);
SPIwrite
(
data16
,
REG_CHANNEL_0
);
...
@@ -89,7 +97,7 @@ void setup_adc(){
...
@@ -89,7 +97,7 @@ void setup_adc(){
bool
data_ready
(){
bool
data_ready
(){
uint8_t
status
;
uint8_t
status
;
SPIread
(
status
,
REG_STATUS
);
SPIread
(
status
,
REG_STATUS
);
return
!
(
status
>>
8
);
return
!
(
status
>>
7
);
}
}
uint32_t
get_data
(){
uint32_t
get_data
(){
...
@@ -113,7 +121,9 @@ double temperature(double R){
...
@@ -113,7 +121,9 @@ double temperature(double R){
}
}
void
setup
()
{
void
setup
()
{
Serial
.
begin
(
9600
);
//Serial.begin(9600);
//Serial.begin(460800);
Serial
.
begin
(
128000
);
digitalWrite
(
nCS
,
HIGH
);
digitalWrite
(
nCS
,
HIGH
);
pinMode
(
nCS
,
OUTPUT
);
pinMode
(
nCS
,
OUTPUT
);
SPI
.
begin
();
SPI
.
begin
();
...
@@ -123,7 +133,6 @@ void setup() {
...
@@ -123,7 +133,6 @@ void setup() {
digitalWrite
(
nCS
,
LOW
);
digitalWrite
(
nCS
,
LOW
);
setup_adc
();
setup_adc
();
digitalWrite
(
nCS
,
HIGH
);
digitalWrite
(
nCS
,
HIGH
);
}
}
void
loop
()
{
void
loop
()
{
...
@@ -136,12 +145,18 @@ void loop() {
...
@@ -136,12 +145,18 @@ void loop() {
uint32_t
adc_data
;
uint32_t
adc_data
;
if
(
data_ready
()){
if
(
data_ready
()){
adc_data
=
get_data
();
adc_data
=
get_data
();
uint8_t
buf
[
3
];
uint8_t
buf
[
6
];
buf
[
0
]
=
uint8_t
(
adc_data
&
0x000000FF
);
buf
[
0
]
=
uint8_t
(
adc_data
&
0x000000FF
);
buf
[
1
]
=
uint8_t
((
adc_data
>>
8
)
&
0x000000FF
);
buf
[
1
]
=
uint8_t
((
adc_data
>>
8
)
&
0x000000FF
);
buf
[
2
]
=
uint8_t
((
adc_data
>>
16
)
&
0x000000FF
);
buf
[
2
]
=
uint8_t
((
adc_data
>>
16
)
&
0x000000FF
);
Serial
.
write
(
buf
,
3
);
buf
[
3
]
=
uint8_t
(
0x0a
);
Serial
.
flush
();
buf
[
4
]
=
uint8_t
(
0x0a
);
buf
[
5
]
=
uint8_t
(
0x0a
);
Serial
.
write
(
buf
,
6
);
//Serial.write('\n');
//Serial.write('\n');
//Serial.write('\n');
//Serial.flush();
/*
/*
Serial.print("Data: \t");
Serial.print("Data: \t");
Serial.print(adc_data, HEX);
Serial.print(adc_data, HEX);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment