TDA8425 I2C Audio Processor
Hier wat code voorbeelden voor de TDA8425 I2C Audio Processor.
Om te beginnen een voorbeeld met 2 knops bediening (mode knop en adjust knop).
'****************************************************************
'* Name : TDA8425 2 knops bediening *
'* Author : Knutselaar *
'* Notice : Copyright (c) 2014 Knutselaar.eu *
'* : All Rights Reserved *
'* Date : 05/12/2014 *
'* Version : 1.0 *
'* Notes : Met TEA5767 als geluidsbron *
'****************************************************************
Device 18F25K22
CONFIG_START
FOSC = INTIO67 ;Internal oscillator block, port function on RA6 and RA7
FCMEN = Off ;Fail-Safe Clock Monitor disabled
IESO = Off ;internal external switchover mode
;PWRT = On ;power-up timer For 18F25K20
PWRTEN = On ;power-up timer For 18F25K22
BOREN = On ;brown-out reset
;BORV = 27 ;brown-out reset value (2,7V) For 18F25K20
BORV = 285 ;brown-out reset value (2,85V) for 18F25K22
WDTEN = Off ;watchdog timer
WDTPS = 128 ;1:128 WDT prescalar
PBADEN = Off ;analog port B<4:0>
STVREN = On ;stack overflow reset
LVP = Off ;low voltage programming
XINST = Off ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
Debug = Off ;no debug
CONFIG_END
XTAL 16
OSCCON = %01110000 ; 16Mhz intern osc
ANSELA = %00000000 ; 18F25K22 poort A digitaal
ANSELB = %00000000 ; 18F25K22 poort B digitaal
ANSELC = %00000000 ; 18F25K22 Poort C digitaal
Declare CCP1_PIN PORTC.2 'opwekking + 12V (zie schema)
Symbol Speaker = PORTC.5
Symbol LEDGreen = LATA.5
Symbol ButtonAdjust = PORTC.1
Symbol ButtonMode = PORTC.0
Dim TDA8425 As Byte
Dim TEA5767 As Byte
Dim Frequentie As Word
Dim Pll As DWord
Dim x As Byte
Dim mode As Byte
Dim volume As Byte
Dim volumeL As Byte
Dim volumeR As Byte
Dim volumePrint As sByte ;display weergave
Dim bass As Byte
Dim bassPrint As sByte ;display weergave
Dim treble As Byte
Dim treblePrint As sByte ;display weergave
Dim balance As sbyte
Dim absBalance As Byte
Dim chanel As Bit
Dim chanalSwitch As Byte
Clear ; wis geheugen
volumeL = 248 ; loopt van 220 tot 255 in stappen van 2dB
volumeR = 248
volume = 248
bass = 246 ; loopt van 242 (-12dB) tot 251 (+15dB) in stappen van 3dB
treble = 246 ; loopt van 242 (-12dB) tot 250 (+12dB) in stappen van 3dB
balance = 0
TDA8425 = %10000011
TEA5767 = %11000001
;TEA5767 FM module gebruikt als geluidsbron
Frequentie = 1021 ; 102.1 Mhz (538 amstelveen)
GoSub progTEA5767
HPWM 1,127,15000 ; voor opwekken +12V spanning (via C2)
Cls ; init display
Sound Speaker , [115,20]
Print At 1,1, "Knutselaar.eu "
Print At 2, 1, "TDA8425 Test "
;TDA8425 Power On init
HBusOut TDA8425, %00000000,[ volumeL,volumeR,bass,treble ]
HBusOut TDA8425, %00001000,[ %11001110] ;switch fuctie: linear stereo, channel 1 (pin 18, 20), mute off
;[ %11001111] ;switch fuctie: linear stereo, channel 2 (pin 1, 3), mute off
DelayMS 2000
volumePrint = (volume - 252)*2 ;Volume op display: stappen van 2dB, -42dB tot + 6dB
loop:
For x = 1 To 70 ;70 x 50mS = 3.5 seconden loop
If ButtonAdjust = 0 Then x = 1 : GoSub adjustTDA ;Knop op poort C.1
If ButtonMode = 0 Then x = 1 : GoSub setMode ;Knop op poort C.0
DelayMS 50
Next x
mode = 0 ;mode terugzetten naar volume up
GoSub printTDA8425Status ;3.5 seconden na laatste knopdruk komt status scherm weer terug
Toggle LEDGreen
GoTo loop
adjustTDA:
Select mode
Case 1 ;volume up
volume = volume + 1 ; stappen 2dB
;begrenst tot >= 255 (+6dB), tevens max
;+ absBalance is balans correctie voor maximum.
;volume + balance mag niet boven 255 komen
If volume + absBalance -1 >= 255 Then volume = volume - 1 : Sound Speaker, [120,10]
volumeL = volume + balance
volumeR = volume - balance
volumePrint = (volume - 252)*2
Print At 2,1, SDEC volumePrint," "
Case 2 ;volume down
volume = volume - 1
;begrenst tot < 231 (-42dB), 220(-64dB) is minimum
;- absBalance is balans correctie voor minimum
If volume - absBalance < 231 Then volume = 231 + absBalance : Sound Speaker, [120,10]
volumeL = volume + balance
volumeR = volume - balance
volumePrint = (volume - 252)*2
Print At 2,1, SDEC volumePrint, " "
Case 3 ;bas up
bass = bass + 1 ;stappen van 3dB
;begrenst tot >251 (+ 15dB) is maximum
If bass > 251 Then bass = 251 : Sound Speaker, [120,10]
bassPrint = bass - 246
Print At 2,1, SDEC bassPrint, " "
Case 4 ;bas down
bass = bass - 1
;begrenst tot <242 (-12dB), is minimum
If bass < 242 Then bass = 242 : Sound Speaker, [120,10]
bassPrint = bass - 246
Print At 2,1, SDEC bassPrint, " "
Case 5 ;treble up
treble = treble + 1
;begrenst tot >250 (+12dB), is maximum
If treble > 250 Then treble = 250 : Sound Speaker, [120,10]
treblePrint = treble - 246
Print At 2,1, SDEC treblePrint, " "
Case 6 ;treble down
treble = treble - 1
;begrenst tot <242 (-12dB), is minimum
If treble < 242 Then treble = 242 : Sound Speaker, [120,10]
treblePrint = treble - 246
Print At 2,1, SDEC treblePrint, " "
Case 7 ;balans naar links
balance = balance + 1
;begrenst tot 6 stappen (2 x 6dB = 12dB per kanaal, is 24dB kanaal verschil)
If balance > 6 Then balance = 6 : Sound Speaker, [120,10]
absBalance = Abs(balance)
;volume correctie voor maximaal 255 (=6dB)
If volume + absBalance -1 >= 255 Then volume = volume - 1
volumeL = volume + balance
volumeR = volume - balance
volumePrint = (volume - 252)*2
Print At 2,1, SDEC balance," "
Case 8 ;balans naar rechts
balance = balance - 1 ;balance is SBYTE, gaat dus negatief
;begrenst tot 6 stappen (2 x 6dB = 12dB per kanaal, is 24dB kanaal verschil)
If balance < -6 Then balance = -6 : Sound Speaker, [120,10]
absBalance = Abs(balance)
;volume correctie voor maximaal 255 (=6dB)
If volume + absBalance -1 >= 255 Then volume = volume - 1
volumeL = volume + balance
volumeR = volume - balance
volumePrint = (volume - 252)*2
Print At 2,1, SDEC balance," "
Case 9 ;ingangs kanaal selectie
chanel = chanel + 1 ;chanel is bit, schakelt dus tussen 1 en 0 als je er 1 bij optelt.
If chanel = 0 Then
Print At 2,1, "Ingang 1 "
Else
Print At 2,1, "Ingang 2 "
End If
End Select
HBusOut TDA8425, %00000000,[ volumeL,volumeR,bass,treble ] ;geluid instellen
chanalSwitch = %11001110 + chanel
HBusOut TDA8425 , %00001000,[ chanalSwitch ] ;ingangs kanaal keuze
Sound Speaker, [115,10]
DelayMS 300
Return
setMode:
mode = mode + 1
If mode = 10 Then mode = 1
Select mode
Case 1
Print At 1,1, "Volume Up "
Print At 2,1, SDEC volumePrint, " "
Case 2
Print At 1,1, "Volume Down "
Print At 2,1, SDEC volumePrint, " "
Case 3
Print At 1,1, "Bas Up "
Print At 2,1, SDEC bassPrint, " "
Case 4
Print At 1,1, "Bas Down "
Print At 2,1, SDEC bassPrint, " "
Case 5
Print At 1,1, "Hoog Up "
Print At 2,1, SDEC treblePrint, " "
Case 6
Print At 1,1, "Hoog Down "
Print At 2,1, SDEC treblePrint, " "
Case 7
Print At 1,1, "Balance + rechts "
Print At 2,1, SDEC balance, " "
Case 8
Print At 1,1, "Balance + links "
Print At 2,1, SDEC balance, " "
Case 9
Print At 1,1, "Chanel select "
If chanel = 0 Then
Print At 2,1, "Ingang 1 "
Else
Print At 2,1, "Ingang 2 "
End If
End Select
Sound Speaker, [115,10]
DelayMS 500
Return
printTDA8425Status:
Print At 1, 1, "Vol=", SDEC volumePrint, "dB Chan=", Dec chanel + 1
Print At 2, 1, "Treble=", SDEC treblePrint, " Bass=", SDEC bassPrint, " "
Return
progTEA5767:
Pll = Frequentie * 100000 - 225000
Pll = Pll * 4 / 32768
HBusOut TEA5767,[Pll.BYTE1,Pll.BYTE0,$0,$10,$00]
Return
End