This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

multiplier IC

i have analoge volts on the pins.

How can you achieve z=x*y with 8051? 2V*(-3V)=-6V for example

Parents
  • 
    /*
    **======================================================================
    **      main
    **======================================================================
    **
    **  This answers the question "How can you achieve z=x*y with 8051?"
    **  found in the origional contract.
    **
    **  Contract: http://www.keil.com/forum/docs/thread12890.asp
    **
    **  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    **
    **  This shall "infinately" read in two analog voltage values, then
    **  multiply them together, and with that result control a heat-lamp
    **  to keep the french-fries from becoming solid blocks of Crisco.
    **
    **----------------------------------------------------------------------
    **
    **  Parameters Passed:      <none>
    **  Parameters Returned:    <none>
    **  Notes:
    **          This requires a time-base isr, and other 'implied' functions
    **
    **----------------------------------------------------------------------
    */
    void main( void )
    {
        /*------------------------------------------------------------------.
        ;
        '------------------------------------------------------------------*/
        u16     raw_x;      // get the un-scaled ADC values
        u16     raw_y;
    
        s16     x;          // for the scaled values
        s16     y;
    
        s32     result_z;   // our result ... (2^12)x(2^12) = 16,777,216 < 2^32
    
        /*------------------------------------------------------------------.
        ;  Power-up                                                         ;
        '------------------------------------------------------------------*/
        Disable_Interrupts( );  // just in case
        Init_Port_IO( );        // 'safest' port levels
        Init_Debug( );          // initialize the error/debug stuff
    
        /*------------------------------------------------------------------.
        ;  Initialize the time-base                                         ;
        '------------------------------------------------------------------*/
        Init_Time_Base( );      // configure it
        Enable_Time_Base( );    // enable it
    
        /*------------------------------------------------------------------.
        ;  Clear any 'pending' interrupts and then enable the master.       ;
        '------------------------------------------------------------------*/
        Enable_All_Interrupts( );
    
        /*------------------------------------------------------------------.
        ;  Simple forever loop which reads, multiplies, and outputs         ;
        '------------------------------------------------------------------*/
        while( FOREVER )
        {
            /*--------------------------------------------------------------.
            ;  Read in the ADC values                                       ;
            '--------------------------------------------------------------*/
            raw_x = Get_ADC_Value( CHANNEL_0 );
            raw_y = Get_ADC_Value( CHANNEL_1 );
    
            /*--------------------------------------------------------------.
            ;  Scale the values per the system requirements                 ;
            '--------------------------------------------------------------*/
            x = Scale_ADC( raw_x );
            y = Scale_ADC( raw_y );
    
            /*--------------------------------------------------------------.
            ;  Multiply the two readings, and feed that into our output...  ;
            '--------------------------------------------------------------*/
            result_z = x * y;                   // the complex math
    
            /*--------------------------------------------------------------.
            ; The output is a signed 32-bit PWM channel operating with a    ;
            ; base frequency of 50kHz, and this is used to control the      ;
            ; french-fry heat lamps, and simultaneously killing the flies   ;
            ; buzzing about with the intense Infra-Red lamps.  Those little ;
            ; black dots in your fry container are not 'zesty' spices.      ;
            '--------------------------------------------------------------*/
            Update_PWM_Out( CHANNEL_A, result_z );
        }
    
    }
    
    
    
    /*===========================================================================
    *       END OF MODULE ( Keil_Forum_Example.C )
    ===========================================================================*/
    
    

    I did not include all of the functions, but you can figure it out from there.

    Also I have not compiled this code because it will only show a bunch of errors and complain how it should not work. I hate that. So I never actually compile or link programs. This way I also avoid that debugging thing too. It takes too much time anyway.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

Reply
  • 
    /*
    **======================================================================
    **      main
    **======================================================================
    **
    **  This answers the question "How can you achieve z=x*y with 8051?"
    **  found in the origional contract.
    **
    **  Contract: http://www.keil.com/forum/docs/thread12890.asp
    **
    **  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    **
    **  This shall "infinately" read in two analog voltage values, then
    **  multiply them together, and with that result control a heat-lamp
    **  to keep the french-fries from becoming solid blocks of Crisco.
    **
    **----------------------------------------------------------------------
    **
    **  Parameters Passed:      <none>
    **  Parameters Returned:    <none>
    **  Notes:
    **          This requires a time-base isr, and other 'implied' functions
    **
    **----------------------------------------------------------------------
    */
    void main( void )
    {
        /*------------------------------------------------------------------.
        ;
        '------------------------------------------------------------------*/
        u16     raw_x;      // get the un-scaled ADC values
        u16     raw_y;
    
        s16     x;          // for the scaled values
        s16     y;
    
        s32     result_z;   // our result ... (2^12)x(2^12) = 16,777,216 < 2^32
    
        /*------------------------------------------------------------------.
        ;  Power-up                                                         ;
        '------------------------------------------------------------------*/
        Disable_Interrupts( );  // just in case
        Init_Port_IO( );        // 'safest' port levels
        Init_Debug( );          // initialize the error/debug stuff
    
        /*------------------------------------------------------------------.
        ;  Initialize the time-base                                         ;
        '------------------------------------------------------------------*/
        Init_Time_Base( );      // configure it
        Enable_Time_Base( );    // enable it
    
        /*------------------------------------------------------------------.
        ;  Clear any 'pending' interrupts and then enable the master.       ;
        '------------------------------------------------------------------*/
        Enable_All_Interrupts( );
    
        /*------------------------------------------------------------------.
        ;  Simple forever loop which reads, multiplies, and outputs         ;
        '------------------------------------------------------------------*/
        while( FOREVER )
        {
            /*--------------------------------------------------------------.
            ;  Read in the ADC values                                       ;
            '--------------------------------------------------------------*/
            raw_x = Get_ADC_Value( CHANNEL_0 );
            raw_y = Get_ADC_Value( CHANNEL_1 );
    
            /*--------------------------------------------------------------.
            ;  Scale the values per the system requirements                 ;
            '--------------------------------------------------------------*/
            x = Scale_ADC( raw_x );
            y = Scale_ADC( raw_y );
    
            /*--------------------------------------------------------------.
            ;  Multiply the two readings, and feed that into our output...  ;
            '--------------------------------------------------------------*/
            result_z = x * y;                   // the complex math
    
            /*--------------------------------------------------------------.
            ; The output is a signed 32-bit PWM channel operating with a    ;
            ; base frequency of 50kHz, and this is used to control the      ;
            ; french-fry heat lamps, and simultaneously killing the flies   ;
            ; buzzing about with the intense Infra-Red lamps.  Those little ;
            ; black dots in your fry container are not 'zesty' spices.      ;
            '--------------------------------------------------------------*/
            Update_PWM_Out( CHANNEL_A, result_z );
        }
    
    }
    
    
    
    /*===========================================================================
    *       END OF MODULE ( Keil_Forum_Example.C )
    ===========================================================================*/
    
    

    I did not include all of the functions, but you can figure it out from there.

    Also I have not compiled this code because it will only show a bunch of errors and complain how it should not work. I hate that. So I never actually compile or link programs. This way I also avoid that debugging thing too. It takes too much time anyway.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

Children
No data