- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi I would like to connect a Murata piezo buzzer on a 20736 SOC
But I am using
3 Channels to drive LED
W
hat are my option ?
Which pin can I use to rive the piezo
Can I use PWM2_OUTPUT_ENABLE_P28 ?
// Port = P#/16 and PIN = P# % 16
#define LED_RED 26
#define LED_GREEN 14
#define LED_BLUE 13
#define GPIO_PORT(x) (x/16)
#define GPIO_PIN(x) (x%16)
#define GPIO_PIN_28 28
/*
enum
{
/// PWM0 Output enable on P26
PWM0_OUTPUT_ENABLE_P26 = GPIO_OUTPUT_ENABLE,
/// PWM1 Output enable on P27 N/A MOSI
PWM1_OUTPUT_ENABLE_P27 = GPIO_OUTPUT_ENABLE,
/// PWM2 Output enable on P28
PWM2_OUTPUT_ENABLE_P28 = GPIO_OUTPUT_ENABLE,
/// PWM2 Output enable on P6 N/A
PWM2_OUTPUT_ENABLE_P6 = (GPIO_OUTPUT_ENABLE | (1 << 4)),
/// PWM2 Output enable on P14
PWM2_OUTPUT_ENABLE_P14 = (2 << 4),
/// PWM3 Output enable on P29 N/A
PWM3_OUTPUT_ENABLE_P29 = GPIO_OUTPUT_ENABLE,
/// PWM3 Output enable on P13
PWM3_OUTPUT_ENABLE_P13 = (2 << 4)
};
*/
#define ENABLE_LED_RED PWM0_OUTPUT_ENABLE_P26
#define ENABLE_LED_GREEN PWM2_OUTPUT_ENABLE_P14 // PWM3_OUTPUT_ENABLE_P13
#define ENABLE_LED_BLUE PWM3_OUTPUT_ENABLE_P13 // PWM2_OUTPUT_ENABLE_P14
1 P27 MOSI
36 P25 MISO
37 P24 SCK
30 P3 CS_TC1
31 P2 CS_TC2
## UART ##
18 RX
19 TX
ADC
35 P8 Battery Voltage Monitoring
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't see why not. You can use the following APIs to do this. More details in pwm.h.
gpio_configurePin();// to enable the port
pwm_setReset(1 << PWM2, 0);
pwm_start();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't see why not. You can use the following APIs to do this. More details in pwm.h.
gpio_configurePin();// to enable the port
pwm_setReset(1 << PWM2, 0);
pwm_start();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using a Piezo PKM13EPYH4000-A0
What would be the correlation between Music note Frequency and
toggle and init value ?
* The PWM uses the ACLK as a reference clock and the counts are
* incremented at the ACLK edges starting at init value. When the
* count reaches toggle value, the PWM channel output is inverted
* and when the count reaches 0x3FF, the output is inverted again
* and the count wraps around to init value and so on. When a 50%
* duty cycle is called for, ensure that init value is the same
* distance from toggle value as toggle value is from 0x3FF.
on Raspberry PI the API is straightforwar and human readable
but not in Wiced.
Here is a conversion table
How to convert standard notes to pwm_start(PWM2, PMU_CLK, 0x2FF, 0x200); from
typedef struct
{
UINT32 freqX100;
UINT16 init;
UINT16 toggle;
} PWM_INIT_TOGGLE_VALUES_FOR_TONES;
char *scale_to_idx[37] = { "C5", "C#5", "D", "D#5", // 0 52325
"E5", "F5", "F#5", "G5", // 4 65925
"G#5", "A5", "A#5", "B5", // 8 83061
"C6", "C#5", "D6", "D#6", // 12 104650
"E6", "F6", "F#", "G6", // 16 131851
"G#6", "A6", "A#6", "B6", // 20 166122
"C7", "C#7", "D7", "D#7", // 24 209300
"E7", "F7", "F#7", "G7", // 28 263702
"G#7", "A7", "A#7", "B7" // 32 332244
"C8" // 36 418601
};
PWM_INIT_TOGGLE_VALUES_FOR_TONES C5_to_B8[] =
{
{52325, 45, 534}, // C5 // 0
{55437, 99, 561}, // C#5 // 1
{58733, 151, 587}, // D5 // 2
{62225, 200, 612}, // D#5 // 3
{65925, 246, 635}, // E5 // 4
{69846, 290, 657}, // F5 // 5
{73999, 331, 677}, // F#5 // 6
{78399, 370, 697}, // G5 // 7
{83061, 407, 715}, // G#5 // 8
{88000, 441, 732}, // A5 // 9
{93233, 474, 749}, // A#5 // 10
{98777, 505, 764}, // B5 // 11
{104650, 534, 779}, // C6
{110873, 561, 792}, // C#5
{117466, 587, 805}, // D6
{124451, 612, 818}, // D#6 // 15
{131851, 635, 829}, // E6
{139691, 656, 840}, // F6
{147998, 677, 850}, // F#6
{156798, 696, 860}, // G6
{166122, 715, 869}, // G#6 // 20
{176000, 732, 878}, // A6
{186466, 748, 886}, // A#6
{197553, 764, 894}, // B6
{209300, 778, 901}, // C7
{221746, 792, 908}, // C#7 // 25
{234932, 805, 914}, // D7
{248902, 817, 920}, // D#7
{263702, 829, 926}, // E7
{279383, 840, 932}, // F7
{295996, 850, 937}, // F#7 // 30
{313596, 860, 942}, // G7
{332244, 869, 946}, // G#7
{352000, 878, 951}, // A7
{372931, 886, 955}, // A#7
{395107, 893, 958}, // B7 // 35
{418601, 901, 962}, // C8 // NOT SUPPORTED ON PIEZO <= 4.01KHz
{443492, 908, 966}, // C#8
{469863, 914, 969}, // D8
{497803, 920, 972}, // D#8
{527404, 926, 975}, // E8 // 40
{558765, 931, 977}, // F8
{591991, 937, 980}, // F#8
{627193, 941, 982}, // G8
{664488, 946, 985}, // G#8
{704000, 950, 987}, // A8 // 45
{745862, 954, 989}, // A#8
{790213, 958, 991}, // B8
};
And here is the Raspberry PI human readable API that can then be implemented using the Translation table C5_to_B8 and
scale_to_idx
Hope this helps!
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# buzzer control - pigpio PWM
import pigpio
import time
import re
BUZZER_PIN = 18
tm = 60.0 / 120.0 * 4
musical_scale = {
"C":523, "C#":554, "D":587, "D#":622,
"E":659, "F":698, "F#":740, "G":784,
"G#":831, "A":880, "A#":932, "B":988
}
pi1 = pigpio.pi()
pi1.set_mode(BUZZER_PIN, pigpio.OUTPUT)
pi1.hardware_PWM(BUZZER_PIN, 0, 0)
try:
score = "C4D4E2C4D4E2C4D8E16F16G8A4B2"
while len(score) > 0:
m = re.match(r"^([A-Ga-g]+)([0-9]+)", score)
if m:
s = m.group(1)
d = m.group(2)
score = score.lstrip(s + d)
freq = musical_scale
pi1.hardware_PWM(BUZZER_PIN, freq, 500000)
print "%s : %d" % ((s + d), freq)
time.sleep(tm / float(d))
else:
break
except KeyboardInterrupt:
pass
# cleanup
print "done."
pi1.hardware_PWM(BUZZER_PIN, 0, 0)
pi1.set_mode(BUZZER_PIN, pigpio.INPUT)
pi1.stop()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The sample pwm_tones app gave some idea on how to do this conversion. In this app, it gave an example for 5 frequencies.
void tones_play_tone(void)
{
switch(tones_current_state)
{
case TONES_STATE_0:
// PWM channel 2 is P28 and the buzzer is connected to P28
// This will give us ~1.017KHz
pwm_start(PWM2, PMU_CLK, 0x2FF, 0x200);
break;
case TONES_STATE_1:
// This will give us ~2.04KHz.
pwm_start(PWM2, PMU_CLK, 0x37F, 0x300);
break;
case TONES_STATE_2:
// This will give us ~3.05KHz
pwm_start(PWM2, PMU_CLK, 0x3AA, 0x355);
break;
case TONES_STATE_3:
// This will give us ~4.01KHz.
pwm_start(PWM2, PMU_CLK, 0x3BF, 0x37E);
break;
case TONES_STATE_4:
// This will give us ~8.03KHz.
pwm_start(PWM2, PMU_CLK, 0x3E0, 0x3BF);
break;
default:
break;
}