⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m_engctl.c

📁 TMS320F2812的C++ examples 各个模块的程序
💻 C
字号:
/********************************************************************* * FILENAME: $RCSfile: m_engctl.c,v $ * VERSION : $Revision: 1.1 $ * DATE    : $Date: 2000/12/21 20:36:39 $ * Copyright (c) 1997-2000 Texas Instruments Incorporated * * Engine Simulation Example: *____________________________________________________________________ * - Uses ONE output channel and ONE input channel *         * * - This is the module to be run on the TARGET. * - This program is meant to be used with the RTDX display *   engineprog.exe ********************************************************************/#include <stdio.h>                      /* fprintf(), puts()        */#include <stdlib.h>                     /* abort(), rand()          */#include <time.h>                       /* time()                   */#include <rtdx.h>                       /* RTDX                     */#include "target.h"                     /* TARGET_INITIALIZE()      *//* =================================================================== * Typedefs & Global Data structures * ================================================================ */#define TEST_ITERATIONS 100#define MIN_RPM         0       /* Min/Max Engine RPM's             */#define MAX_RPM         9000#define MIN_TC          0       /* Min/Max Turbo Charger RPM        */#define MAX_TC          25000#define MIN_MP          -150    /* Min/Max Manifold Pressure        */#define MAX_MP          +150#define MIN_WG          10      /* Min/Max Waste Gate %             */#define MAX_WG          90#define MIN_TH          10      /* Min/Max Throttle %               */#define MAX_TH          90const int timer         = 1;    /* (sec) timer tick value           */int Get_New_Desired_RPM( void );int Get_New_Desired_RPM2( int i );int Get_New_RPM( int MP );int Get_New_WG( int RPM_Diff, int MP );int Get_New_TC( int RPM, int WG );int Get_New_MP( int RPM, int TC );/* * Declare and initialize an output channel called "ochan" and an * input channel called "ichan". */RTDX_CreateOutputChannel(ochan);#ifdef ACCEPTS_DISPLAY_INPUTRTDX_CreateInputChannel(ichan);#endif/* ================================================================ */void main( void ){        int i;                  /* test iterations                  */        #ifdef ACCEPTS_DISPLAY_INPUT        int dummy;        #endif        struct {                int DRPM;       /* Desired RPM                      */                int RPM;        /* Engine's RPMs                    */                int MP;         /* (.1 psi) Manifold Pressure       */                int TC;         /* (rpm) Turbo Charger              */                int WG;         /* % Waste Gate                     */                } chan_data;        /* Initialize "chan_data" structure                         */        chan_data.RPM = 2000;        chan_data.MP = 0;        /* Target initialization for RTDX                           */        TARGET_INITIALIZE();        /* Enable channels                                          */        RTDX_enableOutput (&ochan);        #ifdef ACCEPTS_DISPLAY_INPUT        RTDX_enableInput (&ichan);        #endif	for( i = 0; i<TEST_ITERATIONS; i++ ) {                #ifdef ACCEPTS_DISPLAY_INPUT                chan_data.DRPM  = Get_New_Desired_RPM2(i);                #else                chan_data.DRPM  = Get_New_Desired_RPM();                #endif                chan_data.WG    = Get_New_WG( chan_data.DRPM -                                              chan_data.RPM,                                              chan_data.MP );                chan_data.TC    = Get_New_TC( chan_data.RPM,                                              chan_data.WG );                chan_data.MP    = Get_New_MP( chan_data.RPM,                                              chan_data.TC);                chan_data.RPM   = Get_New_RPM( chan_data.MP );                /* Send the data to the host                        */                if (!RTDX_write( &ochan,                                 &chan_data,                                 sizeof(chan_data)) ) {                        fprintf(stderr,                                "\nError: RTDX_write() failed!\n");                        abort();                }                /* Wait for data transfer                           */                while ( RTDX_writing != NULL ) {                        #if RTDX_POLLING_IMPLEMENTATION                                /* Call Poll to do data transfer    */                                RTDX_Poll();                        #endif                }	}        #ifdef ACCEPTS_DISPLAY_INPUT        /* One last read to synch with display */        RTDX_read( &ichan, &dummy, sizeof(dummy) );        #endif        /* Disable channels                                         */        RTDX_disableOutput( &ochan );        #ifdef ACCEPTS_DISPLAY_INPUT        RTDX_disableInput( &ichan );        #endif        puts("\nProgram Completed!");}/* ================================================================ */int Get_New_Desired_RPM( void ){        static int seeded;      /* 1 if random nbr generator seeded */        static time_t t;        static long int i       = 80;   /* time keeper              */        static int Desired_RPM  = 2000;        int New_RPM             = Desired_RPM;        /* Generate seed for random nbr generator */        if ( !seeded ) {                srand( (unsigned) time(&t) );                seeded = 1;        }        if ( i++ > 100 ) {                do {                        /* reset i                                 */                        i = 0;                        Desired_RPM = (rand()%8) * 1000 + 1000;                } while ( New_RPM == Desired_RPM );        }        return(Desired_RPM);}/* ================================================================ */int Get_New_Desired_RPM2( int i ){        static int Desired_RPM = 2000;  /* the current Desired RPM  */        int rpm_change = 0;             /* input from user          */        /*         * After every 10 Write operations, issue 1 Read operation,         * to keep in synch with the display.         */        /* If 10th iteration...                                     */        if ( (i != 0) && (i % 10 == 0) ) {                                #ifdef ACCEPTS_DISPLAY_INPUT                /* Get data from display                            */                if ( (RTDX_read( &ichan,                                 &rpm_change,                                 sizeof(rpm_change) ) ) !=                    sizeof(rpm_change) ) {                        fprintf(stderr,                                "\nError: RTDX_read() failed\n");                        abort();                }                #endif                /* Compute new Desired RPM                          */                Desired_RPM += rpm_change;                /* If less than allowed...                          */                if ( Desired_RPM < MIN_RPM )                        /* Clip value to minimum                    */                        Desired_RPM = MIN_RPM;                /* If more than allowed...                          */                if ( Desired_RPM > MAX_RPM )                        /* Clip value to maximum                    */                        Desired_RPM = MAX_RPM;        }        return(Desired_RPM);}/* ================================================================ */int Get_New_RPM( int MP ){         static int RPM = 2000;        float m_MP     = 1000.0/150.0;        int New_RPM;        New_RPM = m_MP*(float)(MP);        RPM += New_RPM;        if ( RPM > MAX_RPM )                RPM = MAX_RPM;        if ( RPM < MIN_RPM )                RPM = MIN_RPM;        return( RPM );}/* ================================================================ */int Get_New_WG( int Diff_RPM, int MP ){        int WG;        float m_Diff_RPM = 10.0/300.0;        WG = m_Diff_RPM*(float)Diff_RPM + 50;        if ( MP > 150 )         /* keep manifold from exploding	    */                WG = 100;	        if ( WG > MAX_WG )                WG = MAX_WG;        if ( WG < MIN_WG )                WG = MIN_WG;        return (WG);}/* ================================================================ */int Get_New_TC( int RPM, int WG ){        int TC;        float m_RPM = 25000.0/9000.0;        TC = (m_RPM*(float)(RPM)) * ((float)WG/100.0);        if ( TC > MAX_TC )                TC = MAX_TC;        if ( TC < MIN_TC )                TC = MIN_TC;        return( TC );}/* ================================================================ */int Get_New_MP( int RPM, int TC ){        int MP;         /* (psi) Manifold Pressure                  */        float m_RPM     = -150.0/4500.0;        float m_TC      =  66.0/2777.0;        MP  = m_RPM*(float)RPM;        MP += m_TC*(float)TC;        if ( MP > MAX_MP )                MP = MAX_MP;        if ( MP < MIN_MP )                MP = MIN_MP;        return( MP );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -