PDA

View Full Version : Depending on value, SOUND statement leaves port output high



CuriousOne
- 4th October 2023, 05:19
Which leads to disastrous results, if you have passive buzzer connected thru transistor :)

For example,

PIC16F1828.

Sound PORTB.6,[115,1] - ok
Sound PORTB.6,[116,1] - port is left high

So when called, first statement works fine, if 2nd statement uses same frequency, it is also fine, but if 2nd statement uses different frequency, then port is left high. However, if I call the statement 3rd time, again, with different frequency, then port is turned low.

Technically, this is not a big issue - I just modified my code and added LOW PORTB.6 everywhere, after the SOUND statement, but I'm curious, is this bug or a feature?

tumbleweed
- 4th October 2023, 12:58
I think it's just the way it works, and probably depends on the timing since SOUND just toggles the IO pin to produce the output.
The manual shows using an inline capacitor to block the DC output.

Ioannis
- 4th October 2023, 20:13
Or if you do not want to use a capacitor, being brave enough, after the command use LOW to drive the pin at zero level.

Ioannis

CuriousOne
- 5th October 2023, 05:22
I guess that "feature" worth mentioning in manual :D

Ioannis
- 5th October 2023, 12:05
Well, it shows a capacitor. So, you have to use a capacitor. It is that simple...

Ioannis