Generating a frequency

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Generating a frequency

Jump to solution
2,104 Views
Jairo
Contributor III

Hi i want to know if there's somebody who can help me with this, i need to generate a pulse signal in one pin (20 MHz). First of all i was able to do so but at very low frequencies compared with this, to achieve it i modified the timer example program to toggle the state of a pin. Another attempt i made was to copy the configuration made from Processor Expert and adapt it to MQX but with unsatisfactory results.

 

 /************************** 20MHz USING GPT**************************************/ //*********************************************************************************************    printf("Inicializando frecuencia...");    clrReg8Bits(reg_ptr->GPT.GPTIE, 0x02);  //Disable interrupts    setReg8(reg_ptr->GPT.GPTSCR1, 0x00);    //Stop Timer    setReg8Bits(reg_ptr->GPT.GPTIOS, 0x0A);     clrSetReg8Bits(reg_ptr->GPT.GPTCTL1, 0xC8, 0x04);        clrReg8Bits(reg_ptr->GPT.GPTCTL2, 0xCC);               setReg8(reg_ptr->GPT.GPTSCR2,0x08);    setReg16(reg_ptr->GPT.GPTC1, 0x01U);    //Store the given number in the compare registry    setReg16(reg_ptr->GPT.GPTC3, 0x01U);    //                    setReg8Bit(reg_ptr->GPT.GPTSCR1 , 0x80U); //Run the timer

Regarding all my attempts i got some doubts with MQX

1. In time what is a tick?

2. Is there another way to toggle on/off a pin, or i got to use the ioctl functions?

3. Which is the minimum intervalusing the lwtimer instead the timer?

 

Thanks in advance.

 

0 Kudos
1 Solution
617 Views
DavidS
NXP Employee
NXP Employee

Hi Jairo,

I wouldn't recommend bit banging method for high frequency clock generation.   I'd setup a DMA Timer to toggle its output pin when it reaches a particular value.  It then can reset the counter and repeat the process without any processor/CPU intervention.  You can also update the reference count value to change the frequency/clock output.

The "tick" in the RTOS is 5ms.

Regards,

David 

View solution in original post

0 Kudos
5 Replies
617 Views
ipa
Contributor III

Hi Jairo,

Did you looked at PWM module? it is capable of clock up to Internal_Bus_Clock/2.

I did not make any further checks on setting the rest of PWM ...

Another solution is to use CLKOUT and dividing externally by 4 if you run at 80MHz.

Regards,

IPA 

0 Kudos
618 Views
DavidS
NXP Employee
NXP Employee

Hi Jairo,

I wouldn't recommend bit banging method for high frequency clock generation.   I'd setup a DMA Timer to toggle its output pin when it reaches a particular value.  It then can reset the counter and repeat the process without any processor/CPU intervention.  You can also update the reference count value to change the frequency/clock output.

The "tick" in the RTOS is 5ms.

Regards,

David 

0 Kudos
617 Views
CarlFST60L
Senior Contributor II

We were considering making a 512Khz square wave output with another signal doing a single pulse every 16 counts (Generating PCM and Sync). Would this be possible without adding load to the processor?(Our processor is already pushing very high speed SPI and 3 UARTS among other hi load threads.

 

I know in the 8 bit processors it would be easy as they have a timer and modulo counter which you can easily setup and leave runing with zero processor loading as the module just toggles when the counter reachs module.

 

0 Kudos
617 Views
Jairo
Contributor III

Thnks to all for your replies, i've decided to generate the frequncy using the DMA Timer instead the PWM because the signal is 50% duty cycle, so i use the flip-flop function in the timer.

 

Best Regards.

0 Kudos
617 Views
CarlFST60L
Senior Contributor II
Can someone post an example of using the DMA timer to generate a PWM? Or is there an example somewhere?
0 Kudos