PDA

View Full Version : Voice Playback CHIP SD20



robert.quaas
- 22nd December 2008, 15:12
Recently purchased a voice chip called SD20; Here is my code for PIC16F88, can not seem to get it to work.

If you look at page 12,13; and page 20 for info.

Attached is part of the datasheet document pages 1-13, I will post others up due to size limits.

appreciate some help on this ......


@ DEVICE XT_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF

DEFINE LOADER_USED 1

Include "Modedefs.Bas"

' ** Setup the Resonator Frequency, in Mhz **
Define OSC 4

' DEFINE SHIFT_PAUSEUS 100

ANSEL = 0 'Configure all pins to digital operation since not using ADC
'(Analog to Digital Converter)


Baud con 84 ' 9600 baud rate

' ** Port configurations **

TX VAR PORTB.5
RX VAR PORTB.2

CLK VAR PORTA.4
DI Var PORTA.0

PIEZO VAR PORTB.7

DAT VAR word


Init:

TRISA=%11111111 ' Set PortA TRIS register
TRISB=%00000000 ' Set PortB TRIS register

begin:

low piezo
high CLK
high DI

dat = $FFF7
serout2 tx,baud,["1st Data = ",bin16 dat,13,10]
Shiftout DI, CLK, 1,[dat/16]

dat = $3
serout2 tx,baud,["2nd Data = ",bin16 dat,13,10]
Shiftout DI, CLK, 1,[dat/16]

dat = $fffe
serout2 tx,baud,["3rd Data = ",bin16 dat,13,10]
Shiftout DI, CLK, 1,[dat/16]

END

robert.quaas
- 22nd December 2008, 15:19
Attached Pages from datasheet 14-20.

robert.quaas
- 22nd December 2008, 15:23
Attached last of datasheet info: pages 21-26

robert.quaas
- 22nd December 2008, 15:30
Here is a photo of my test circuit. Refer to page 22 from PDF document.

Resistor network connected to CLK and DI pin in SD20 from PIC as follows:

PortA.4
|
10K
|
10K
|------ CLK - SD20 - P04
10K
|
Gnd


PortA.0
|
10K
|
10K
|------ DI - SD20 - P05
10K
|
Gnd

'************************************************

Code as follows; but can not get it to work; any help PLEASE ?????

@ DEVICE XT_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF

DEFINE LOADER_USED 1

Include "Modedefs.Bas"

' ** Setup the Resonator Frequency, in Mhz **
Define OSC 4

' DEFINE SHIFT_PAUSEUS 100

ANSEL = 0 'Configure all pins to digital operation since not using ADC
'(Analog to Digital Converter)


Baud con 84 ' 9600 baud rate

' ** Port configurations **

TX VAR PORTB.5
RX VAR PORTB.2

CLK VAR PORTA.4
DI Var PORTA.0

PIEZO VAR PORTB.7

DAT VAR word


Init:

TRISA=%11111111 ' Set PortA TRIS register
TRISB=%00000000 ' Set PortB TRIS register

begin:

low piezo
high CLK
high DI

dat = $FFF7
serout2 tx,baud,["1st Data = ",bin16 dat,13,10]
Shiftout DI, CLK, 1,[dat/16]

dat = $3
serout2 tx,baud,["2nd Data = ",bin16 dat,13,10]
Shiftout DI, CLK, 1,[dat/16]

dat = $fffe
serout2 tx,baud,["3rd Data = ",bin16 dat,13,10]
Shiftout DI, CLK, 1,[dat/16]

END

robert.quaas
- 23rd December 2008, 03:28
I have posted up my code and datasheets for reference but no one has any ideas ???? as yet ????

Please let me know if anyone can help me ??

Thanks
:eek:

Archangel
- 23rd December 2008, 04:48
I have posted up my code and datasheets for reference but no one has any ideas ???? as yet ????

Please let me know if anyone can help me ??

Thanks
:eek: Can you be more specific? What do you mean it is not working, will it do nothing at all ? I notice you are trying to use PortA as digital, Have you disabled the comparators? Hint CMCON = ? Good idea to make it do a little dance before settling in to do serious work, like a heartbeat LED, just so you know life exists, helps keep from banging your head on the keyboard. That way you know the PIC is working but not as expected. you need to set ADCON register on this chip too.

robert.quaas
- 23rd December 2008, 05:33
I have disabled the Comparators; and All PortA pins are digital.

ANSEL = %00000000 ' PortA pins all digital

ADCON0 = %00000000
CMCON = 7 ' Turn off comparators(All digital)


When I say it is not working. It sends the data; but does not playback. I hear a few clicks and that is it.

What am I doing wrong here ???

Archangel
- 23rd December 2008, 06:07
I have disabled the Comparators; and All PortA pins are digital.

ANSEL = %00000000 ' PortA pins all digital

ADCON0 = %00000000
CMCON = 7 ' Turn off comparators(All digital)


When I say it is not working. It sends the data; but does not playback. I hear a few clicks and that is it.

What am I doing wrong here ???
I am guessing the data you are shifting out is somehow invalid. You are serial outputing data of nearly 2 full bytes, right? Is that what the module requires? I could not make that from that "data sheet". Please allow me to ask, does the module work if you switch it manually as in the schematic, by grounding p05? I feel like the data sheet is inadequate in it's detail as to how th control it with a microcontroller, it looks like p05 is the play button, P04 is clock(but for what) and P02 and p03 are to switch the wavs played, maybe it will spi control or not the way they show it. BTW do you have the SD card with appropriately named wavs programmed into it, installed? <font color=red>Where can get 1 of these to play with?</font color>

robert.quaas
- 23rd December 2008, 06:44
The updated code is as follows:

@ DEVICE XT_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF

DEFINE LOADER_USED 1

Include "Modedefs.Bas"

' ** Setup the Resonator Frequency, in Mhz **
Define OSC 4

'DEFINE SHIFT_PAUSEUS 100

ANSEL = %00000000 ' PortA pins all digital

ADCON0 = %00000000
CMCON = 7 ' Turn off comparators(All digital)


Baud con 84 ' 9600 baud rate

' ** Port configurations **

TX VAR PORTB.5
RX VAR PORTB.2

CLK VAR PORTA.4
DI VAR PORTA.0

RESET VAR PORTB.6

PIEZO VAR PORTB.7

DAT VAR word


Init:

TRISA=%11111111 ' Set PortA TRIS register
TRISB=%00000000 ' Set PortB TRIS register

begin:

low piezo
HIGH RESET
high CLK
high DI


LOW RESET
PAUSE 5
HIGH RESET
PAUSE 300
LOW RESET


dat = $FFF7
serout2 tx,baud,["1st Data = ",bin16 dat,13,10]
Shiftout DI, CLK,MSBFIRST,[dat/16]

dat = $3
serout2 tx,baud,["2nd Data = ",bin16 dat,13,10]
Shiftout DI, CLK,MSBFIRST,[dat/16]

dat = $fffe
serout2 tx,baud,["3rd Data = ",bin16 dat,13,10]
Shiftout DI, CLK,MSBFIRST,[dat/16]

end

**************************************************

It clicks and does not play; do you think I have the timing correct as per the diagram from the datasheet ?

Pedro Pinto
- 26th December 2008, 00:52
Hello robert.quaas

I'm interesting in this chip to. If i can understand, the chip can playback mp3 and wav files, is this correct? and you can connect it directly to a sd card, right?
Must i order directly from china manufacturer or exists in Europe a supplier?

Thanks for any information

fsantos at ses-electronic.com

Best regards
Pedro

Darrel Taylor
- 26th December 2008, 20:41
LOW RESET
PAUSE 5
HIGH RESET
PAUSE 300
LOW RESET

The second LOW RESET keeps the device in RESET during the transfer, it should not be there.

The CLK rate of SHIFTOUT is 50khz or higher, but the device is expecting no more than 500 hz clk (2ms per bit).
To slow it down, add ...
DEFINE SHIFT_PAUSEUS 2000


PortA.4
|
10K
|
10K
|------ CLK - SD20 - P04
10K
|
Gnd
Your voltage divider is only supplying 1.6V to the inputs (when High), and All inputs to the WTV020-SD-16P have internal Pull-up resistors of unknown value. So when the PIC's output is low the 10K resistor will be fighting the pull-up and probably doesn't go low enough.

A better way would probably be to not use SHIFTOUT and send each bit and clk in a FOR loop. Then you can use LOW and INPUT and remove the voltage dividers completely. Just remember, NEVER use HIGH or SHIFTOUT or TRIS when directly connected.

Pedro Santos
- 26th December 2008, 21:15
Hello Darrel

Have you a code example how to do that with the For / Loop
For beginners it helps a lot

Regards
Pedro

Darrel Taylor
- 26th December 2008, 21:48
Sure, maybe something like this...
@ DEVICE XT_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF

DEFINE LOADER_USED 1

' ** Setup the Resonator Frequency, in Mhz **
Define OSC 4

Baud con 84 ' 9600 baud rate

' ** Port configurations **
TX VAR PORTB.5
RX VAR PORTB.2
CLK VAR PORTA.4
DI Var PORTA.0
RESET VAR PORTB.6
PIEZO VAR PORTB.7

DAT VAR WORD
Idx VAR BYTE

;---------------------------------------------------------------------------
Init:
ANSEL = 0 'Configure all pins to digital operation since not using ADC
CMCON = 7 ' disable comparators

begin:
low piezo

dat = $FFF7
serout2 tx,baud,["1st Data = ",bin16 dat,13,10]
GOSUB SendDat

dat = $3
serout2 tx,baud,["2nd Data = ",bin16 dat,13,10]
GOSUB SendDat

dat = $fffe
serout2 tx,baud,["3rd Data = ",bin16 dat,13,10]
GOSUB SendDat

STOP

;---------------------------------------------------------------------------
SendDAT:
LOW RESET ; 5ms reset pulse
PAUSE 5
INPUT RESET
PAUSE 300 ; 300ms before data

For Idx = 15 to 0 STEP -1 ; loop thru the bits
LOW CLK ; set CLK LOW
IF dat.0(Idx) THEN
INPUT DI ; if bit = 1 then INPUT, not HIGH
ELSE
LOW DI ; if bit = 0 then LOW
ENDIF
PAUSE 1 ; data settle time
INPUT CLK ; clks data on rising edge
PAUSE 1 ; data read time
NEXT Idx ; do rest of the bits
INPUT DI ; leave data line tri-stated
RETURN

Pedro Santos
- 26th December 2008, 23:00
Hello Darrel
Thank you for the sample

Can you explain this?
For Idx = 15 to 0 STEP -1 ; loop thru the bits

is this correct?
IF dat.0(Idx) THEN

why not
IF dat(Idx) THEN

dat is a word variavel, so if
in the loop at the moment
idx is say 1 then it's the same like
dat.1, that is the second bit of the word, or not

NEXT Idx

Thanks and best regards
Pedro

Darrel Taylor
- 26th December 2008, 23:17
Can you explain this? ...
IF dat.0(Idx) THEN ...
I can.

But since Melanie's already covered the subject, I'll let her. :)

Bits, Bytes Words and Arrays
http://www.picbasic.co.uk/forum/showthread.php?t=544
<br>

Pedro Santos
- 26th December 2008, 23:22
Thanks again Darrel

Regards

Pedro :)

Darrel Taylor
- 27th December 2008, 05:02
You're Welcome Pedro,

Hope you (and everyone else) had a Happy "Boxing Day"!
<br>

robert.quaas
- 30th December 2008, 19:40
Hi Darrel

Thanks for help of this. I finally got it working, the engineer from the manufacturer found a small bug in their chip firmware. So anyone interested in using this chip should increase the reset time and increase the time for playback also.


See the amended code here :

@ DEVICE XT_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF

DEFINE LOADER_USED 1

' ** Setup the Resonator Frequency, in Mhz **
Define OSC 4

Baud con 84 ' 9600 baud rate

' ** Port configurations **
TX VAR PORTB.5
RX VAR PORTB.2
CLK VAR PORTA.4
DI Var PORTA.0
RESET VAR PORTB.6
PIEZO VAR PORTB.7

DAT VAR WORD
Idx VAR BYTE

counter var byte
volume var word

volume = 65527

'---------------------------------------------------------------------------

Init:
ANSEL = 0 'Configure all pins to digital operation since not using ADC
CMCON = 7 ' disable comparators

begin:
low piezo

dat = $FFF7
serout2 tx,baud,["Voice Volume - 1st Data = ",bin16 dat,13,10]
GOSUB SendDat

dat = $4
' set counter to file no. 4
counter = 4
serout2 tx,baud,["Address 4 of voice file - 2nd Data = ",bin16 dat,13,10]
GOSUB SendDat

playaddr:
dat = $fffe
serout2 tx,baud,["Play/Pause - 3rd Data = ",bin16 dat,13,10]
' GOSUB SendDat
GOSUB Playdata

' --------------------------------------------------------------------------
switch:

'if porta.2=0 then
' counter = counter - 1
' if counter<=1 then counter = 2
' dat = counter
'
' serout2 tx,baud,["Address of voice file - 2nd Data = ",bin16 dat,13,10]
' GOSUB SendDat
' goto playaddr
'endif

if porta.1=0 then
counter = counter + 1
if counter>=7 then counter = 6
dat = counter

serout2 tx,baud,["Address of voice file - 2nd Data = ",bin16 dat,13,10]
GOSUB SendDat
goto playaddr
endif

' Reduce Volume
if porta.2=0 then
volume = volume - 1
if volume<=65520 then volume = 65527
dat = volume

serout2 tx,baud,["Address of voice volume = ",bin16 dat,13,10]
GOSUB SendDat
'goto playaddr
endif

goto switch

STOP

'---------------------------------------------------------------------------

SendDAT:
LOW RESET ; 5ms reset pulse
PAUSE 5
INPUT RESET
PAUSE 300 ; 300ms before data

For Idx = 15 to 0 STEP -1 ; loop thru the bits
LOW CLK ; set CLK LOW
IF dat.0(Idx) THEN
INPUT DI ; if bit = 1 then INPUT, not HIGH
ELSE
LOW DI ; if bit = 0 then LOW
ENDIF
PAUSE 1 ; data settle time
INPUT CLK ; clks data on rising edge
PAUSE 1 ; data read time
NEXT Idx ; do rest of the bits
INPUT DI ; leave data line tri-stated
RETURN


' --------------------------------------------------------------------------

Playdata:

LOW RESET ; 5ms reset pulse
PAUSE 5
INPUT RESET
PAUSE 1250 ; 300ms before data


For Idx = 15 to 0 STEP -1 ; loop thru the bits
LOW CLK ; set CLK LOW
IF dat.0(Idx) THEN
INPUT DI ; if bit = 1 then INPUT, not HIGH
ELSE
LOW DI ; if bit = 0 then LOW
ENDIF
PAUSE 1 ; data settle time
INPUT CLK ; clks data on rising edge
PAUSE 1 ; data read time
NEXT Idx ; do rest of the bits
INPUT DI ; leave data line tri-stated
RETURN

' --------------------------------------------------------------------------

All the best; Happy NEW Year !!!

Darrel Taylor
- 30th December 2008, 21:32
Wow, you have to wait 1-1/4 seconds after the reset.

That's quite a "Bug".

Especially since the datasheet says ...
1 second after reset , if no action to the module, the chip will be into standby status within one second if no action after reset.

Well, at least it works!

Happy NEW YEAR!

robert.quaas
- 31st December 2008, 04:38
Thanks Darrel for your help.

All the best and Happy New Year

Robert Quaas