<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Setting Thingy52 Audio rate</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/42563/setting-thingy52-audio-rate</link><description>The customer&amp;#39;s goal is to play a tone on an external speaker with a data rate of 11.05KHz. 
 The &amp;quot;default&amp;quot; demo code for the Thingy52 @ https://github.com/NordicSemiconductor/Nordic-Thingy52-FW has a PWM driver that runs at 8KHz. 
 In drv_speaker.c SEQ_REPEATES</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 15 Jan 2019 17:10:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/42563/setting-thingy52-audio-rate" /><item><title>RE: Setting Thingy52 Audio rate</title><link>https://devzone.nordicsemi.com/thread/165821?ContentTypeID=1</link><pubDate>Tue, 15 Jan 2019 17:10:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dcf75280-b8a2-4dac-869d-8a409302e46c</guid><dc:creator>Jeff4BLE</dc:creator><description>&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting Thingy52 Audio rate</title><link>https://devzone.nordicsemi.com/thread/165820?ContentTypeID=1</link><pubDate>Tue, 15 Jan 2019 07:38:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:22390880-353e-4426-9d6c-14ae460d475f</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Jeff&lt;/p&gt;
&lt;p&gt;Yes, yes and yes. It seems you have understood it. Best of luck!&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting Thingy52 Audio rate</title><link>https://devzone.nordicsemi.com/thread/165819?ContentTypeID=1</link><pubDate>Mon, 14 Jan 2019 21:03:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:810b0bfa-a5ab-4981-bd02-7fc6b208b3f7</guid><dc:creator>Jeff4BLE</dc:creator><description>&lt;p&gt;Hi Simon,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please confirm that 250mS does not set the duty cycle,it sets the period or top value. In this case the period is 8 times faster then the targeted 8KHz sample rate, hence the SEQ_REPEATS value. So effectively, there are 8 sub-periods within a single sample period.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When using p_sound[i], i represents a portion of top or duty cycle of each sub-period.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If I understand this correctly the following timing diagrams should be relatively accurate. Please confirm.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-576244bc7ce341e4af20a52e5b183689/2019_2D00_01_2D00_14_5F00_12_2D00_57_2D00_25.bmp" /&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Jeff&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting Thingy52 Audio rate</title><link>https://devzone.nordicsemi.com/thread/165818?ContentTypeID=1</link><pubDate>Fri, 11 Jan 2019 13:43:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:070b7f8f-940a-4036-888b-9320562162c6</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Jeff&lt;/p&gt;
&lt;p&gt;The PWM runs on a 16MHz clock, with a duty cycle of 250ms. The SEQ_REPEATES is defined as 7 because that is how many times the duty cycle sequence is repeated (after the initial cycle), which is how the PWM driver runs at 8kHz. To make the PWM driver operate at 11049.72Hz, which is the closest I got to 11050Hz by trial and error , you will have to modify the .top_value in&amp;nbsp;&lt;span style="font-family:inherit;"&gt;nrf_drv_pwm_config_t&amp;nbsp;&lt;/span&gt;which is set to 250 down to 181.&lt;/p&gt;
&lt;p&gt;If you do this you will also have to alter the sound files played so that they play correctly on the modified PWM driver. As I do not know which sound file is played I can just give you general pointers here. If you are playing some of the sounds already on the Thingy:52 you will have to go through the sounds.h file and multiply all values by 0.724 (181/250) to ensure that the sound files doesn&amp;#39;t come out warped when playing them on a modified PWM driver. If the sound files in question are being sent by another device, the easiest thing would be to modify the sound files being before sending them to the Thingy. Alternatively, it might work if you multiply the p_sound[i] with 0.724 in lines 360, 390, and 401, in the drv_speaker.c file, however I am not completely sure this is correct.&lt;/p&gt;
&lt;p&gt;Note: It might be possible to get closer to the desired value by altering both the SEQ_REPEATES value as well as the duty cycle value. Exactly 11.05kHz will not be achieveable on a 16MHz clock.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>