Jump to content


  • Content Count

  • Joined

  • Last visited

  1. Thank you for your help currently working on a new code hope it works
  2. Hello,thank you for the reply #define DR P1OUT = P1OUT | BIT4 // define RS high #define CWR P1OUT = P1OUT & (~BIT4) // define RS low #define READ P1OUT = P1OUT | BIT5 // define Read signal R/W = 1 for reading #define WRITE P1OUT = P1OUT & (~BIT5) // define Write signal R/W = 0 for writing #define ENABLE_HIGH P1OUT = P1OUT | BIT6 // define Enable high signal #define ENABLE_LOW P1OUT = P1OUT & (~BIT6) // define Enable Low signal unsigned int i; unsigned int j; volatile unsigned int CounterValue = 0; volatile unsigned int StoredCount = 0; unsigned int Result = 0; const int NumberSamples = 4; unsigned int Frequency = 0; unsigned int SampleTuneTime = 10000; so these are the values i have declared,about the code my idea was that on the rising edge of the signal i turn on the counter i store it in a variable and on falling edge i stop it and read it.I load a value into TA0CCR0 so that TA0 can count up to it,after that TA0CCR0 intrerrupt triggers and increments CounterValue.StoredCount is the number of positive edges seen in the desired frequency.Im havent set a fixed frequency yet because i was still experimenting float SampTime = 0.03; // 30mS sample time Frequency = Result / SampTime; // Divide the averaged sampled result by the sample time to gain the frequency i calculate the frequency like this i convert the value stored in Frequency to a string with the itoa function and send it to the LCD like this And about the overflow thing,sinse i think the SMCLK is only 1 MHz and i need 10 from what i understanded the overflow lets you go higher but i need to read more about it. void send_string(char *s) { while(*s) { send_data(*s); s++; } } Of course what i did could be completely wrong sinse its my very first msp430 project and things are still confusing for me/
  3. Hello guys,i have a question for my project im using the msp430g2231 microcontroller and i want to measure frequencies up to 10Mhz.Im new to microcontrollers(not programming),and im not sure how to make the overflow work void main(void) { WDTCTL = WDTPW + WDTHOLD; // stop watchdog timer BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation delay(100); // delay 100mS until next screen refresh /*** Timer_A Set-Up ***/ TA0CCR0 = SampleTuneTime; TA0CCTL0 |= CCIE; // Interrupt enable TA0CTL |= TASSEL_1 + ID_3; // SMCLK TA0CCTL1 |= CCIE + CCIS_0 + CM_1 + CAP; // Interrupt enable, capture select CCIxA, Positive edge, capture mode TA0CTL |= TASSEL_1; //SMCLK _BIS_SR(GIE); // Enter LPM0 with interrupts enabled while(1) { TA0CTL |= MC0; // Start timer up mode.Timer counts up to TACCR0 TA0CTL |= MC1; // Start timer //while(CounterValue != 400); // Wait while CounterValue is not equal to 400 TA0CTL &= ~MC0; // Stop timer mode TA0CTL &= ~MC1; // Stop timer Result >>= 2; // Divide Result by 4 calc_freq(); //convert long into frequency char buffer[8]= { 0, }; unsigned long toLCD = Frequency; // int Base = 10; itoa(toLCD,buffer); //convert decimal lcd_init(); send_string("FREQUENCY IS"); send_command(0xC0); send_string(buffer); send_command(0xC8); send_string("HZ"); Result = 0; // Zero Result CounterValue = 0; // Zero CounterValue StoredCount = 0; // Zero StoredCount TA0R = 0; // Zero Timer_A0 register } } #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer0_A0(void) { TA0CTL &= ~MC0; // Stop timer TA0CTL &= ~MC1; // Stop timer CounterValue++; // Increment CounterValue if (CounterValue >= (NumberSamples +1)) // Reset values if NumberSamples +1 is reached { CounterValue = 0; // Zero CountValue StoredCount = 0; // Zero StoredCount } Result += StoredCount; // Store accumulated count in Result StoredCount = 0; // Zero StoredCount TA0CTL |= MC1; // Start timer TA0CTL |= MC0; // Start timer StoredCount++; // Increment StoredCount } this is the main code of the program im using custom made function for the itoa and the communication with the LCD.I have two questions 1.) Can i make the frequency meter up to 10Mhz cuz the g2231 has one timer and 1Mhz calibration available. 2.)Can i somehow check if the code is working cuz i dont have any way to send frequency right now,like counting the internal frequency or something like that. Thank you for your time.
  • Create New...