// MSP430.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #include #include // ......................................................... //MSP430 source code // ......................................................... // scope is this file for globals static int64_t plq0; static int64_t plq1; static int64_t plq2; static int64_t plq_power; extern int32_t pl_data; extern PL_PARAMS* pl_slot; PL_PARAMS* pl_slot; inline void private_line_clear( ) { plq1= 0; plq2= 0; plq_power= 0; } //return 1000 as max clean power of slot inline uint16_t private_line_power( ) { return (uint16_t)( plq_power * 1200 / pl_slot->power_factor ); } // ......................................................... //interrupts don't have parameters so all is global void pseudo_interrupt( ) { plq0= pl_slot->coeff * plq1 / SCALE_INT - plq2 + pl_data; plq2= plq1; plq1= plq0; if( abs( plq0 ) > plq_power ) plq_power= abs( plq0 ); } // ......................................................... //test code // ......................................................... int32_t pl_coeff; int32_t pl_data; // ......................................................... //#define PRINT int _tmain(int argc, _TCHAR* argv[]) { pl_slot= &PL_XZ; //Generate uses an int32_t but we will use the lower 16 //as if the data is from the ADC12 int32_t* a= new int32_t[ TEST_DATASET_SIZE ]; for( int i= 0; i < PLS_SIZE; ++i ) { Generate( (double)pl_slot->freq / 10, pl_slot->n_size, a ); #ifdef PRINT std::ofstream file( "../simple_fft/testout.txt", std::ios::ate ); #endif //the test private_line_clear( ); //enable 1 millisecond interrupts for( size_t j= 0; j < pl_slot->n_size; ++j ) { // and read the ADC12 and process. pl_data= a[ j ]; pseudo_interrupt( ); #ifdef PRINT file << ( plq0 ) << std::endl; #endif } //count hit, disable the interrupts and get power uint16_t power= private_line_power( ); // uint32_t power= plq_power; std::cout << "freq: " << (double)pl_slot->freq / 10 << "\tpower: " << power << std::endl; pl_slot+= sizeof( PL_PARAMS ) / 8; //TODO Why is sizeof 8 times what it really is??????!!!!! #ifdef PRINT file.close( ); break; #endif } getchar( ); return 0; }