⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
6 posts / 0 new
Last post
posljh
Offline
Last seen:3 years 4 months ago
加入:2016-12-23 05:47
4MHz clock using GPIO

I want to make 4MHz clock using GPIO..;; Can I get it using any timer??

Device:
MT_dialog
Offline
Last seen:2 months 3 weeks ago
工作人员
加入:2015-06-08 11:34
Hi posljh,

Hi posljh,

Yes, you can use the timers and the PWM functionallity in order to generate a 4MHz pulse. You can have a look at the peripheral_examples folder in the timer0 and timer2 examples.

In order to achieve a 4MHz pulse you can set the timer divider to 2 in order to generate a clock of 8MHz (set_tmr_div(CLK_PER_REG_TMR_DIV_2);) and set the high and low counters of the timer to 0 (timer0_set_pwm_high_counter(PWM_HIGH);, timer0_set_pwm_low_counter(PWM_LOW);), those settings will generate a 4MHz pulse.

Thanks MT_dialog

posljh
Offline
Last seen:3 years 4 months ago
加入:2016-12-23 05:47
Thank you so much:))

Thank you so much:))

I can make a 4MHz pulse now. By the way I want to use I2C also. But i can't use I2C when i generate 4MHz pulse..;; Plz give me some adivse..;;

posljh
Offline
Last seen:3 years 4 months ago
加入:2016-12-23 05:47
I attached a file that

I attached a file that include some waveform according to different timer0 setting.
I could use i2c when I generate 160kHz pulse. But the more I raised frequency, the more i get unstable pulse and i can't use i2c..;;
Plz check a file. The ripple voltage of high frequency pulse is too high..;;

MT_dialog
Offline
Last seen:2 months 3 weeks ago
工作人员
加入:2015-06-08 11:34
Hi posljh,

Hi posljh,

I dont see any issues between using the I2C and the timer at the same time, using the peripheral examples from the SDK and attaching a timer 0 functionallity with 4MHz pulse on the p0_0. Some comments on the code that you have attached, i see that you are also enabling the TIMER_ON, that means that the depending on the frequency that the timer is running you will also get the corresponding interrupt, i suppose that the reason that you dont see any I2C activity is because the interrupts from the timer are so fast that they dont allow the processor the reach the I2C interaction, so simply there is no I2C interaction because simply the code doesn't reach that point. You dont have to use the interrupts for the timer in order to have the PWM functionallity, instead of using the timer0_set(TIMER_ON, PWM_HIGH, PWM_LOW); you can use the timer0_set_pwm_high_counter(PWM_HIGH); and timer0_set_pwm_low_counter(PWM_LOW); and dont enable the IRQ of the timer. The reason that you could see I2C interaction when lowering the frequency is because the interrupt was occuring less frequently, so there was time for the ARM to execute the I2C interaction code. Regarding the nasty ringing that you observed, i am not able to see that on my osciloscope when increasing the frequency, so perhaps this is somekind of an electrical issue, caused by a load on the PWM pin, or perhaps this is also caused by the probes of the oscilloscope that you are using.

Thanks MT_dialog

posljh
Offline
Last seen:3 years 4 months ago
加入:2016-12-23 05:47
Thank you so much!!:)

Thank you so much!!:)

Now I'm able to use I2C with PWM. The problem was enable function of IRQ. The code worked correctly when i get rid of that function.