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.

CCS/RM48L952: CCS/RM48L952

Part Number: RM48L952
Other Parts Discussed in Thread: HALCOGEN

Tool/software: Code Composer Studio

Hello,

I am a newbie. I intend to drive two DC motors with the RM48 Hercules Development Kit (HDK) and also display their RPM in CCS. Using Halcogen and Code Composer, I have been able to use the HET1 driver to generate PWM with different duty cycles to run both motors easily (thanks to examples from T.I). I am however, quite confused about converting the tachometer signal from each motor to RPM and displaying it. I have looked at similar examples online and tried to get mine to work, all to no avail.

This is what I have done so far:

Enabled HET1 driver

In the Pwm 0-7 tab, Enabled PWM for output pin 9 and 10. Pin 9 is at 60% duty cycle while pin 10 is at 20% duty cycle

In the pin 8 - 15 tab, enabled output direction for bit 9 and 10

TO CALCULATE RPM OF BOTH MOTORS FROM TACHOMETER SIGNAL

 Enabled GIO driver

Opened the GIO tab, port A. Chose GIOA[0] and GIOA[1]

Enabled Bit 0 and Bit 1 interrupt, Chose falling edge interrupt for Bit 0 and Bit 1 

Bit 0 and Bit 1 are input by default

Enabled Bit 0 and Bit 1 pullup 

CODE USED IN CCS

/* USER CODE BEGIN (0) */
#include "het.h"
#include "gio.h"
#include "important.h"
#include <stdio.h>
/* USER CODE END */

/* Include Files */

#include "sys_common.h"
#include "system.h"
#include "reg_gio.h"
/* USER CODE BEGIN (1) */
/* USER CODE END */

/** @fn void main(void)
* @brief Application main function
* @note This function is empty by default.
*
* This function is called after startup.
* The user can use this function to implement the application.
*/

/* USER CODE BEGIN (2) */
/* USER CODE END */

int main(void)
{
/* USER CODE BEGIN (3) */
hetInit();
gioInit();
while(1);
/* USER CODE END */


}

/* USER CODE BEGIN (4) */
unsigned int tachCount1 = 0; // Count revolutions of fan
unsigned int tachCount2 = 0; // Count revolutions of fan
unsigned int tachRPM1 = 0; // Stores RPM of fan
unsigned int tachRPM2 = 0; // Stores RPM of fan
unsigned int lastRPM1 = 0; // Stores RPM of last reading
unsigned int lastRPM2 = 0; // Stores RPM of last reading

{
refreshTach(); // Update Tachometer
_enable_interrupt_(TACH1); // enable tachometer interrupt
_enable_interrupt_(TACH2); // enable tachometer interrupt

}

void updateTach(void)
{

_disable_interrupt_(TACH1); // Disable tachometer interrupt
_disable_interrupt_(TACH2); // Disable tachometer interrupt
__nop(); // Wait 1 instruction cycle
// Convert pulse count to RPM
tachRPM1 = (tachCount1/PULSESPERREVOLUTION1)*60;
tachRPM2 = (tachCount2/PULSESPERREVOLUTION2)*60;
_enable_interrupt_(TACH1); // Re-enable tachometer interrupt
_enable_interrupt_(TACH2); // Re-enable tachometer interrupt
tachCount1 = 0; // Reset the pulse counter
tachCount2 = 0; // Reset the pulse counter
}
void refreshTach()
{
updateTach(); // Refresh tachometer readings
printf("RPM = %i\n",tachRPM1); // Print RPM of First motor
printf("RPM = %i\n",tachRPM2); // Print RPM of Second motor
}

/* USER CODE END */

THE HEADER FILE

important.h
*
* Created on: 7 Sep 2018
* Author: chuks
*/

#ifndef SOURCE_IMPORTANT_H_
#define SOURCE_IMPORTANT_H_


// PortA Pin Configuration
#define TACH1 Bit 0
#define TACH2 Bit 1

#define PULSESPERREVOLUTION1 2
#define PULSESPERREVOLUTION2 2

/************ FUNCTION PROTOTYPES ******************************************************/

void updateTach(void);
// Usage: Translate tachometer pulse counts into the actual RPM value
// Parameters: none
void refreshTach(void);
// Usage: Updates all variables corresponding to the tachometer
// Parameters: none

#endif /* SOURCE_IMPORTANT_H_ */

Please, any suggestions on why I am getting errors and it isn't working?

Kind Regards

 

  • Hello Chuck,

    My understanding is that you use GIO interrupt routine to capture the event on GIO pins. You need to enable the GIO interrupt in HALCoGen?

  •  Hello QJ Wang,

    Thanks for responding. I tried your suggestion, but still got the following error. Is there something I am missing?

    Kind Regards

  • Hello,

    I don't know how you enable and disable the GIO interrupt. There are 3 things to enable a peripheral interrupt:

    1. Enable the interrupt in module level, for example GIOA[0]: falling edge, and low priority (low level)

    2. Enable the GIO interrupt in VIM module: in step 1, low priority is used, so in VIM, the low level GIO interrupt should be enabled

    3. To enable IRQ (used for GIO interrupt defined in step 2)  interrupt in CPU level (CPSR register)

    _enable_IRQ(); 

    Another question, you can not call functions outside the function:

  • Hello,

    Thanks for responding. I have followed the steps you suggested to enable the GIO interrupts. However, I do not fully understand this comment

    ``Another question, you can not call functions outside the function:´´

    Please, can you elaborate more on what you meant? Thanks.

    Kind Regards
  • Hello,

    I mean that you make the following functions call outside the functions (main(), or updateTach()):

    refreshTach(); // Update Tachometer
    _enable_interrupt_(TACH1); // enable tachometer interrupt
    _enable_interrupt_(TACH2); // enable tachometer interrupt

    You can call those function in main() or in updateTach()
  • Hello,

    Thanks a lot, that reduced the number of errors. However, other errors still exist. I suspect that I didn't define or configure the gio correctly.  I want to use GIOA[0] and GIOA[1] as input to receive the tachometer signal from two DC motors. This is what I did in my header file:

    // PortA Pin Configuration

    #define TACH1     gioPORTA,0

    #define TACH2     gioPORTA,1

    I am getting the error ``too many arguments in function call´´

    Please, any suggestion will be appreciated.

    Kind Regards

  • Hello,

    Thanks a lot, that reduced the number of errors. However, other errors still exist. I suspect that I didn't define or configure the gio correctly.  I want to use GIOA[0] and GIOA[1] as input to receive the tachometer signal from two DC motors. This is what I did in my header file:

    // PortA Pin Configuration

    #define TACH1     gioPORTA,0

    #define TACH2     gioPORTA,1

    I am getting the error ``too many arguments in function call´´

    Please, any suggestion will be appreciated.

    Kind Regards

  • Hi Chuck,
    1. those two macro don't make sense to me. what value is assigned to TACH1 and TACH2?
    #define TACH1 gioPORTA,0
    #define TACH2 gioPORTA,1

    2. _enable_IRQ(..) is a function you defined?

    You can enable the GIO interrupt in HALCoGen. The interrupt routine is generated and located in gio.c. You can add your code in gioNotification().
  • Hello,
    Thanks for all the assistance so far, I have made significant progress. However, I have another question. Let me briefly explain my project before asking the question.
    I intend to drive two DC motor fans (Nidec TA450DC) with the RM48 Hercules Development Kit (HDK) using PWM and also display their RPM in Code Composer Studio. Using Halcogen and Code Composer Studio, I have followed all the right steps as previously instructed. HET pin 9 and 10 send PWM to both DC motor fans. GIOA[0] and GIOA[1] are used as inputs to receive the tachometer signal from both DC motor fans.

    My question has to do with the interrupt routine. I want these two functions:

    tachCount1++;
    tachCount2++;

    to be called when the interrupt is enabled. For instance, this is what I mean

    If GIOA[0] interrupt occurs or tachometer signal is detected,
    tachCount1++;

    and

    If GIOA[1] interrupt occurs or tachometer signal is detected,
    tachCount2++;


    1. What is the right way of representing this in the code?
    2. Am I supposed to include these two functions in the interrupt routine present in gio.c ?

    Looking forward to your reply.

    Kind Regards
    Chuks
  • Hi Chuck,

    When the GIO interrupt occurs, the code will jump to gio ISR: gioHighLevelInterrupt(), them jump to gioNotification(..) which is defined in notification.c. You can add your code in this function:

    #pragma WEAK(gioNotification)

    void gioNotification(gioPORT_t *port, uint32 bit)

    {

    /*  enter user code between the USER CODE BEGIN and USER CODE END. */

    /* USER CODE BEGIN (19) */

      if (bit == 1){

               tachCount1++;

      }else if (bit == 2)

               tachCount2++;

      }

    /* USER CODE END */

    }

  • Hello,

    Thanks for the assistance. I have made necessary changes. My code compiles and gets transferred to the The RM48 Hercules™ Development Kit successfully. However, when I connect both DC motor fans (Nidec TA450DC), this error pops up ``IcePick: Power Failure on target CPU´´

    sys_main.c  

    int main(void)
    {
    /* USER CODE BEGIN (3) */
               hetInit();
               gioInit();
               while(1);
    /* USER CODE END */
    }
    /* USER CODE BEGIN (4) */
    unsigned int tachCount1 = 0;                 // Count revolutions of fan
    unsigned int tachCount2 = 0;                 // Count revolutions of fan
    unsigned int tachRPM1 = 0;                   // Stores RPM of fan
    unsigned int tachRPM2 = 0;                   // Stores RPM of fan
    void updateTach(void)
    {
        refreshTach();                              // Update Tachometer
        _enable_IRQ();                      // enable tachometer interrupt
        gioSetBit(gioPORTA,0,0);            //creates falling edge interrupt on gioA, pin 0
        gioSetBit(gioPORTA,1,0);            //creates falling edge interrupt on gioA, pin 1
        __delay_cycles(1000);                // wait 1 second
        _disable_IRQ();                       // Disable tachometer interrupt
        tachCount1 = 0;                            // Reset the pulse counter ready for calculation
        tachCount2 = 0;                            // Reset the pulse counter ready for calculation
                                                  // Convert pulse count to RPM
        tachRPM1 = (tachCount1/PULSESPERREVOLUTION1)*60;
        tachRPM2 = (tachCount2/PULSESPERREVOLUTION2)*60;
    }
    void refreshTach()
    {
        updateTach();                            // Refresh tachometer readings
        printf("RPM1 = %i\n",tachRPM1);            // Print RPM of First motor
        printf("RPM2 = %i\n",tachRPM2);            // Print RPM of Second motor
    }
    notification.c

    {
    /* enter user code between the USER CODE BEGIN and USER CODE END. */
    /* USER CODE BEGIN (19) */
    gioSetBit(gioPORTA,bit,1);

    unsigned int tachCount1 = 0; // Count revolutions of fan
    unsigned int tachCount2 = 0; // Count revolutions of fan

    if (bit == 1)
    {
    tachCount1++;
    }

    else if (bit == 2)
    {
    tachCount2++;
    }

    /* USER CODE END */
    }

    amaechi.h           (a created header file)

    /*
    * amaechi.h
    *
    * Created on: 22 Oct 2018
    * Author: k2mon
    */

    #ifndef SOURCE_AMAECHI_H_
    #define SOURCE_AMAECHI_H_


    #define PULSESPERREVOLUTION1 2
    #define PULSESPERREVOLUTION2 2

    /************ FUNCTION PROTOTYPES ******************************************************/

    void updateTach(void);
    // Usage: Translate tachometer pulse counts into the actual RPM value
    // Parameters: none
    void refreshTach(void);
    // Usage: Updates all variables corresponding to the tachometer
    // Parameters: none


    #endif /* SOURCE_AMAECHI_H_ */

    Please, have I taken the wrong approach? Any assistance will be appreciated.

    Regards

  • Hello Chuck,

    How do you connect your motors to HDK? Do the motors use the power supply from HDK?
  • Hello,

    Both motors are 12V motors, so both motors use the power supply from the HDK. Is that the wrong approach?
  • If the motors draw two much current, it may cause the HDK power failure. Please use separate power supplies to the motors.