Jump to content

pga/aout programming


pilo

Recommended Posts

I try to send value to the TI chip pga4311, it works like the aout module so I only change the aout.inc file... And it doesn't work (the pga4311 seems to be in mute mode, it doesn't received the right value).

here's the code :

#define PGA_LAT_CS      LATC      ; The chip select pin CS#
#define PGA_TRIS_CS      TRISC      ; is connected to Port C.5 
#define PGA_PIN_CS      5      ; (CANNOT be shared with other outputs!)
;
#define PGA_LAT_DIN      LATC      ; The data input pin DIN
#define PGA_TRIS_DIN      TRISC      ; is connected to Port C.4 
#define PGA_PIN_DIN      4      ; (can be shared with other outputs)
;
#define PGA_LAT_SCLK      LATD      ; The shift clock input pin SCLK
#define PGA_TRIS_SCLK      TRISD      ; is connected to Port D.3 
#define PGA_PIN_SCLK      3      ; (can be shared with other outputs)
;
; Number of connected MAX525
;
#define PGA_NUMBER_OF_CHANNEL 4      ; either PGA2310, PGA2311 or PGA4311
;                        ; -> makes 8 Channel
;
; ==========================================================================
;
; Copyright (C) 2003  Thorsten Klose (Thorsten.Klose@gmx.de)
; 
; ==========================================================================
; 
; This file is part of an MIOS example application
;
; This application is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This application is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this application; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
;
; ==========================================================================

PGA_Init
      ;; enable pin drivers
      bcf      PGA_TRIS_CS, PGA_PIN_CS
      bcf      PGA_TRIS_DIN, PGA_PIN_DIN
      bcf      PGA_TRIS_SCLK, PGA_PIN_SCLK
      
;; --------------------------------------------------------------------------
;;  FUNCTION: PGA_SEND_GAIN
;;  DESCRIPTION: This function set for all channel (CHANNEL_GAIN_0 to CHANNEL_GAIN_7)
;;  IN:   o gain value in CHANNEL_GAIN_0 to CHANNEL_GAIN_7
;;  OUT:  -
;;  USES: BSR --- PGA_SR contains unknown values after the load procedure
;; --------------------------------------------------------------------------
PGA_SEND_GAIN
      IRQ_DISABLE                        ; disable interrupts
      ;; (for the case that interrupt driven pins are used)

      bcf      PGA_LAT_CS, PGA_PIN_CS      ; activate chip select
        bcf      PGA_LAT_SCLK, PGA_PIN_SCLK      ; clear clock

      
      movlw      PGA_NUMBER_OF_CHANNEL-1            ; init outer loop counter
      movwf      PGA_SR_CTR
PGA_LoadSR_OuterLoop
      clrf      PGA_SR_BIT_CTR      ; clear inner loop counter
      
      ;; pointer = current pga channel
      lfsr      FSR0, CHANNEL_GAIN_0      
      movlw      PGA_NUMBER_OF_CHANNEL
      subfwb      PGA_SR_CTR, W
      addwf      FSR0L, F
      movff      INDF0, PGA_SR
      
      
PGA_LoadSR_Value
PGA_LoadSR_Value_Loop
      bcf      PGA_LAT_DIN, PGA_PIN_DIN      ; set DIN depending on current MSB
      btfsc      PGA_SR, 7
      bsf      PGA_LAT_DIN, PGA_PIN_DIN
      
      rlf      PGA_SR, F            ; start to shift the 8-bit value
      
      bsf      PGA_LAT_SCLK, PGA_PIN_SCLK      ; rising clock edge
      nop
      bcf      PGA_LAT_SCLK, PGA_PIN_SCLK      ; falling clock edge
      
      incf      PGA_SR_BIT_CTR, F      ; loop 8 times
      btfsc      PGA_SR_BIT_CTR, 3
      rgoto   PGA_LoadSR_Value_Loop

PGA_LoadSR_Next
      ;; loop until last register reached
      decf      PGA_SR_CTR, F
      bc      PGA_LoadSR_OuterLoop

      bsf      PGA_LAT_CS, PGA_PIN_CS      ; deactivate chip select

      IRQ_ENABLE                        ; enable interrupts again
      return

thanks!

Link to comment
Share on other sites

The pointer calculation part could be wrong (looks dangerous ;-) - why not initialising FSR0 with CHANNEL_GAIN_7 before the outer loop will be entered, and accessing the register with POSTDEC0, so that it will be decremented automatically

(But I'm not sure if this is the error...)

Best Regards, Thorsten.

Link to comment
Share on other sites

mmm I though I made an error in the output ;)

But yeah it's a great idea ;) I just start with pic programming (and with MIOS it's a lot of fun!!)

BUT I just reallized I put the /mute output low... and so it mute the chip... how stupid I am!!!!

let me try it again!

thanks!

Link to comment
Share on other sites

It always makes sense to output some values on a LCD, or just to send them out via MIDI to get some kind of logfile (here you only have to ensure that the MIDI protocol won't be violated - means: first byte should be a status byte like 0xF0, thereafter as much bytes as you want, but 7th bit should never be set (ensure this by masking it with 0x7f - the stream must end with a 0xf7)

Best Regards, Thorsten.

Link to comment
Share on other sites

I can already display the value (in db, between -95.5 a,d + 31.5 corresponding to the byte value store in CHANNEL_GAIN_*), but as I "rewrote" the output function, I though the error came from here...

it's smd package, hard to unsolder one pin... I think I can do it (and I hope!!!!lol)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...