-
Notifications
You must be signed in to change notification settings - Fork 1
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
Revision of PDM code to have proper sinc filter and maybe dB-gain-managed output #2
Comments
Thank you @deanm1278! |
Fantastic news @ladyada! Thanks @deanm1278 😄 |
hi @jamesadevine I have a Q:
This should initialize the mic and then generate an event when the PDM level goes above or below 0 right?
Is there something else I should be doing to release the buffer? |
LevelDetector lvl(mic, 0, 0); Off the top of my head, you may be hitting a corner case in the code, I think it presumes that the two values are different, not the same... LevelDetector lvl(mic, 1, 0); Would likely work, I'll give it a look in a bit 😄 |
@deanm1278 HEY! Sorry this took a little while to get back to you, here's a sample that will work...: #include "CircuitPlayground.h"
#include "SAMD21DMAC.h"
#include "SAMD21PDM.h"
#include "LevelDetector.h"
#include "StreamNormalizer.h"
CircuitPlayground cplay;
SAMD21DMAC dma;
SAMD21PDM mic(cplay.io.microphoneData, cplay.io.microphoneClock, dma, 22000);
LevelDetector lvl(mic.output, 70, 30);
void high(Event)
{
cplay.io.led.setDigitalValue(1);
}
void low(Event)
{
cplay.io.led.setDigitalValue(0);
}
int main()
{
cplay.messageBus.listen(DEVICE_ID_SYSTEM_LEVEL_DETECTOR,LEVEL_THRESHOLD_HIGH,high);
cplay.messageBus.listen(DEVICE_ID_SYSTEM_LEVEL_DETECTOR,LEVEL_THRESHOLD_LOW,low);
mic.enable();
release_fiber();
} I've also added some samples we had knocking about on an old repository to the circuit-playground repo (https://github.com/lancaster-university/codal-circuit-playground/tree/master/samples) |
P.S. I've found that sample works best if you blow directly at the mic 😄 |
@jamesadevine ok thanks very much! I'll check it out when I have a minute to get back to this. Was mine not working because I'm supposed to use |
Yes, that's correct 😄 sorry didn't spot it in my cursory glance... |
ok @jamesadevine @pelikhan I have made a bunch of PDM updates here: and have also updated the LevelShifter stream to use dB SPL here: If this is not the correct place for the dB SPL code, or it should go in it's own stream please let me know. So that I can be sure things are correct before I submit a PR, is there any way to print things via USB CDC similar to Arduino Thanks! |
There's a uf2 equivalent yes, see uf2tool. Alternately just attach a usb to serial cable, to TX and RX on the cplay. By default dmesg uses uf2 to debug, if you flip the DMESG_SERIAL_DEBUG flag and have |
@deanm1278 WRT your code, I think there should be a separation of concerns... It seems like your modifications to
So for me it feels like these should be two separate nodes in the stream:
I think it's useful to have both versions of the level detector, so I think that your floating point level detector should be a separate class. What do you think @deanm1278 @finneyj ? Does it make sense to separate out the decibels conversion? |
Ok I've broken out a separate dB SPL level detector (see my PRs in codal-samd21 and codal-core). |
@deanm1278 Agreed, cool. I've given your PRs a quick review, it took me a little while to be able to test 😄 I like that we now use an SI unit for the microphone, it opens up a whole bunch more educational scenarios in the classroom. Thanks a lot! |
Dean @deanm1278 kindly volunteered to port his Arduino-calibrated code to CODAL!
The text was updated successfully, but these errors were encountered: