Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pub
hello-world
nrf52
Commits
ffd1f29d
Commit
ffd1f29d
authored
Oct 01, 2017
by
Sam Calisch
Browse files
added pwm
parent
a4abad43
Pipeline
#860
passed with stage
in 1 second
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
modules/pwm/pwm.ino
0 → 100644
View file @
ffd1f29d
//sec 2017
uint16_t
pwms
[
1
]
=
{
0
};
//duty cycles. can put more to loop through a sequence
const
uint8_t
pwm_pin
=
26
;
//p26
void
setup
()
{
//Use PWM module. Can also use a timer and ppi.
NRF_GPIO
->
DIRSET
=
(
1
<<
pwm_pin
);
//set ref pin as output
NRF_GPIO
->
OUTCLR
=
(
1
<<
pwm_pin
);
//set ref pin low
NRF_PWM0
->
PSEL
.
OUT
[
0
]
=
(
pwm_pin
<<
PWM_PSEL_OUT_PIN_Pos
)
|
(
PWM_PSEL_OUT_CONNECT_Connected
<<
PWM_PSEL_OUT_CONNECT_Pos
);
NRF_PWM0
->
ENABLE
=
(
PWM_ENABLE_ENABLE_Enabled
<<
PWM_ENABLE_ENABLE_Pos
);
NRF_PWM0
->
MODE
=
(
PWM_MODE_UPDOWN_Up
<<
PWM_MODE_UPDOWN_Pos
);
NRF_PWM0
->
PRESCALER
=
(
PWM_PRESCALER_PRESCALER_DIV_1
<<
PWM_PRESCALER_PRESCALER_Pos
);
//16MHz tick
NRF_PWM0
->
COUNTERTOP
=
(
1600
<<
PWM_COUNTERTOP_COUNTERTOP_Pos
);
//10 kHz pwm freq.
NRF_PWM0
->
LOOP
=
(
PWM_LOOP_CNT_Disabled
<<
PWM_LOOP_CNT_Pos
);
NRF_PWM0
->
DECODER
=
(
PWM_DECODER_LOAD_Common
<<
PWM_DECODER_LOAD_Pos
)
|
(
PWM_DECODER_MODE_RefreshCount
<<
PWM_DECODER_MODE_Pos
);
pwms
[
0
]
=
800
;
NRF_PWM0
->
SEQ
[
0
].
PTR
=
((
uint32_t
)(
pwms
)
<<
PWM_SEQ_PTR_PTR_Pos
);
NRF_PWM0
->
SEQ
[
0
].
CNT
=
(
1
<<
PWM_SEQ_CNT_CNT_Pos
);
NRF_PWM0
->
SEQ
[
0
].
REFRESH
=
0
;
NRF_PWM0
->
SEQ
[
0
].
ENDDELAY
=
0
;
NRF_PWM0
->
TASKS_SEQSTART
[
0
]
=
1
;
}
void
loop
()
{}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment