TI中文支持网
TI专业的中文技术问题搜集分享网站

2530输出方波

芯片:2530

协议栈:mesh1.0.0

问题:请问我用以下程序输出4khz的方波是否正确?用P1_2的IO翻转模拟方波。

void T3timerInit( void )
{P1SEL &= ~0x04;//将P1_2设置为通用IO输出P1DIR |= 0x04;P1_2 = 0;T3CTL |= 0x08;//开溢出中断T3IE = 1;//开T3定时器总中断T3CTL|=0X80;//16分频T3CTL &= ~0X03;//自动重装T3CTL |= 0X10;//启动EA = 1;//开总中断
}


/************************************

中断函数

************************************/

#pragma vector = T3_VECTOR  //定时器 T3

__interrupt void T3_ISR(void)
{TIMIF &= ~BV(0);//清中断标志位P1_2 = ~P1_2;// 电平翻转产生方波
}

Viki Shi:

用timer输出PWM即可,参考下这边的代码:sunmaysky.blogspot.com/…/how-to-output-pwm-from-cc2530.html

user6069081:

回复 Viki Shi:

请问我想用你所给的代码输出pwm到P1_3,那么我如何修改使得Timer3输出pwm到通道0即P1_3呢?

PERCFG &= (~(0x20)); // Select Timer 3 Alternative 1 locationP2SEL |=0x20;P2DIR |= 0xC0;// Give priority to Timer 1 channel2-3P1SEL |= BV(4);// Set P1_4 to peripheral, Timer 1,channel 2P1DIR |= BV(4);T3CTL &= ~0x10;// Stop timer 3 (if it was running)T3CTL |= 0x04;// Clear timer 3T3CTL &= ~0x08;// Disable Timer 3 overflow interruptsT3CTL |= 0x03;// Timer 3 mode = 3 - Up/DownT3CCTL1 &= ~0x40;// Disable channel 0 interruptsT3CCTL1 |= 0x04;// Ch0 mode = compareT3CCTL1 |= 0x10;// Ch0 output compare mode = toggle on compareT3CTL &= ~0xE0;// Clear Prescaler divider valueT3CTL |= 0xA0;//Set Prescaler divider value = Tick frequency /32T3CC0 = 128;//Set ticks = 128// Start timerT3CTL |= 0x10;

YiKai Chen:

回复 user6069081:

P1SEL |= BV(4);/P1DIR |= BV(4); 改為P1SEL |= BV(3);/P1DIR |= BV(3);

user6069081:

回复 YiKai Chen:

T3CCTL1 是否要修改为T3CCTL0?

YiKai Chen:

回复 user6069081:

YES

user6069081:

回复 YiKai Chen:

你好,我使用了以下的程序,但是得出的波形不是我想要的4khz的方波,请问哪里需要改进吗,非常感谢!

void pwmoutput( void )
{PERCFG &= (~(0x20));P2SEL |=0x20;P2DIR |= 0xC0;P1SEL |= BV(3);// Set P1_3 to peripheral, Timer 1,channel 2P1DIR |= BV(3);T3CTL &= ~0x10;// Stop timer 3 (if it was running)T3CTL |= 0x04;// Clear timer 3T3CTL &= ~0x08;// Disable Timer 3 overflow interruptsT3CTL |= 0x03;// Timer 3 mode = 3 - Up/DownT3CCTL0 &= ~0x40;// Disable channel 0 interruptsT3CCTL0 |= 0x04;// Ch0 mode = compareT3CCTL0 |= 0x10;// Ch0 output compare mode = toggle on compareT3CTL &= ~0xE0;// Clear Prescaler divider valueT3CTL |= 0xA0;//Set Prescaler divider value = Tick frequency /32T3CC0 = 128;//Set ticks = 128// Start timerT3CTL |= 0x10;
}

YiKai Chen:

回复 user6069081:

調整一下T3CC0看看

user6069081:

回复 YiKai Chen:

请问YK,osal_pwrmgr_device( PWRMGR_BATTERY )会对输出PWM有影响吗?

赞(0)
未经允许不得转载:TI中文支持网 » 2530输出方波
分享到: 更多 (0)