Pic 16f88 AD4 audio Player mikrobasic pro program.

Post your requests and ideas on the future development of mikroBasic PRO for PIC.
Author
Message
leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Pic 16f88 AD4 audio Player mikrobasic pro program.

#1 Post by leo73 » 30 Oct 2014 18:42

Reading a wtv020sd Arduino library i started to traslate arduino language to MikroBasic pro language , afther few month i made a rigth code to manage the sound module by pic.
This program manage the wtv020sd to play the song in sd memory.
Before you'll copy the conveted songs in sd you have to rename songs name, how follow:
0001.ad4, 0002.ad4, 0003.ad4.....256 songs max.
In attached files there's mp3 to ad4 program converter.

======= what about program Job============
The program is wrote using a AD4-module time Table Signal (in dataSheet book), the SendCommand(hex Addr) Subrutine convert a 16bit Address word in a serial Word to send to AD4-Module(using FOR-cicle and bit compare operation "<<").
The program send, using DI(pin10 module), a serial 16bit command, example if you want listen the song number one
you need to send command 0X0000, song number 2 0X0001,...all this synchronized by the clock signal(pin7 sound-module). Additional command is play/stop: 0XFFFE, VOLUME MAX:OXFFF7, VOLUME MIN:OXFFF0 and Stop:
OXFFFF.
====== Program CORE: =================
for i = 15 to 0 step -1
porta.2=0 ' Pone il pin ra2 (A4-ClockPin) a Livello Basso
delay_us(50) ' Attesa 50ms
if((addr>>i) and %0001 >0) then 'confronta bit per bit se c'e un 1 o uno 0
' con in metodo dello shift e del AND
porta.3=1'Spedisce in modo seriale livello logico-1 pin ra3(A5-DataPin)Alto

else
porta.3=0'Spedisce in modo seriale livello logico-1 pin ra3(A5-DataPin)Basso
end if
' scrive i dato(bit) digitale appena inviato
delay_us(50) ' Attesa 50ms
porta.2=1 ' setta il pin ra2 (A4-ClockPin) alto
next i

If you want convert an Parallel Address in Serial Address you have to use follow Metod:
1) example:addr=001F (H) and i=3 --> the operation addr>>i, make shift 3 Time the addr:
addr=0000-0000-0001-1111 >> 3 become addr=0000-0000-0000-0011 (0003H).
2) how undestand if the 3° bit is 0 or 1 you have to make this operation:
addr>>i and %0001 >0 if the condition is TRUE the 3° bit is 1 if the condition is FALSE is the 3°bit is 0
3) If you'll repeat FOR cicle for 15 bit Values you could convert the parallel Information in serial Information on Porta.3(by pic)
================== end Program Desciption =================
The resistors (betwin mcu and sound-module) is used because pic use 5Volt signal and the module 3,3Volt Signal.

I am available to explain how the program could be work. :wink:

IMPORTANT:Is required to use only a Micro-SD 2gb SanDisk Brand, format sd by fat16, Loadin sd Card .AD4 files and powered Sound-Module using 3,3 Volt, i tested it stand-alone and it work.
Attachments
Lettore AD4Mikrobasic Pro Update GOOD WORK!!!!-30-Nov-04.zip
Now it WORK Try and improve it.
Next step is how listen the complete sounds track time.
(1.32 MiB) Downloaded 390 times
serial test displaied.zip
the file display on 16x2 lcd the digital value from a exadecimal value 16bit.
!!!!!!!!! It work !!!!!!!
(35.21 KiB) Downloaded 286 times
SchemaLettoreAD4.JPG
SchemaLettoreAD4.JPG (159.59 KiB) Viewed 9792 times
Last edited by leo73 on 30 Nov 2014 23:22, edited 6 times in total.

leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Re: Pic 16f88 AD4 Player mikrobasic program

#2 Post by leo73 » 30 Nov 2014 22:27

A think, the ad4 player play the songs for few second only (in stand alone or with MCU), some one could help me to undestant the problem? Listening the song is like the module gets blocked, there's simple rate conversion problems? in the same time i could ask to factory if possible.

leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Re: Pic 16f88 AD4 audio Player mikrobasic pro program.

#3 Post by leo73 » 12 Dec 2014 15:04

the player play the songs for few second because 8 ohm Speaker are necessary setting volume at FFF4 else the module going in protection.
Attachments
Player-MikroBasic-CODE-WTV020SD16P Ver 12-Dic-2014.zip
12/Dic/2014
Code more stable then next, if you don't want use the LCD leave ContaTempo Function and LCD declarations.
In the file there's video too.
(5.5 MiB) Downloaded 404 times
Last edited by leo73 on 12 Dec 2014 18:28, edited 1 time in total.

Toley
Posts: 922
Joined: 03 Sep 2008 16:17

Re: Pic 16f88 AD4 audio Player mikrobasic pro program.

#4 Post by Toley » 12 Dec 2014 16:43

Hi leo73,

Libstock is a much better place to post your project. http://www.libstock.com/
Serge T.
Learning is an endeless process but it must start somewhere!

leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Re: Pic 16f88 AD4 audio Player mikrobasic pro program.

#5 Post by leo73 » 12 Dec 2014 18:39

Hi Serge T
Thank you, Next time i'll go to look this site, for me is important share the informations (here and other) about full Experiance , everyone could publish projects (if it's work).
In more Forum there's more people who make's only Problem unless solution, share the Experience help everyone to improve the Experience. Have a good Study.

Bye Leonardo M

leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Re: Pic 16f88 AD4 audio Player mikrobasic pro program.

#6 Post by leo73 » 04 Feb 2015 16:42

This is ultimate Mikrobasic library, i tested it and it Work !!! thanks for your cooperation with Xmaspako.

=====================================================================
program WTV020TestXmaspako

' ResetPin=ra1 OUTPUT
' ClockPin=ra2 OUTPUT
' DataPin=ra3 OUTPUT
' BusyPin=RA4 INPUT


' connections between WTV020 and MCU
dim WTV020_RS as sbit at RA1_bit
WTV020_CL as sbit at RA2_bit
WTV020_DA as sbit at RA3_bit
WTV020_BS as sbit at RA4_bit



WTV020_RS_Direction as sbit at TRISA1_bit
WTV020_CL_Direction as sbit at TRISA2_bit
WTV020_DA_Direction as sbit at TRISA3_bit
WTV020_BS_Direction as sbit at TRISA4_bit



const _PLAY_PAUSE as word = $FFFE
const _STOP as word = $FFFF
const _VOLUME_MIN as word = $FFF0
const _VOLUME_MAX as word = $FFF7

' WTV020 initializas sbit ation
sub procedure Wtv020_Init()
ADCON0=0 'ATTIVA IL CONVERTITORE ANALOGICO DIGITALE
ANSEL=0 ' CONFIGURA TUTTI I PIN ANALOGICI COME DIGITALI
CMCON=0x07 ' SPEGNE IL COMPARATORE
'trisa=%00010001 ' Pone RA0 come Entrata,RA1..RA3 uscita,RA4 come Entrata
'trisb=%00000011 ' Pone RB0,RB1 come Entrata RB3..RB7 come Uscita

'setting up direction
WTV020_CL_Direction=0 ' set line as output
WTV020_DA_Direction=0 ' set line as output
WTV020_RS_Direction=0 ' set line as output
WTV020_BS_Direction=1 ' set line as input
WTV020_CL=0
WTV020_RS=1
'reset pulse
WTV020_RS=0
delay_ms(100)
WTV020_RS=1
'reset idle to start bit
WTV020_CL=1
delay_ms(300)
end Sub

'send command to module
sub procedure Wtv020_SendCommand(dim commando as word)
dim mask as byte
'clock low level pulse
WTV020_CL=0
'initial delay
delay_ms(2)
for mask=15 to 0 step -1
'clock timing
delay_us(50)
'transfer command bit to das sbit ata pin
if ((commando>>mask) and %0001>0) then
WTV020_DA=1
else
WTV020_DA=0
end if
'clock timing
delay_us(50)
'clock high level pulse
WTV020_CL=1
'clock timing
delay_us(50)
if (mask>0) then WTV020_DA=0 'set data pin to low (till last bit)
else WTV020_DA=1 end if
delay_us(50) 'clock timing
if (mask>0) then WTV020_CL=0 'clock low level pulse (till last bit)
else WTV020_CL=1 end if
next mask
'busy active high from last das sbit ata bit las sbit atch
delay_ms(20)
end sub

'play entire song and wait till song ends
sub procedure Wtv020_Play(dim voiceNumber as word)
Wtv020_SendCommand(voiceNumber)
'wait 20ms for busy to be active
delay_ms(20)
'do nothing and wait while BUSY is high
while(WTV020_BS)
wend
end sub

'start playing song and return
sub procedure Wtv020_AsyncPlay(dim voiceNumber as word)
Wtv020_SendCommand(voiceNumber)
end sub

'stop playing song
sub procedure Wtv020_Stop()
Wtv020_SendCommand(_STOP)
end sub

'pause/resume song
sub procedure Wtv020_Pause()
Wtv020_SendCommand(_PLAY_PAUSE)
end sub

'mute sound
sub procedure Wtv020_Mute()
Wtv020_SendCommand(_VOLUME_MIN)
end sub

'set volume (from 0 to 7)
sub procedure Wtv020_Volume(dim volume as byte)
if volume<8 then
Wtv020_SendCommand(_VOLUME_MIN+volume)
else
Wtv020_SendCommand(_VOLUME_MAX)
end if
end sub

'==========MAIN PROGRAM==========
'=======for test purposes========
'================================
main:
dim i as word
Wtv020_Init
'setting volume to half
Wtv020_Volume(4)
for i=0 to 5
Wtv020_AsyncPlay(i)
delay_ms(6000)
next i

'play second voice for 5 secs
'Wtv020_AsyncPlay(1)
'delay_ms(5000)
'pause play for 3 secs
'Wtv020_Pause()
'delay_ms(3000)
'setting volume to max
'Wtv020_Volume(7)
'resume play for 1 sec
'Wtv020_Pause()
'delay_ms(1000)
'Wtv020_Stop()
'play voice 0 till it ends
'Wtv020_Play(0)

end.
=========================================================================

fdapport
Posts: 4
Joined: 27 May 2015 07:31

Re: Pic 16f88 AD4 audio Player mikrobasic pro program.

#7 Post by fdapport » 27 May 2015 08:05

Ciao,
I have some difficult to have the module WTV020-SD16P works. It work manually (play next, previus, etc). When I try with a pic18F2620 I have no sound from the module. I thinks is a problem of timing, I have seen that you have made different versions of the timing on CLK, DATA e Reset PIN. I have attached the current timing from my program. I still using another compiler but the syntax is around the same of mikrobasic. The current set is: ResetPin 5ms, then 300ms... CLK 3ms high, 3ms low when send data, maybe some error in the data timing. The attached picture is for $0004 data value. Please let me know if you see same errors in the data PIN. Any sugestion will be good!!!...Ciao
Attachments
WTV020 time.jpg
WTV020 time.jpg (71.55 KiB) Viewed 8947 times

leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Re: Pic 16f88 AD4 audio Player mikrobasic pro program.

#8 Post by leo73 » 27 May 2015 12:54

Hi Fdapport
I wrote in first time basic code in second time i wrote another time with xmaxpako(nickname) and
I maked correction about the timing, if you are writing in c language you could take the
XMaxpako's c code and try it. I'm sure about this basic code , you have to search in http://www.libstok.com (official site) , here you can search xmaxpako (or if you search my name there my basic program to), If you'll find any errors please you reply in this forum , i'll test your code and if it's more stable than my i'll change the code.
It's very difficult working by sync signals !!!
I have another problem to solve about manage by pic sound module (this is a true mp3 player) the name is DFPlayer Mini, and i seach to coopetate together you or some one else to write a c and basic code to drive this new module, what do you think?
Thank you for your time.
Bye Leonardo.
http://www.libstock.com/

fdapport
Posts: 4
Joined: 27 May 2015 07:31

Re: Pic 16f88 AD4 audio Player mikrobasic pro program.

#9 Post by fdapport » 27 May 2015 20:59

Thanks for the information, I am still develop right now by PicBasic PRO. No C unfortunately. I am still develop a project for telemetry (hardware and software) of RC flight model, like Vario, Air speed, GPS, etc. I need to have a module speaking about altitude without have a LCD display or watch it. Still in the develop test phase...I have try as well the timing that you have in the last post.. same result.. NO VOICE...See last timing sequence attached!!!... the Hardware module is WTV020-SD-16P 2012-01-12 version. I am interested in the new module that you have found, what I need to have the possibility to play number in sequence, link 125 meter with the number syntax, line 100, them 20, 5 .. cento - venti - cinque with busy status PIN. I could share the codes as well or help to find solution.

This is the current PicBasic code copied from yours:

SendCommand:
'Questa subroutine trasforma i comandi esadecimali a 16bit in comandi seriali
'e li invia sul pin ra3(A5 Data-Pin) in ingresso al modulo WTV020-SD-16pin
' il ciclo for permette la realizzazione della trasmissione seriale.
ClockPin=0
DelayMS 2

For II = 15 To 0 Step -1
ClockPin=0 ' Pone il pin ra2 (A4-ClockPin) a Livello Basso
DelayUS 50 ' Attesa 50us prima di inviare dati su dataPin

addrW=addr>>II

addrX=addrW & %0001

If addrX >0 Then 'conftronta bit per bit se c'e un 1 o uno 0 con in metodo dello schift e del AND
DataPin=1 'Spedisce in modo seriale livello logico-1 pin ra3(A5-DataPin)Alto
Else
DataPin=0 'Spedisce in modo seriale livello logico-1 pin ra3(A5-DataPin)Basso
EndIf
DelayUS 50 ' Attesa 50us prima di inviare dati su dataPin
ClockPin=1
DelayUS 50 ' Attesa 50us prima di inviare dati su dataPin

If II>0 Then
DataPin=0
Else
DataPin=1
EndIf

DelayUS 50

If II>0 Then
ClockPin=0
Else
ClockPin=1
EndIf
Next II

'-------------------------------------------------------------------
'Il pin RA4(Busy) sarà per un pò ancora alto dopo aver spedito tutto il comando
DelayMS 20 'meglio attendere un po prima di inviare altri comandi
Return
Attachments
20150523_182635.jpg
20150523_182635.jpg (396.85 KiB) Viewed 8926 times
WTV020_SD005.jpg
WTV020_SD005.jpg (60.51 KiB) Viewed 8926 times
WTV020_SD004.jpg
WTV020_SD004.jpg (43.88 KiB) Viewed 8926 times

leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Re: Pic 16f88 AD4 audio Player mikrobasic pro program.

#10 Post by leo73 » 28 May 2015 18:39

Hi fdapport
Ok, thank you so much, as soon as you
Found rigth time table and changed the microseconds values
copy and paste the entere my picBasic corrected code here and if it's possible save it in a attachment file, is more good what about page layout ;-).
When you'll finish your project, if you want ,you could share it in http://www.libstock.com by your nick name.
See you soon.

fdapport
Posts: 4
Joined: 27 May 2015 07:31

Re: Pic 16f88 AD4 audio Player mikrobasic pro program.

#11 Post by fdapport » 05 Jun 2015 08:05

Finaly WORKS!!!!, see the data timing diagram. The correct PIC basic is the following, count from 2 to 20 (0002.AD4 to 0020.AD4).

Main:
For J=2 To 20
xxx1:
If BusyPin=1 Then GoTo xxx1 ' Verifico il PIN Busy, se alto attendo
DelayMS 10

VoiceNumber=J
GoSub PlayVoiceNumber
Toggle Led
DelayMS 35
Next J

GoTo Main

SendCommand:

ClockPin=0
DelayUS 1950

For II = 15 To 0 Step -1
ClockPin=0 ' Pone il pin ra2 (A4-ClockPin) a Livello Basso
DelayUS 50 ' Attesa 50us prima di inviare dati su dataPin

addrW=addr>>II

addrX=addrW & %0001

If addrX >0 Then 'conftronta bit per bit se c'e un 1 o uno 0 con in metodo dello schift e del AND
DataPin=1 'Spedisce in modo seriale livello logico-1 pin Data Alto
Else
DataPin=0 'Spedisce in modo seriale livello logico-1 pin Data Basso
EndIf
DelayUS 50 ' Attesa 50us prima di inviare dati su dataPin
ClockPin=1
DelayUS 100 ' Attesa 100us prima di inviare dati su dataPin

Next II
DelayUS 1900 ' Attesa 1900us prima di inviare dati su dataPin

DelayMS 20 'meglio attendere un po (20ms) prima di inviare altri comandi
Return
Attachments
WTV020_timing.jpg
WTV020_timing.jpg (93.4 KiB) Viewed 8871 times

leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Re: Pic 16f88 AD4 audio Player mikrobasic pro program.

#12 Post by leo73 » 05 Jun 2015 12:04

Hi fdapport
Well very well, i have to try this new time table, i want make you a recommendation
Don't use jamping code like this:

Main:
For J=2 To 20
xxx1:
If BusyPin=1 Then GoTo xxx1 ' Verifico il PIN Busy, se alto attendo
DelayMS 10

Use:
Main:
For J=2 To 20
While BusyPin=1 ' Verifico il PIN Busy, se alto attendo
Wend
DelayMS 10

It's more elegant and clear.
Leo

leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Re: Pic 16f88 AD4 audio Player mikrobasic pro program.

#13 Post by leo73 » 05 Jun 2015 19:15

I fdapport

i tryed to rewrite your code but it isn't not complite and not clear, i asked you to use the same sintax and make some code corrections and not completely upset the code !!!!!!!!!!! , i cannot try your code if you don't send me full version code !!!!!
Could you send me it please ?

fdapport
Posts: 4
Joined: 27 May 2015 07:31

Re: Pic 16f88 AD4 audio Player mikrobasic pro program.

#14 Post by fdapport » 08 Jun 2015 14:18

The small code was just to test the timing and give the correct delayus that you need to have the module work. The program repeat the numbers from 0 to 20, testing the busy PIN. The important part is the diagram of the time to have it works. On the web we have many different version of the timing to have the module works. One interesting thinks that I didn’t find in any datasheet is that after the command you need to way 35ms before to test the Busy line. See my program below :

Please let me know if you need additional information.


'********************************************************************************************
' Inizio Programma, legge il file 0000.AD4 a 0020.AD4 presenti nella scheda SD
'********************************************************************************************

Main:
For J=0 To 20 ' Ripeto da 0 a 20

While BusyPin=1 ' Aspetta che la scheda torni libera in attesa di comandi
Wend

DelayMS 10 ' Aggiungo un ritardo di 10ms, per poter funzionare è necessario

VoiceNumber=J ' File da riprodurre , come J.AD4
GoSub PlayVoiceNumber ' Eseguo la routine
Toggle Led ' lampeggio il LED
DelayMS 35 ' Ritardo di 35ms dopo avere lanciato la lettura del file
Next J

GoTo Main


'********************************************************************************************
' Routine PlayVoiceNumber, legge il file
'********************************************************************************************
' Input=VoiceNumber
PlayVoiceNumber:
addr=VoiceNumber
GoSub SendCommand ' Spedisce il comando in modo seriale sulla linea dati/clock
While BusyPin=1 ' Aspetta che la scheda torni libera in attesa di comandi
Wend
Return

'********************************************************************************************
' Routine SendCommand, serializza i comandi
'********************************************************************************************
SendCommand:
' Input=Addr

ClockPin=0 ' Pin Clock BASSO
DelayUS 1950 ' Aspetto 1950 us (1.95ms)

For II = 15 To 0 Step -1
ClockPin=0 ' Pone il pin clock a Livello Basso
DelayUS 50 ' Attesa 50us prima di inviare dati su dataPin

addrW=addr>>II ' "Shifto" di II posizioni

addrX=addrW & %0001 ' faccio un AND con la maschera %0001

If addrX >0 Then ' confronta bit per bit se c'e un 1 o uno 0 con in metodo dello schift e del AND
DataPin=1 ' Spedisce in modo seriale livello DataPin Alto se uquale a 1
Else
DataPin=0 ' Spedisce in modo seriale livello DataPin Basso se uquale a 0
EndIf
DelayUS 50 ' Attesa 50us prima di inviare dati su dataPin
ClockPin=1 ' metto alto il Clock
DelayUS 100 ' Attesa 100us

Next II ' Ripeto
Return

leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Re: Pic 16f88 AD4 audio Player mikrobasic pro program.

#15 Post by leo73 » 08 Jun 2015 17:55

Hi fdapport

Thank you to this code, i understood whi your sintax code is a little bit different , because you don't use mikrobasic compiler !!! Unfortunately i don't have more documents but have only this Datasheets in attacment, they are cinese and it's made very bad.(what about specifications)
Attachments
DFPlayer Mini Manul.pdf
This is the real mp3 module how i spoke, you can plug in serial port to pic, and in usb port to personal computer, it's interesting write the pic basik code.
(422.65 KiB) Downloaded 265 times
WT588D-U Voice Module.pdf
Similar module
(309.61 KiB) Downloaded 240 times
WTV020_manual_V1.3.pdf
(455.75 KiB) Downloaded 224 times

Post Reply

Return to “mikroBasic PRO for PIC Wish List”