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
8121654e
Commit
8121654e
authored
1 year ago
by
Pascal Engeler
Browse files
Options
Downloads
Patches
Plain Diff
Added driver for ltc6992 pwm chip
parent
f6509522
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
firmware/drivers/ltc6992/ltc6992.cpp
+42
-0
42 additions, 0 deletions
firmware/drivers/ltc6992/ltc6992.cpp
firmware/drivers/ltc6992/ltc6992.hpp
+25
-0
25 additions, 0 deletions
firmware/drivers/ltc6992/ltc6992.hpp
with
67 additions
and
0 deletions
firmware/drivers/ltc6992/ltc6992.cpp
0 → 100644
+
42
−
0
View file @
8121654e
#include
<ltc6992.hpp>
#include
<stdint.h>
bool
Ltc6992
::
initialized_
=
false
;
uint16_t
Ltc6992
::
current_level_
=
0b0000000000000000
;
uint16_t
Ltc6992
::
max_level_
=
0b0000111111111111
;
uint16_t
Ltc6992
::
min_level_
=
0b0000000000000000
;
void
Ltc6992
::
init
(){
analogWriteResolution
(
12
);
current_level_
=
0b0000000000000000
;
analogWrite
(
LTC6992_PIN
,
current_level_
);
initialized_
=
true
;
}
bool
Ltc6992
::
set_level
(
double
lev
){
if
(
!
initialized_
){
return
false
;
}
if
(
lev
>
1.0
||
lev
<
0.0
){
//If input out of bounds, silently turn off
lev
=
0.0
;
}
uint16_t
new_level
=
static_cast
<
uint16_t
>
(
static_cast
<
int
>
(
static_cast
<
double
>
(
static_cast
<
int
>
(
max_level_
))
*
lev
));
if
(
new_level
>
max_level_
||
new_level
<
min_level_
){
//If something strange happens, turn off
current_level_
=
min_level_
;
}
else
{
current_level_
=
new_level
;
}
analogWrite
(
LTC6992_PIN
,
current_level_
);
return
current_level_
==
new_level
;
}
double
Ltc6992
::
current_level
(){
return
static_cast
<
double
>
(
current_level_
)
/
static_cast
<
double
>
(
max_level_
);
}
unsigned
Ltc6992
::
current_ulevel
(){
return
unsigned
(
current_level_
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
firmware/drivers/ltc6992/ltc6992.hpp
0 → 100644
+
25
−
0
View file @
8121654e
#ifndef LTC6992_HPP_INCLUDED
#define LTC6992_HPP_INCLUDED
#include
<stdint.h>
#include
<Arduino.h>
#define LTC6992_PIN DAC1
struct
Ltc6992
{
//first call to a member must be to init()
static
void
init
();
//lev is in [0, 1]
static
bool
set_level
(
double
lev
);
static
double
current_level
();
static
unsigned
current_ulevel
();
private:
static
bool
initialized_
;
static
uint16_t
current_level_
;
static
uint16_t
max_level_
;
static
uint16_t
min_level_
;
};
#endif
\ No newline at end of file
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