Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
baharehf committed Mar 28, 2024
1 parent 39bcb60 commit 7bd13e4
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion boards/adafruit-clue/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static const spi_conf_t spi_config[] = {
/** @} */

/**
* @name PDM configuration
* @brief PDM configuration
* @{
*/
static const pdm_conf_t pdm_config = {
Expand Down
2 changes: 1 addition & 1 deletion boards/feather-nrf52840-sense/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static const i2c_conf_t i2c_config[] = {
/** @} */

/**
* @name PDM configuration
* @brief PDM configuration
* @{
*/
static const pdm_conf_t pdm_config = {
Expand Down
4 changes: 1 addition & 3 deletions cpu/nrf52/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ void spi_twi_irq_register_i2c(NRF_TWIM_Type *bus,
spi_twi_irq_cb_t cb, void *arg);

/**
* @brief Acquire the shared I2C/SPI peripheral in I2C mode
*
* @param bus bus to acquire exclusive access on
Expand Down Expand Up @@ -147,15 +146,14 @@ void nrf5x_spi_acquire(NRF_SPIM_Type *bus, spi_twi_irq_cb_t cb, void *arg);
* @param bus bus to release exclusive access on
*/
void nrf5x_spi_release(NRF_SPIM_Type *bus);

/**
* @brief Structure for PDM configuration data
*/
typedef struct {
uint8_t din_pin; /**< DIN pin */
uint8_t clk_pin; /**< CLK pin */
} pdm_conf_t;

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion cpu/nrf52/periph/pdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "periph/gpio.h"
#include "periph/pdm.h"

#define ENABLE_DEBUG (0)
#define ENABLE_DEBUG 0
#include "debug.h"

/* The samples buffer is a double buffer */
Expand Down
13 changes: 13 additions & 0 deletions dist/tools/pdm_check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# PDM Testing Report

## About
This report outlines the testing process and results for a PDM implementation on a Feather nRF52840 Sense board to validate its functionality and performance.

## Requirements
To run the python script, you need to install some packages listed in `requirements.txt`.

## Usage
This repord provides insights into the testing and the corresponding results obtained:
-Testing the PDM and visualizing the results in a chart.
-Saving the output data as a wave format for Audacity.
-Comparing the output signals from Python script and that from the Audacity.
3 changes: 3 additions & 0 deletions dist/tools/pdm_check/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
matplotlib==3.8.3
numpy==1.26.4
pyserial==3.5
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import re
import numpy as np
import os
import csv
from itertools import groupby
from operator import itemgetter
import serial
import struct
import wave
import time

str1 = "Start of the new buffer".encode('ascii')
str2= "End of the new buffer".encode('ascii')
str2 = "End of the new buffer".encode('ascii')

start_index_buf = 0
start_index_buf = 0
stop_index_buf = 0
start_found = False
buffer_number = 0
Expand All @@ -27,7 +22,6 @@
ser.writelines(["start\n".encode('ascii')])
while start:
line = ser.readline()
#print(line)
value = line.strip()
data[key] = value
if line.find(str1) != -1:
Expand All @@ -41,7 +35,7 @@
break
key +=1

print(start_index_buf)
print(start_index_buf)
print(stop_index_buf)
print(buffer_number)
ser.close()
Expand All @@ -61,23 +55,23 @@
samplerate = 16000
length = 1

# The left channel for 1 second.
# The left channel for 1 second
t = np.linspace(0, length, samplerate)
left_channel = 0.5 * np.sin(2 * np.pi * 440.0 * t)

# Noise on the right channel.
# Noise on the right channel
#right_channel = np.random.random(size=samplerate)
left_channel = data_to_plot/np.max(np.abs(data_to_plot))
audio = np.array([left_channel]).T

# Convert to (little-endian) 16 bit integers.
# Convert to (little-endian) 16 bit integers
audio = (audio * (2 ** 15 - 1)).astype("<h")

# Save the data as a wave format
with wave.open("sound_new_buf.wav", "w") as f:
with wave.open("sound.wav", "w") as f:
# Mono Channel
f.setnchannels(1)
# 2 bytes per sample.
# 2 bytes per sample
f.setsampwidth(2)
f.setframerate(samplerate)
f.writeframes(audio.tobytes())
Expand Down
4 changes: 3 additions & 1 deletion drivers/include/periph/pdm.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ typedef enum {
#define PDM_BUF_SIZE (128U)
#endif

// Define the new buffer size
/**
* @brief Define the new buffer size
*/
#define NEW_BUF_SIZE (PDM_BUF_SIZE * 5 * 16 * 16)

/**
Expand Down

0 comments on commit 7bd13e4

Please sign in to comment.