HI TI Experts, I am using following code to generate duty cycle for sending data through ez430-rf2500 product. My questions are as follows:- 1) I am using timer A for duty cycle in which I set TACCR0 = 30000 which is equivalent to 2 to 3 seconds. Correct me if I am wrong. So after every 2 to 3 seconds ISR runs code which is under __interrupt void Timer_A (void) which produces duty cycle of time period 2 to 3 seconds. I want to generate duty cycle equivalent to 10 to 15 seconds, how will it be possible using interrupts with Timers ? 2) Can you tell me if there are any other Timers where we can accommodate 10 to 15 seconds, and can you elaborate the frequency of clocks and how it works?? 3) If you need any further info, let me know? Code attached below:- #include "mrfi.h" #define MYADDR 0x09 #define MYX 0x03 #define MYY 0x07 #define NEXTHOP 0x01 __no_init volatile int tempOffset @ 0x10F4; // Temperature offset set at production mrfiPacket_t packetToSend; uint8_t get_temperature() { int degC; volatile long temp; ADC10CTL1 = INCH_10 + ADC10DIV_4; // Temp Sensor ADC10CLK/5 ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE + ADC10SR; for( degC = 240; degC > 0; degC-- ); // delay to allow reference to settle ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start __bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled degC = ADC10MEM; ADC10CTL0 &= ~ENC; // oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278 // the temperature is transmitted as an integer where 32.1 = 321 // hence 4230 instead of 423 temp = degC; degC = (((temp - 673) * 4230) / 1024); if( tempOffset != 0xFFFF ) { degC += tempOffset; } return (uint8_t)(degC&0xFF); } uint8_t get_battery() { int battery=0; ADC10CTL1 = INCH_11; // AVcc/2 ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V; for( battery = 240; battery > 0; battery-- ); // delay to allow reference to settle ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start __bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled battery = ADC10MEM; ADC10CTL0 &= ~ENC; ADC10CTL0 &= ~(REFON + ADC10ON); // turn off A/D to save power battery = (battery*25)/512; uint8_t batterybyte = battery&0xFF; return batterybyte; } int main(void) { BSP_Init(); //enable the button P1DIR &= ~0x04; P1REN |= 0x04; P1OUT |= 0x04; P1IE |= 0x04; //initialize the radio MRFI_Init(); MRFI_Sleep(); //__delay_cycles(80000000); //MRFI_WakeUp(); //MRFI_RxOn(); //initialize the timer BCSCTL3 |= LFXT1S_2; TACCTL0 = CCIE; TACCR0 = 30000; //initialize to ~3 second TACTL = MC_1+TASSEL_1; __bis_SR_register(GIE+LPM3_bits); } #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) { //initialize the radio MRFI_WakeUp(); //P1OUT ^= 0x01; // change timer randomly uint16_t fixed_part, random_part, random; fixed_part = 10000; random_part = MRFI_RandomByte(); random_part |= (MRFI_RandomByte()<<8); random_part = random_part%20000; random = fixed_part + random_part; TACTL = MC_0; TAR = 0; TACCR0 = random; TACTL = MC_1+TASSEL_1; //fill packet uint8_t temperature = get_temperature(); uint8_t battery = get_battery(); packetToSend.frame[0] = 13; //length packetToSend.frame[1] = 0x01; packetToSend.frame[2] = 0x00; packetToSend.frame[3] = 0x00; packetToSend.frame[4] = MYADDR; packetToSend.frame[5] = 0x00; packetToSend.frame[6] = 0x00; packetToSend.frame[7] = 0x00; packetToSend.frame[8] = NEXTHOP; packetToSend.frame[9] = MYX; packetToSend.frame[10] = MYY; packetToSend.frame[11] = 0x01; packetToSend.frame[12] = temperature; packetToSend.frame[13] = battery; //send packet MRFI_Transmit(&packetToSend, MRFI_TX_TYPE_FORCED); MRFI_Sleep(); //delay } #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from SR } void MRFI_RxCompleteISR() { //when I receive, I do nothing but toggling a LED P1OUT ^= 0x02; } #pragma vector=PORT1_VECTOR __interrupt void Port_1 (void) { //the button is not used, I reset the interrupt flag to avoid loops P1IFG &= ~0x04; }
↧