Hard coded PWM with 500kHz frequency works
This commit is contained in:
parent
cf2725e028
commit
05dcb9de84
7 changed files with 75 additions and 7 deletions
|
|
@ -48,6 +48,7 @@ SRC_FILES += \
|
|||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_gpiote.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_rtc.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_pwm.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uart.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uarte.c \
|
||||
$(SDK_ROOT)/components/libraries/bsp/bsp.c \
|
||||
|
|
@ -62,6 +63,7 @@ SRC_FILES += \
|
|||
$(SDK_ROOT)/components/softdevice/common/nrf_sdh_ble.c \
|
||||
$(SDK_ROOT)/components/softdevice/common/nrf_sdh_soc.c \
|
||||
$(PROJ_DIR)/prst/ble.c \
|
||||
$(PROJ_DIR)/prst/pwm.c \
|
||||
$(PROJ_DIR)/prst/rtc.c \
|
||||
|
||||
# Include folders common to all targets
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
#ifndef _PRST_CONFIG_H_
|
||||
#define _PRST_CONFIG_H_
|
||||
|
||||
#include "nrf_gpio.h"
|
||||
|
||||
// Deep sleep.
|
||||
#define PRST_DEEP_SLEEP_IN_SECONDS 2
|
||||
|
||||
// BLE.
|
||||
#define PRST_BLE_ADV_NAME "Prst"
|
||||
|
||||
// PWM.
|
||||
#define PRST_PWM_PIN NRF_GPIO_PIN_MAP(0, 29)
|
||||
#define PRST_PWM_FREQUENCY 500000
|
||||
|
||||
#endif // _PRST_CONFIG_H_
|
||||
|
|
@ -2710,13 +2710,13 @@
|
|||
// <e> NRFX_PWM_ENABLED - nrfx_pwm - PWM peripheral driver
|
||||
//==========================================================
|
||||
#ifndef NRFX_PWM_ENABLED
|
||||
#define NRFX_PWM_ENABLED 0
|
||||
#define NRFX_PWM_ENABLED 1
|
||||
#endif
|
||||
// <q> NRFX_PWM0_ENABLED - Enable PWM0 instance
|
||||
|
||||
|
||||
#ifndef NRFX_PWM0_ENABLED
|
||||
#define NRFX_PWM0_ENABLED 0
|
||||
#define NRFX_PWM0_ENABLED 1
|
||||
#endif
|
||||
|
||||
// <q> NRFX_PWM1_ENABLED - Enable PWM1 instance
|
||||
|
|
@ -4949,7 +4949,7 @@
|
|||
// <e> PWM_ENABLED - nrf_drv_pwm - PWM peripheral driver - legacy layer
|
||||
//==========================================================
|
||||
#ifndef PWM_ENABLED
|
||||
#define PWM_ENABLED 0
|
||||
#define PWM_ENABLED 1
|
||||
#endif
|
||||
// <o> PWM_DEFAULT_CONFIG_OUT0_PIN - Out0 pin <0-31>
|
||||
|
||||
|
|
@ -5049,7 +5049,7 @@
|
|||
|
||||
|
||||
#ifndef PWM0_ENABLED
|
||||
#define PWM0_ENABLED 0
|
||||
#define PWM0_ENABLED 1
|
||||
#endif
|
||||
|
||||
// <q> PWM1_ENABLED - Enable PWM1 instance
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include "nrf_sdh_ble.h"
|
||||
#include "nrf_soc.h"
|
||||
#include "prst/ble.h"
|
||||
#include "prst/pwm.h"
|
||||
#include "prst/rtc.h"
|
||||
|
||||
// P0.03
|
||||
|
|
@ -79,6 +80,8 @@ int main(void) {
|
|||
log_init();
|
||||
leds_init();
|
||||
power_management_init();
|
||||
prst_pwm_init();
|
||||
prst_pwm_start();
|
||||
prst_ble_init();
|
||||
|
||||
prst_rtc_set_callback(rtc_callback);
|
||||
|
|
|
|||
|
|
@ -58,9 +58,6 @@ static uint8_t adv_handle_ = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
|
|||
static ble_gap_adv_params_t adv_params_;
|
||||
|
||||
static void init_advertisement_data() {
|
||||
UNUSED_VARIABLE(adv_data_);
|
||||
UNUSED_VARIABLE(advdata_service_data_);
|
||||
|
||||
// We'll just broadcast our data, so we disallow connections and scan
|
||||
// requests.
|
||||
adv_params_.properties.type =
|
||||
|
|
|
|||
50
code/b-parasite/src/prst/pwm.c
Normal file
50
code/b-parasite/src/prst/pwm.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#include "prst/pwm.h"
|
||||
|
||||
#include <app_error.h>
|
||||
#include <nordic_common.h>
|
||||
#include <nrf_drv_pwm.h>
|
||||
#include <nrf_log.h>
|
||||
#include <nrf_pwm.h>
|
||||
|
||||
#include "prst_config.h"
|
||||
|
||||
#define PRST_PWM_BASE_FREQ NRF_PWM_CLK_16MHz
|
||||
|
||||
static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0);
|
||||
|
||||
static nrf_pwm_values_common_t seq_values_[] = {8};
|
||||
static const nrf_pwm_sequence_t seq_ = {
|
||||
.values.p_common = seq_values_,
|
||||
.length = NRF_PWM_VALUES_LENGTH(seq_values_),
|
||||
.repeats = 0,
|
||||
.end_delay = 0};
|
||||
|
||||
void prst_pwm_init() {
|
||||
UNUSED_VARIABLE(seq_);
|
||||
|
||||
nrf_drv_pwm_config_t const config0 = {
|
||||
.output_pins =
|
||||
{
|
||||
PRST_PWM_PIN | NRF_DRV_PWM_PIN_INVERTED, // channel 0
|
||||
NRF_DRV_PWM_PIN_NOT_USED, // channel 1
|
||||
NRF_DRV_PWM_PIN_NOT_USED, // channel 2
|
||||
NRF_DRV_PWM_PIN_NOT_USED, // channel 3
|
||||
},
|
||||
.irq_priority = APP_IRQ_PRIORITY_LOWEST,
|
||||
// This is the hal PRESCALER.
|
||||
.base_clock = NRF_PWM_CLK_16MHz,
|
||||
// This is the hal COUNTERTOP.
|
||||
.count_mode = NRF_PWM_MODE_UP_AND_DOWN,
|
||||
// .top_value = (uint16_t)(1e16 / PRST_PWM_FREQUENCY),
|
||||
.top_value = 16,
|
||||
.load_mode = NRF_PWM_LOAD_COMMON,
|
||||
.step_mode = NRF_PWM_STEP_AUTO};
|
||||
APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm0, &config0, NULL));
|
||||
}
|
||||
|
||||
void prst_pwm_start() {
|
||||
APP_ERROR_CHECK(
|
||||
nrf_drv_pwm_simple_playback(&m_pwm0, &seq_, 1, NRF_DRV_PWM_FLAG_LOOP));
|
||||
}
|
||||
|
||||
void prst_pwm_stop() {}
|
||||
10
code/b-parasite/src/prst/pwm.h
Normal file
10
code/b-parasite/src/prst/pwm.h
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef _PRST_PWM_H_
|
||||
#define _PRST_PWM_H_
|
||||
|
||||
void prst_pwm_init();
|
||||
|
||||
void prst_pwm_start();
|
||||
|
||||
void prst_pwm_stop();
|
||||
|
||||
#endif // _PRST_PWM_H_
|
||||
Loading…
Add table
Reference in a new issue