Jump to content

error compiling c app


moxi
 Share

Recommended Posts

Propably because you toggle the SCLK two times within the loop?

In addition, it makes sense to insert a NOP or another instruction between the toggle as well in order to add some delay for a proper pulse

Best Regards, Thorsten.

Link to comment
Share on other sites

  • Replies 106
  • Created
  • Last Reply

Top Posters In This Topic

it's good, i've removed the second

  bsf  CV_AOUT_LC_LAT_SCLK, CV_AOUT_LC_PIN_SCLK  ; rising clock edge  MOVED FOR AOUT_LC DRIVER

  bcf  CV_AOUT_LC_LAT_SCLK, CV_AOUT_LC_PIN_SCLK  ; falling clock edge

from your code and that works..

1 get the right pattern for the two values...

Link to comment
Share on other sites

:),

thanks again for your hint TK.

now the code is working for my four cv output:

the define in aout.h:

#if 1

//common AOUT_LC connections

#define AOUT_LC_LAT_RCLK     _LATC // The latch enable input

#define AOUT_LC_TRIS_RCLK _TRISC //is connected to Port C.5

#define AOUT_LC_PIN_RCLK     5 // (CANNOT be shared with other outputs!)

#define AOUT_LC_LAT_DOUT     _LATC // The data pin

#define AOUT_LC_TRIS_DOUT _TRISC //is connected to Port C.4

#define AOUT_LC_PIN_DOUT     4 //(can be shared with other outputs)

#define AOUT_LC_LAT_SCLK     _LATD // The shift clock input pin SCLK

#define AOUT_LC_TRIS_SCLK _TRISD // is connected to Port D.5

#define AOUT_LC_PIN_SCLK     5 //(can be shared with other outputs)

#endif

the new code for the file aout.c:

/*

* AOUT_LC program module

* This module is contains a lot of assembler-optimized code for fastest execution

*

* ==========================================================================

*

* Copyright © 2005  Thorsten Klose (tk@midibox.org)

*

* ==========================================================================

*

* This file is part of a MIOS 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

*

* ==========================================================================

*/

/////////////////////////////////////////////////////////////////////////////

// Include files

/////////////////////////////////////////////////////////////////////////////

#include "cmios.h"

#include "pic18f452.h"

#include "main.h"

#include "aout.h"

/////////////////////////////////////////////////////////////////////////////

// Global variables

/////////////////////////////////////////////////////////////////////////////

// AOUT values

unsigned int aout_value[8];

// stores the last AOUT values (to determine, if the shift registers have to be updated)

unsigned int last_aout_value[8];

// the gate pins

aout_gates_t aout_gates;

// last state of the aout gate flags to determine changes

aout_gates_t last_aout_gates;

/////////////////////////////////////////////////////////////////////////////

// This function initializes the AOUT module

/////////////////////////////////////////////////////////////////////////////

void AOUT_Init(void)

{

  unsigned char i;

  // Enable pin drivers

__asm

;; since the pins are defined in assembler-friendly syntax (-> aout.h)

;; we have to clear the pins within an ASM block

bcf AOUT_LC_TRIS_RCLK, AOUT_LC_PIN_RCLK

    bcf AOUT_LC_TRIS_DOUT, AOUT_LC_PIN_DOUT

bcf AOUT_LC_TRIS_RCLK, AOUT_LC_PIN_SCLK

__endasm;

  // clear gate pins and request update

  aout_gates.ALL = 0x00;

  last_aout_gates.ALL = 0xff;

  // set AOUT voltages to 0V and request update

  for(i=0; i<sizeof(aout_value); ++i) {

    aout_value = 0x0000;

    last_aout_value = 0xffff;

  }

}

/////////////////////////////////////////////////////////////////////////////

// This is an internal assembler function which updates four chained

// 74HC595 devices

/////////////////////////////////////////////////////////////////////////////

// following variables are placed outside the function (instead of making them static)

// to simplify the addressing within an assembler block

unsigned char loop_ctr;    // loop counter

unsigned int aout_sr0; // chain data

unsigned int aout_sr1;

void AOUT_Load2SR(unsigned int sr0_value, unsigned int sr1_value)

{

  aout_sr0 = sr0_value;

  aout_sr1 = sr1_value;

__asm

        bcf    AOUT_LC_LAT_SCLK, AOUT_LC_PIN_SCLK  ; clear clock  COPIED FROM MBCV DRIVER

  ;; bcf  AOUT_LAT_CS, AOUT_PIN_CS  ; activate chip select  NOT NEEDED FOR AOUT_LC

  ;; I believe that the below might be able to be ignored for the AOUT_LC?

  ;; you will notice that the instructions are sometimes arranged

  ;; in a special order to ensure proper output signals - for example:

  ;; between a rising and a falling SCLK edge there is at least one

  ;; other instruction to ensure that the high pulse of the SCLK

  ;; is longer than 100 nS (the MAX525 datasheet specifies at least 40 nS)

  banksel _loop_ctr

  movlw  32            ; init loop counter  FOR 2 AOUT_LC modules

  movwf  _loop_ctr, 1

  ;; This is the same as the original AOUT driver with the names changed, and the latching copied from the MBCV

AOUT_Load2SR_Loop:

  banksel _aout_sr0

  bcf  AOUT_LC_LAT_DOUT, AOUT_LC_PIN_DOUT  ; set DOUT depending on current MSB

  btfsc  _aout_sr1+1, 7, 1

  bsf  AOUT_LC_LAT_DOUT, AOUT_LC_PIN_DOUT

  rlcf  _aout_sr0+0, F, 1      ; start to shift the 16-bit value

  rlcf  _aout_sr0+1, F, 1      ; second step for the 16-bit shift

  rlcf  _aout_sr1+0, F, 1      ; third step for the 16-bit shift

  rlcf  _aout_sr1+1, F, 1      ; last step for the 16-bit shift

  bsf  AOUT_LC_LAT_SCLK, AOUT_LC_PIN_SCLK  ; rising clock edge  MOVED FOR AOUT_LC DRIVER

  nop  ;; not sure it's the right place, but that works

  bcf  AOUT_LC_LAT_SCLK, AOUT_LC_PIN_SCLK  ; falling clock edge

  banksel _loop_ctr

  decfsz  _loop_ctr, F, 1      ; loop 32 times

  bra  AOUT_Load2SR_Loop

    bsf    AOUT_LC_LAT_RCLK, AOUT_LC_PIN_RCLK  ; latch SID values

  bcf  AOUT_LC_LAT_DOUT, AOUT_LC_PIN_DOUT  ; clear out pin (standby)

    bcf    AOUT_LC_LAT_RCLK, AOUT_LC_PIN_RCLK  ; release latch

__endasm;

}

/////////////////////////////////////////////////////////////////////////////

// This function should be called from USER_Tick() to update the requested

// AOUT pins

/////////////////////////////////////////////////////////////////////////////

void AOUT_Update(void)

{

  if( (aout_value[0] != last_aout_value[0]) || (aout_value[2] != last_aout_value[2]) ) {

    AOUT_Load2SR(aout_value[0] | (0x3000) | (0xff00), aout_value[2] | (0x3000) | (0xff00));

    last_aout_value[0] = aout_value[0];

    last_aout_value[2] = aout_value[2];

}

if( (aout_value[1] != last_aout_value[1]) || (aout_value[3] != last_aout_value[3]) ) {

    AOUT_Load2SR(aout_value[1] << 8 | (0x3000) | (0xff), aout_value[3] <<8 | (0x3000) | (0xff));

    last_aout_value[1] = aout_value[1];

    last_aout_value[3] = aout_value[3];

}

}

AOUT Update of the gate is missing, as i won't use them.

my two aout_lc modules are set in 8/8bit configuration,

my map.c file is configured to load 8 bit value in  aout_value[x]  :

example, for my first CV:

  ///////////////////////////////////////////////////////////////////////////

  // AOUT #1: forward CC7 of MIDI channel #1

  aout_value[0] = CONV_7BIT_TO_8BIT(midi_cc_chn0[7]);

there is probably useless code in the AOUT_Update function...but i've make it working doing a lot of hardware testing, and as i'm a beginner ,i'm not sure that i  understood all things fine...

thanks you all..

Link to comment
Share on other sites

There is still room for improvements. ;-)

You can remove the channel selection (OR combination with 0x3000), otherwise you will get wrong results on Channel 2 and 4 (or 1 and 3? don't know).

In addition, since 32 bits are transfered with one run, you have to arrange the 8bit values in the following way:

void AOUT_Update(void)
{
  if( aout_value[0] != last_aout_value[0] ||
      aout_value[1] != last_aout_value[1] ||
      aout_value[2] != last_aout_value[2] ||
      aout_value[3] != last_aout_value[3] ) {

    AOUT_Load2SR(((aout_value[1]&0xff) << 8) | (aout_value[0]&0xff),
                ((aout_value[3]&0xff) << 8) | (aout_value[2]&0xff));

    last_aout_value[0] = aout_value[0];
    last_aout_value[1] = aout_value[1];
    last_aout_value[2] = aout_value[2];
    last_aout_value[3] = aout_value[3];
  }
}
[/code]

otherwise the second Load2SR will overwrite the values of the first.

Best Regards, Thorsten.

Link to comment
Share on other sites

You can remove the channel selection (OR combination with 0x3000), otherwise you will get wrong results on Channel 2 and 4 (or 1 and 3? don't know).

it's exactly why i've tested many bit manipulation!

i will try this tonight...your code is more clear!

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...
 Share


×
×
  • Create New...