Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add function to enable high pass filter #9

Merged
merged 3 commits into from
Oct 13, 2021

Conversation

h3ndrik
Copy link
Contributor

@h3ndrik h3ndrik commented Oct 8, 2021

adds a function to write to the enable bit of the high pass filter. this is required for some microphone hardware.

@CelliesProjects
Copy link
Owner

Hi @h3ndrik
Thanks for your time and effort.

Could you explain the code to me?

@h3ndrik
Copy link
Contributor Author

h3ndrik commented Oct 10, 2021

yes: you can find more details in the datasheet under "Selectable High Pass Filter". It has 2 modes: audio and application mode. This is about audio mode.

In audio mode the high pass filter removes any frequencies below 3.7 Hz. Effectively removing any DC offset.
To enable this, you need to set HPFEN=1 (and HPFAPP=0).
HPFEN is bit 8 of R14

The code

  • saves the content of R14,
  • then clears bit 8 to zero (via the standard trick: AND with the inverted bitmask)
  • and then sets bit 8 to the parameter of the function.
  • and writes it back to R14

I tried to write it similar to the existing functions.

Motivation: I got a board with an elecret microphone. I had problems and noticed the captured waveform has quite a noticable offset. The high pass filter fixes this.

As frequences at below 3.7 Hz are inaudible, you might as well turn the HPF on by default, for example when writing to R14 the Init function:
Write_Reg(14, 1 << 3 | 1 << 8); //R14,ADC 128x采样率 and high pass filter

@CelliesProjects
Copy link
Owner

I get it. The one-complement operator was a new one for me.

As frequences at below 3.7 Hz are inaudible, you might as well turn the HPF on by default, for example when writing to R14 the Init function:
Write_Reg(14, 1 << 3 | 1 << 8); //R14,ADC 128x采样率 and high pass filter

If you could add that to this PR please.

@h3ndrik
Copy link
Contributor Author

h3ndrik commented Oct 12, 2021

alright. i've added that to the init function. thank you.

@CelliesProjects CelliesProjects merged commit 197226d into CelliesProjects:master Oct 13, 2021
@CelliesProjects
Copy link
Owner

Merged. @h3ndrik Thanks!

@h3ndrik
Copy link
Contributor Author

h3ndrik commented Oct 18, 2021

great. could you please also add a new tag / release a new version, so this will become available on platformio etc? thanks!

@CelliesProjects
Copy link
Owner

Version 1.0.4 is just released and should be picked up by the arduino library bot within 24-48 hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants