Hello All,
I am using FPB-RA4E1 board with FSP v4.2. I know that I can enable GPT output pins but I am trying to get a PWM output from a different pin (P015). I used the GPT module and set up a periodic timer with 1MHZ. During the callback function I toggle the output pin. Though I should get a 500kHz output the maximum value I saw is 360kHz. Is there a maximum limit to frequency of I/O pins? What is the reason for not getting the frequency I want?
Thanks
İrem
What is the clock speed of the processor, and how many instructions are there in the interrupt routine? Add in the time to stack the registers, and if you have more than 40 instructions in the routine, you are in trouble!
You need to write the interrupt routines in assembler.
Hello,
Thanks for reaching out to Renesas Engineering Community.
I think that what you are trying to do cannot succeed for high frequencies.
With a timer frequency of 1 MHz and clock source = 200MHz, I achieved a pin output frequency of 446 KHz (still away from 500 KHz) with very simple software.
If I reduce the timer frequency to 100KHz the result can be achieved:
So you need to lower the frequency to output the timer in this way because after a point the software routine is not fast enough.
Hope it helps.
Best regards
AZ
It may look like simple software, but just look on the disassembly panel and see how many instructions it takes!
Why didn't you put it in the interrupt service routine? That would save quite a bit of time.
You should be able to write it in half a dozen assembler instruction which would execute in about 100ns.
set up "level" to be 0x404
Interupt service routine:
LDR R1,=level
LDR R2,=R_PFS_BASE
LDR R0,[R1]
EORS R0,R0,#1
STR R0,[R2,<portaddress>
BX LR
Executes in 55ns plus the time it takes to stack and unstack R0-R3 and R12
Let me share some more information on the interrupt handling process of FSP.
First the 'gpt_counter_overflow_isr' is called. This function calls then 'r_gpt_call_callback' and then the user defined callback function will be called. In the user defined callback function the pin write function is called to write the pin.
So all these commands must be executed from the moment that the interrupt occurs until the pin is written.
A way to improve this is to declare an overflow ISR and not use the FSP callback method. The code for interrupt handling will be significantly reduced.
Then we can improve the pin toggling process by not calling 'R_IOPORT_PinWrite' but using register access to write the pin.
R_PORT0->PCNTR3_b.POSR = 0x8000; // Set P015 high R_PORT0->PCNTR3_b.PORR = 0x8000; // Set P015 low
I hope it helps.
Regards