• AVR Freaks

Hot!mips_vec_dot16 function halts the PIC32MX795F512L

Author
syntax3
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/01/02 09:23:44
  • Location: 0
  • Status: offline
2020/01/16 22:58:15 (permalink)
0

mips_vec_dot16 function halts the PIC32MX795F512L

Hi, I want to use dot product function of PIC32MX795F512L with using dsplib_dsp.h.
 
Below you can see my code.
 
I shift the values so it becomes Q15 format.
Then send these values to function and finally send results trough UART.
However, when I program the uC it does not send the result.
After quick debug I realized the microcontroller halts at "result = mips_vec_dotp16(matrix,vector,3,0);".
waits at _reset:
          jal _startup
          nop
 
Is there example codes for these functions?
 
//-----------------------CONFIGURATION BITS------------------------//
// DEVCFG3
#pragma config USERID = 0xFFFF // Enter Hexadecimal value (Enter Hexadecimal value)
#pragma config FSRSSEL = PRIORITY_7 // SRS Select (SRS Priority 7)
#pragma config FMIIEN = OFF // Ethernet RMII/MII Enable (RMII Enabled)
#pragma config FETHIO = OFF // Ethernet I/O Pin Select (Alternate Ethernet I/O)
#pragma config FCANIO = OFF // CAN I/O Pin Select (Alternate CAN I/O)
#pragma config FUSBIDIO = OFF // USB USID Selection (Controlled by Port Function)
#pragma config FVBUSONIO = OFF // USB VBUS ON Selection (Controlled by Port Function)

// DEVCFG2
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider (2x Divider)
#pragma config FPLLMUL = MUL_20 // PLL Multiplier (20x Multiplier)
#pragma config UPLLIDIV = DIV_1 // USB PLL Input Divider (1x Divider)
#pragma config UPLLEN = OFF // USB PLL Disable (Disabled)
#pragma config FPLLODIV = DIV_1 // System PLL Output Clock Divider (PLL Divide by 1)

// DEVCFG1
#pragma config FNOSC = PRIPLL // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL))
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable (Disabled)
#pragma config IESO = OFF // Internal/External Switch Over (Disabled)
#pragma config POSCMOD = HS // Primary Oscillator Configuration (HS osc mode)
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_8 // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/8)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls))

// DEVCFG0
#pragma config DEBUG = OFF // Background Debugger Enable (Debugger is disabled)
#pragma config ICESEL = ICS_PGx2 // ICE/ICD Comm Channel Select (ICE EMUC2/EMUD2 pins shared with PGC2/PGD2)
#pragma config PWP = OFF // Program Flash Write Protect (Disable)
#pragma config BWP = OFF // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF // Code Protect (Protection Disabled)



#define SYS_FREQ 80000000L

#include <xc.h>
#include <sys/attribs.h>
#include <dsplib_dsp.h>
#include <dsplib_def.h>


//-------FUNCTION PROTOTYPE-------//
void Initialization();
unsigned char * int2str(unsigned int value);
void UART_Send_String(char *data);

int16 matrix[] = {1,2,3};
int16 vector[] = {1,2,3};
int16 result;

int i,j;


void main(void) {
    
    Initialization();
    
    for(i = 0; i < 3; i++)
    {

        matrix[i] = matrix[i]<<11;

    }
    
    for(i = 0; i < 3; i++)
    {
        vector[i] = vector[i]<<11;
    }
    
  
    result = mips_vec_dotp16(matrix,vector,3,0);

    result = result >> 11;
    
    
    while(1)
    {
        
        UART_Send_String(int2str(result));
        UART_Send_String("\n\r");
        
    }
    
    
    return;
}












void Initialization()
{

    //------------PORT SETUP---------------//
    TRISFbits.TRISF5 = 0; //Output TX
    TRISFbits.TRISF4 = 1; //Input RX
    
    //Only one pair of U2RX and U2TX exist in PIC32MX795F512L so no need to peripheral pin map.
    
    
    
    //------------USART SETUP--------------//
    U2MODEbits.ON = 0; //Disable UART
    
    U2MODEbits.BRGH = 0; //divide by 16
    U2BRG = 64; //9600 baudrate
    /*
     * Fpb
     * UxBRG = (---------------------) - 1
     * 16 * Baudrate
     */
    
    U2MODEbits.SIDL = 0; //Continue operation in sleep mode
    U2MODEbits.IREN = 0; //IrDA is disabled
    U2MODEbits.RTSMD = 0;//U2RTS pin is in Flow Control mode
    U2MODEbits.UEN = 0b00; //U2TX and U2RX are enabled
    U2MODEbits.WAKE = 1; //Wake-up enabled
    U2MODEbits.LPBACK = 0; //Loopback mode disabled
    U2MODEbits.RXINV = 0; //U2RX IDLE state is '1'
    U2MODEbits.PDSEL = 0b00; //8-bit data, no parity
    U2MODEbits.STSEL = 0; //1 stop bit
    U2STAbits.UTXINV = 0; //U2TX IDLE state is '1'
    U2STAbits.URXEN = 1; //UART2 Receiver is enabled
    U2STAbits.UTXEN = 1; //UART2 Transmitter is enabled
    
 
    U2MODEbits.ON = 1; //UART2 is enabled
    
}


unsigned char * int2str(unsigned int value)
{
    //Converting 4 digit (Since 10 bit = 1024 and 12 bit = 4096) integer value into string
    static unsigned char str[5]; //Number of digits + 1 since '\0' is needed at end of string
    unsigned int k = 0;
    const unsigned int digits[4] = {1000, 100, 10,1};//Add 10^n to set for desired digits
    while(k != 4)
    {
        str[k] = '0';

        while (value >= digits[k])
        {
            value -= digits[k];
            str[k]++;
        }

        k++;
    }
    str[4] = '\0';

    return str;

}


void UART_Send_String(char *data)
{

    while(*data != '\0') // Loop until end of the string
    {

        U2TXREG = *data; // Place data into TX Buffer
        data++; // Increment data address
        while(!(U2STAbits.TRMT)); //Wait until transmission is over
    }
    
    
}


post edited by syntax3 - 2020/01/16 23:17:17
#1

3 Replies Related Threads

    syntax3
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2020/01/02 09:23:44
    • Location: 0
    • Status: offline
    Re: mips_vec_dot16 function halts the PIC32MX795F512L 2020/01/17 01:48:10 (permalink)
    0
    I found that in dsplib_dsp.h the functions has no source code. It says "No suitable source file has been found" if I try to navigate to source file. Do anyone know how to get the source files?
    #2
    LostInSpace
    Super Member
    • Total Posts : 310
    • Reward points : 0
    • Joined: 2016/03/11 22:47:59
    • Location: 0
    • Status: offline
    Re: mips_vec_dot16 function halts the PIC32MX795F512L 2020/01/19 19:33:17 (permalink)
    0
    These functions are supplied by MIPS in highly optimized assembler and are precompiled (There should be a .o file somewhere - because it appears it linked to it properly).
     
    In Harmony V2.05 - look in the "help_harmony.chm", there is a similar function called: DSP_VectorDotp16 Function
    There is also an example shown. (Path to help files: "C:\microchip\harmony\v2_05_01\doc..."
     
    This is probably the version you want to use.
     
    Hope this helps.
    #3
    LostInSpace
    Super Member
    • Total Posts : 310
    • Reward points : 0
    • Joined: 2016/03/11 22:47:59
    • Location: 0
    • Status: offline
    Re: mips_vec_dot16 function halts the PIC32MX795F512L 2020/01/19 19:36:29 (permalink)
    0
    Ha! Then I read the remarks in the help file myself and it says,
     
    "Remarks: This must be assembled with .set microMIPS."
     
    That may be the real issue - but I personally would use the 'documented' functions.
     
    #4
    Jump to:
    © 2020 APG vNext Commercial Version 4.5