Hi All
just trying to understand the short tone example and what its supposed to do.
From the code Should the output tone vary in frequency as the input voltage to the ADC varies ?
thanks
Example:
'Sample program to produce a tone on PORTB bit 1, based on the
'reading of an LDR on AN0 (usually PORTA bit 0).
#chip 16F88, 20
#define SoundOut PORTB.1
Dir PORTA.0 In
Do
ShortTone ReadAD(AN0), 100
Loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
that looks like the help program.
Frequency is measured in units of 10 Hz, and Duration is in 1 ms units.
1 should be 10 hz 255 should be 2550 hz since readad is 0-255
but I'm guessing. You'd need an amplifier to hear sound,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Rowdy. Did you check the READAD? Can check the READAD is working by sending the READAD value to a serial port? Or, use a fixed value for the parameter - make sure you have the basics working first. :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have returned to this subject to try and get it to work, I have tried the eample code on a 12f683 and a 12f1840 with changes on port names, but I dont beleive it works, all I get is a low buzzing sound that does not alter with the pot, if i replace the short tone with TONE it sort of works when the output tone starts it starts at a low frequency and as I turn the linear pot the frequency increases till a very high frequency, but then the tone drops to a very low frequency and increases again as I continue to turn the pot, so not sure what is going on, does short tone work for any body else ? Thanks
Last edit: rowdy 2020-09-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Perhaps your ADC is a 10 bit ADC? That way, the value from the pot could be in the range 0 - 1023. If tone expected a value of 0 - 255 you would get four sections where the value in ADC was truncated down to a byte (0 - 255).
Try dividing the value returned by ADC by four. You would need to store the ADC value in a word variable before performing the division or you would get the same result as before.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Check the voltages coming from the POT. Is the range 0v-5v0?
I attached the POT to A.0. I then checked the ADC is operational by testing and showing the value on a serial terminal. Did I get a range of 0 to 255? The TX was moved to A.4 to move from the ADC connection.
Then, I attached a piezo buzzer to porta.1 and it worked making a range of beeps dependent on the value of the ADC.
Then, I changed the code to the PlayRTTTL and it made the attached sound.
It should be noted that programming with these ports is not possible. 1. You must ensure the POT is NOT at 0v or 5v. 2. You MUST disconnect the piezo buzzer from from A1. Why? A.0 and A.1 are the ICSPDAT and ISCSPCLK respectively. A better choice would be ADC on AN2 and piezo buzzer on A.5 (these port recommendations are not validated and therefore will need testing).
'Sample program to produce a tone on PORTA bit 1, based on the'reading of a POT on AN0 (usually PORTA bit 0).
#chip12F1840
#optionExplicit' Test 1 for ADC Operation - shows range IS 0 to 255''USARTsettingsforUSART1' #define USART_BAUD_RATE 9600' #define USART_TX_BLOCKING' #define USART_DELAY OFF'''ChangeSerialouttoA.4' TXCKSEL = 1' Do' HSerPrint ReadAD(AN0)' HSerPrintCRLF' wait 100 ms' Loop'test for ShortTone
#defineSoundOutPORTa.1DoShortToneReadAD(AN0), 100Loop
'Sample program to produce a tone on PORTB bit 1, based on the
'reading of an LDR on AN0 (usually PORTA bit 0).
#chip16f88
#optionExplicit' test for ADC'USART settings for USART1
#defineUSART_BAUD_RATE9600
#defineUSART_TX_BLOCKING
#defineUSART_DELAYOFF'Serial out is on B.5' Do' HSerPrint ReadAD(AN0)' HSerPrintCRLF' wait 100 ms' Loop'test for ShortTone
#defineSoundOutPORTb.1DoShortToneReadAD(AN0), 100Loop
Then, I turned the test board off! and, then, I got a click NOT the SOUND!
Well after two hours I have found an uninitialised variable!!!! I went back the compiler in 2013 - same uninitialised variable.
My previous sound tests, where I output a value on the serial termainal) worked because the RAM memory was set to a value from the validation tests. The physical power cycle then set the RAM to 0 showing the real failure.
And, I went back to the 2013 code. Same issue!! This has been a long standing issue that was not exposed. How wierd that it worked when this simple command was within a larger program. :-) And, even odder... the Help would have been tested.
And, there is demo based upon a real project that uses the ShortTone. And, as it was Hugh... it was probably working with the uninitialised variable.
:-)
Last edit: Anobium 2020-09-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi All
just trying to understand the short tone example and what its supposed to do.
From the code Should the output tone vary in frequency as the input voltage to the ADC varies ?
thanks
Example:
that looks like the help program.
Frequency is measured in units of 10 Hz, and Duration is in 1 ms units.
1 should be 10 hz 255 should be 2550 hz since readad is 0-255
but I'm guessing. You'd need an amplifier to hear sound,
Thanks for the reply Stan, I will try the code and see what happens, yes the code is from the online help document, cheers.
http://gcbasic.sourceforge.net/help/_shorttone.html
@Rowdy. Did you check the READAD? Can check the READAD is working by sending the READAD value to a serial port? Or, use a fixed value for the parameter - make sure you have the basics working first. :-)
I have returned to this subject to try and get it to work, I have tried the eample code on a 12f683 and a 12f1840 with changes on port names, but I dont beleive it works, all I get is a low buzzing sound that does not alter with the pot, if i replace the short tone with TONE it sort of works when the output tone starts it starts at a low frequency and as I turn the linear pot the frequency increases till a very high frequency, but then the tone drops to a very low frequency and increases again as I continue to turn the pot, so not sure what is going on, does short tone work for any body else ? Thanks
Last edit: rowdy 2020-09-30
Perhaps your ADC is a 10 bit ADC? That way, the value from the pot could be in the range 0 - 1023. If tone expected a value of 0 - 255 you would get four sections where the value in ADC was truncated down to a byte (0 - 255).
Try dividing the value returned by ADC by four. You would need to store the ADC value in a word variable before performing the division or you would get the same result as before.
This work as expected.
I did the following:
It should be noted that programming with these ports is not possible. 1. You must ensure the POT is NOT at 0v or 5v. 2. You MUST disconnect the piezo buzzer from from A1. Why? A.0 and A.1 are the ICSPDAT and ISCSPCLK respectively. A better choice would be ADC on AN2 and piezo buzzer on A.5 (these port recommendations are not validated and therefore will need testing).
Anobium
You make to use VLC or a descent media player for the sound attached but it is the code from here: http://gcbasic.sourceforge.net/help/_play_rtttl.html
Last edit: Anobium 2020-09-30
Same test on the 16F88. Worked... SEE BELOW!!!!
'Sample program to produce a tone on PORTB bit 1, based on the
'reading of an LDR on AN0 (usually PORTA bit 0).
Then, I turned the test board off! and, then, I got a click NOT the SOUND!
Well after two hours I have found an uninitialised variable!!!! I went back the compiler in 2013 - same uninitialised variable.
Please update sound.h
https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/lowlevel/sound.h?format=raw
Works now... :-)
My previous sound tests, where I output a value on the serial termainal) worked because the RAM memory was set to a value from the validation tests. The physical power cycle then set the RAM to 0 showing the real failure.
And, I went back to the 2013 code. Same issue!! This has been a long standing issue that was not exposed. How wierd that it worked when this simple command was within a larger program. :-) And, even odder... the Help would have been tested.
And, there is demo based upon a real project that uses the ShortTone. And, as it was Hugh... it was probably working with the uninitialised variable.
:-)
Last edit: Anobium 2020-09-30
Hello Anobium , thank you, I will replace the sound.h file and test, much appreciated
Well I plugged my new code into a 12f1840 and happy to report it now works, so glad that the problem with the file was found, thanks again
Excellent. You found a latent issue. Nice to resolve for the others.
:-)