Output PWM from MC68HC908QY4A

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Output PWM from MC68HC908QY4A

1,518 次查看
aurora
Contributor I

I am using a MC68HC908QY4A microcontroller. It has 2 timer channels. Is it possible to have one channel (PTA0) output a 1KHz square waveform and another channel (PTA1) output a 2KHz square waveform?

 

 

Thanks,

hliu@parkell.com

标签 (1)
0 项奖励
回复
4 回复数

1,058 次查看
aurora
Contributor I

Thanks all. Since both signals have a fixed duty cycle. I think I can use timer interrput to generate the second signal.

 

Thanks again.

0 项奖励
回复

1,058 次查看
bigmac
Specialist III

Hello,

 

I can see a couple of possibilities.

 

Use PWM mode with 50 percent duty for the 1kHz signal, and use output compare mode on the other channel to generate the 2kHz signal.  The PWM output will not require any interrupts, but the output compare channel interrupt will require servicing every 250 microseconds.  The modulo value will need to be set for an overflow period of 1 millisecond, and since it is not free-running, this will add complication to the calculation of the next output compare value.

 

Another alternative would be to use output compare mode for both channels.  This would increase the number of interrupts required, with one every 500 microseconds, and another every 250 microseconds.  However, since the TIM module could be free-running, this would simplify the calculation of the next output compare value for both signals.

 

Do you have a strict phase relationship requirement between the two waveforms?

 

Regards,

Mac

 

0 项奖励
回复

1,058 次查看
rocco
Senior Contributor II

Hi Aurora,

 

Another option, similar to Mac's, is to set the modulus to overflow every half-millisecond.

 

You could then use one channel as 50% PWM to give you 2 kHz, and toggle the other channel (or an I/O pin) on every overflow (or output-compare) to give you 1kHz.

 

I believe (from un-refreshed memory) that there is either a toggle on compare or toggle on overflow function in the QY's timer, but I don't have access to the datasheet right now. That would allow generating both square-waves with no interrupts to service.

0 项奖励
回复

1,058 次查看
bigmac
Specialist III

Hello,

 

I rather like Rocco's approach that would not require any interrupts.

 

Both toggle on overflow and toggle on compare are available for both channels, however it would appear than toggle on overflow would not work unless output compare mode is selected.  So, toggle on compare for the 1kHz channel should give the desired result.

 

Perhaps the following setup would work, assuming trimmed 3.2MHz bus clock frequency, and with channel 0 used for the 2kHz output, and channel 1 for the 1kHz output.

 

TSC = 0x30;    // Stop and clear TIM counter, prescale 1

TMOD = 1599;   // Overflow period 500us

TCH0 = 800;    // 50% duty for Ch 0

TSC0 = 0x1A;   // Unbuffered PWM with clear O/P on compare

TCH1 = 800;    // Toggle point for Ch 1 output

TSC1 = 0x14;   // Output compare with toggle on compare

TSC_TSTOP = 0; // Enable TIM counter

 

 

With this setting, the 1kHz signal should toggle on each negative edge of the 2kHz signal.

 

Regards,

Mac

 

0 项奖励
回复