This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Code Composer Studio problem

Hi,

I would like to say that I am new to programming with hardware. I am currently programming on a TSM320C6713 DSK on CCS v3.3. I'm trying to take an analog input, convert it to a value that I can use to create a PWM. I have several problems with  the code.

First, when I call any functions from the c6713dskinit.c source file, my program falls in an infinite loop somewhere in the disassembly. I don't know why it does, is if that my file is outdated or corrupted? There's no errors in building the code.

Second, I tried to use this:

        union {Uint32 combo; short channel[2];} temp;

        temp.combo = MCBSP_read(DSK6713_AIC23_DATAHANDLE);

to store the input, but it doesn't work. Do I miss something with that?

I read many treads and documentations without find a example that works with my project.  I would apreciate any tips, links, examples that would help me get this done.

It has been modified several times, but here is my code:

#include "stdio.h"
#include "dsk6713.h"
#include "dsk6713_dip.h"
#include "dsk6713_led.h"
#include "dsk6713_aic23.h"
#include <csl.h>
#include <csl_timer.h>
#include <csl_irq.h>
#include <csl_gpio.h>

Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;

#define CTL1 0x01980000        //Adress des registre utiles pour le programme
#define CNT1 0x01980008
#define PRD1 0x01980004
#define GPEN 0x01B00000
#define GPDIR 0x01B00004
#define GPVAL 0x01B00008
#define GPPOL 0x01B00024
#define DSK6713_AIC23_INPUT_MIC 0x0015
#define DSK6713_AIC23_INPUT_LINE 0x0011
#define CHIP_6713 1
#define squareTableLen 800
#define table_size (int)0x100 //size of table = 256
#define    LEFT    0
#define    RIGHT    1
int data_table[table_size]; //data table array

Uint16 inputsource=DSK6713_AIC23_INPUT_LINE;                      

unsigned int intTemp;

short q = 0;
short x = 0;
short y = 0;
short z = 0;
short w = 0;
short length = 99;
short v = 0;
short loop_index = 0;
short table[64] = {0};
short ttick = 0;
int i = 0;
short loop = 0; //table index
short gain =1;
short frequency = 1;
short square_table[squareTableLen]={0}; // table initialization

union {Uint32 combo; short channel[2];} AIC23_data;

void dsk_init(void) //interrupt service routine
{
    intTemp = *(unsigned int *)GPEN;
    intTemp = intTemp|0x07B;
    *(unsigned int*)GPEN = intTemp;        //Active la pin 3

    intTemp = *(unsigned int *)GPDIR;
    intTemp = intTemp & 0xFFFFFF8F;
    intTemp = intTemp | 0x0000000B;            //Sélectionne la pin 3 comme output
    *(unsigned int*)GPDIR = intTemp;

    *(unsigned int *) PRD1 = 3516;    // On configure le timer0 à 8 KHz

    *(unsigned int *) CTL1 = 0x3C7;        // Configure le timer0 en osc interne

}

interrupt void c_int11() //interrupt service routine
{

} // end of interrpt routine

void main(void)
 {
    DSK6713_init();
    
    dsk_init();

    DSK6713_DIP_init(); //Initialize DIP switches

    DSK6713_LED_init(); //Initialize LEDs

    ttick = 0;

    for(q = 0; q < 4; q++)
    {
        printf("Hello World!\n");
    }

    while(1)
    {
        int t;

        AIC23_data.combo = MCBSP_read(DSK6713_AIC23_DATAHANDLE);

        t = (AIC23_data.channel[0]*100)/35;

        x = (t*2860)/100;                         // Le nombre d'échantillion donne la période du PWM
        v = 2860 - x;

        for(y = 0; y < x; y++)
        {
            intTemp = *(unsigned int *)GPVAL;
            intTemp = intTemp|0x00000004;
            *(unsigned int*)GPVAL = intTemp;        //Active la pin 3
            w++;
        }

        for(z = 0; z < v; z++)
        {
            intTemp = *(unsigned int *)GPVAL;
            intTemp = intTemp & 0x00000000;
            *(unsigned int*)GPVAL = intTemp;
            w++;
        }

        if(DSK6713_DIP_get(0)==1)
        {
            DSK6713_LED_on(3);
            intTemp = *(unsigned int *)GPVAL;
            intTemp = intTemp|0x00000003;
            *(unsigned int*)GPVAL = intTemp;
        }

        else
        {
            DSK6713_LED_off(3);
            intTemp = *(unsigned int *)GPVAL;
            intTemp = intTemp | 0x0000000B;
            intTemp = intTemp & 0xFFFFFFFC;
            *(unsigned int*)GPVAL = intTemp;
        }

        if(DSK6713_DIP_get(1)==0)
        {
            DSK6713_LED_on(2);
        }

        else
        {
            DSK6713_LED_off(2);
        }
    }
}




void timer_isr(void)
{
    ttick++;
    return;
}

  • Hi Vincent,

    Sounds like your question is more related to the BSL than with CCS. i will move this to the C67x device forum. There should be more expertise with the 6713DSK BSL there and hopefully you can find the answers you seek.

    Thanks

    ki

  • Vincent,

    First, which functions in c6713dskinit.c cause your program to go into an infinite loop? What is the nature of the infinite loop? In particular, in which function in c6713dskinit.c does this happen? For debug purposes, you can include c6713dskinit.c in your project and that source will replace the similar functions in the library; this will give you the ability to step into the source of the functions in that file.

    Second, when you use the union, in what way does it not work? Does it work if you use a simple Uint32 variable instead?

    From which example file did you start to build your program? In particular the parts where you initialize the GPIOs and Timer?

    Sorry these are just questions, but we will be able to help you find the problem through the probing questions.

    Regards,
    RandyP

  • Hi Randy,

    First, the file c6713dskinit.c is in my project and it falls in this infinite loop:

    if (1) while(!MCBSP_xrdy(DSK6713_AIC23_DATAHANDLE));//if ready to transmit

    When I call comm_intr, it follows in the function output_sample, where is the line above. I suppose the datahandle is never ready but I don't know why.

    Second, it doesn't work with a simple Uint32 variable. What I am trying to do is to take an analog signal, put it in a variable that I can program a ratio with. For that, I need the Line In and the MIC inputs to work (The MIC input will be for later but I guess it will be the same way to make it work)  and the value range the input is in the program (example: If I put 3.3V in the input, what value will it have in the code).

    Third, the example I use to start the code is an old code from my superior with the GPIOs and the Timer in it, no examples of analog inputs.

    Thank you for replying and sorry for the late reply, I guess we live in different timezone,

    Vincent

  • And I forgot to mention, c6713dskinit.c is included in my source file, so I could track the results. My code was linked and built with the DSP/BIOS config, but I have a similar code linked and built in a different way, using some assembly files.

  • Vincent,

    Some of this is still confusing to me. So I will ask questions and offer any suggestions that I can, for what they are worth.

    Vincent Grenier-Horth said:
    my program falls in an infinite loop somewhere in the disassembly.

    Vincent Grenier-Horth said:
    My code was linked and built with the DSP/BIOS config, but I have a similar code linked and built in a different way, using some assembly files.

    Vincent Grenier-Horth said:
    the file c6713dskinit.c is in my project and it falls in this infinite loop:

    if (1) while(!MCBSP_xrdy(DSK6713_AIC23_DATAHANDLE));//if ready to transmit

    If you have two different projects, the while loop above would certainly be stuck in a C source loop and not in disassembly. Are you mixing me up by referring to two different implementations?

    Vincent Grenier-Horth said:
    When I call comm_intr, it follows in the function output_sample, where is the line above. I suppose the datahandle is never ready but I don't know why.

    I do not see comm_intr in your first post, but it sounds like an interrupt service routine. You would usually not call one of those, so I am curious why you are doing that.

    But the bottom line is that if you are stuck waiting for the McBSP Tx to be ready, then you have not initialized the McBSP correctly.

    Vincent Grenier-Horth said:
    the example I use to start the code is an old code from my superior with the GPIOs and the Timer in it, no examples of analog inputs.

    The DSK6713 board supplier, and some DSP authors, offer example programs for the DSK6713 that will demonstrate how to use the various peripherals. Your superior may have one of those that you can start from, or you can go to the board manufacturer's website to download some examples. Or search this forum and even the TI Wiki Pages for some examples.

    It sounds like you started from an example that works for GPIOs and Timers, and added your own code for the McBSP. And the McBSP part does not work. You (or your designee) can dig through every register in the McBSP and in the board components and learn the details of the functions being called to figure out what is wrong with the way you wrote it, or you can start from a working example. I recommend the working example, and I know there have been people discussing using the McBSP for audio input and output on this forum.

    Vincent Grenier-Horth said:
    I need the Line In and the MIC inputs to work

    I am not sure if both can work simultaneously. Perhaps you only need one or the other at any one time? The DSK's Tech Ref and schematics will help you with this.

    Vincent Grenier-Horth said:
    and the value range the input is in the program (example: If I put 3.3V in the input, what value will it have in the code).

    The DSK's Tech Ref and schematics and the datasheets for the ADC/DAC components will help you with this. I usually just start with a small voltage and test it to see what the result is, but the scientific way is better.

    Regards,
    RandyP

    Vincent Grenier-Horth said:
    sorry for the late reply, I guess we live in different timezone,

    In the 19th and early 20th centuries, it was said that "the sun never sets on the British Empire". That may be true today for the TI E2E Forums. We have users and TIers from everywhere that high-tech electronic engineering is being done. I am just in the boring Central US time zone, but you can tell I am not very good at following the clock.

  • Hi Randy,

    I may have be confusing in my last message, I'll try to clear up those interrogations.

    First, the program is trapped in the C code, I assumed it was in the disassembly because when I ran my code step-by-step, it directed me straight in the disassembly afetr passing through the line.

    Second, about the comm_intr, I played a lot with the codes and it isn't there because I must have erased it. it was with the other init functions. it is a interrupt service routine.  My supervisor told me it is important to use this function. My work is only to make a part of the code, the supervisor will take over after the problem is solved, because I'm just a trainee.

    Third, I tried to use other working codes, but I always got errors of undefined symbols and other problems that I find weird. I include the same headers in the code, I do not see if they have other files they put in their source files, but I can't seem to find one that works with my setup(I use a DSP/BIOS configuration to build my projects and also take an already existing project with assembly files).

    Fourth, I can just take the left and right line of the Line In analog input to make my project work. I learned I could do that if I can get it to work.

    Fifth, I'll give the DSK's Tech Ref a read about that.

    Thanks for the help and I hope this clears up things for you

    Vincent

  • Vincent,

    You need to start from a working example. If you can get one of the working examples to work on your board, then you will know that you can succeed in your project. You can then start moving code from the working example to your GPIO/Timer code or start moving code from your GPIO/Timer code to the working code. Then your problems are related to the compiler and linker instead of the details of the peripheral that are giving you big problems.

    You may also benefit from our online training materials. Please go to the TI Wiki Pages and search for "c6713 workshop" (no quotes). There is an archived workshop that includes student guide material and labs with solutions.

    Regards,
    RandyP

  • Hi Randy, its been a few days,

    I read the student guide and tried some solution programs and I found it to be useful, thank you for refering me to the documentation. I learned a few things  but something came up today. I made an example code work (I think) on the C6713 DSK. Its a very basic code, you must have already seen it before, here it is:

    //Loop_intr.c Loop program using interrupt, output=input
    //Comm routines and support files included in C6xdskinit.c
    #include "dsk6713.h"
    #include "dsk6713_aic23.h" //codec-dsk support file
    #define DSK6713_AIC23_INPUT_MIC 0x0015
    #define DSK6713_AIC23_INPUT_LINE 0x0011
    Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate
    Uint16 inputsource=DSK6713_AIC23_INPUT_LINE;   
    int sample_data=0;
    void c_int11()         //interrupt service routine
    {
       sample_data = input_left_sample(); //input data
       output_left_sample(sample_data);   //output data
    }

    void main()
    {
      comm_intr();                   //init DSK, codec, McBSP
     
      while(1);                       //infinite loop
    }

    Here is the situation, the code is used to take an input and direct it to the output. But, it doesn't process DC voltage. Only signals like a sine waves, square waves, triangular waves, etc... can get to the output. While using the watch window, sample_data only varies when the input varies. When there a DC voltage, sample_data stay around 0. Basically, it means that when you change the voltage, sample_data changes to high values(in a random-like pattern) and comes back near 0 when you stop changing the input voltage, even when you have 2-3V at the input. Also, putting a sine wave with a DC voltage offset in the output will result in the same wave without the offset and the end.

    This is my question : Is there a way to make the Line In input react to DC voltage, or it is set that its only signals like sine wave that gets processed?

    If there is, any documentations or tips on the subject would be greatly appreciated.

    I hope I wasn't too confusing.

    Regards,

    Vincent

  • Hello,

    The TLC320AIC23 codec is not intended to support DC (unspecified for this use); you can seek for its datasheet in TI's.

    However, if you really want to try with DC, you will have at least to short the DC-blocking capacitors from the DSK6713 board (470nF C333,C334,C337,C338 in rev.B) and deactivate the ADC high pass filter in the codec.

    Jakez

  • Hi,

    I think you are right, I read the datasheet and I could say the same thing. Well, with this my project is over, I finished the code I was supposed to do. Many thanks to you guys on the forum, it was really helpful.

    Regards,

    Vincent