Continuous Output Pulse at Compare 1 module

An area to discuss 32-bit PIC specific problems and examples

Moderator: Benj

Speed64
Posts: 29
Joined: Sat Jul 16, 2016 12:08 pm
Contact:

Continuous Output Pulse at Compare 1 module

Postby Speed64 » Sat Aug 11, 2018 10:45 am

translated with Google
Hello
I do not know about C code.
I want to generate very short pulses in the MHz range.
If possible around 50MHz
I want to run the following microchip example in FC7.
Example from DS61111E-Page 16
I have a PIC32MZ2048EFM100
Clock runs at 200MHz.
The impulses should appear on port C2
Up to this line no error message comes.
Example code for Output Compare 1 ISR:

what is missing here or is wrong :?

Thanks in advance


################################################################################
// The following code example will set the Output Compare 1 module
// for interrupts on the continuous pulse event and select Timer2
// as the clock source for the compare time-base.T2CON = 0x0018;
// Configure Timer2 for 32-bit operation
// with a prescaler of 2. The Timer2/Timer3
// pair is accessed via registers associated
// with the Timer2 register

OC1CON = 0x0000; // disable OC1 module
OC1CON = 0x0005; // Configure OC1 module for Pulse output
OC1R = 0x3000; // Initialize Compare Register 1
OC1RS = 0x3003; // Initialize Secondary Compare Register 1
PR2 = 0x00500000; // Set period (PR2 is now 32-bits wide)

// configure int

IFS0CLR = 0x00000040; // Clear the OC1 interrupt flag
IFS0SET = 0x00000040; // Enable OC1 interrupt
IPC1SET = 0x001C0000; // Set OC1 interrupt priority to 7,
// the highest level
IPC1SET = 0x00030000; // Set Subpriority to 3, maximum
T2CONSET = 0x8000; // Enable Timer2
OC1CONSET = 0x8000; // Enable OC1

// Example code for Output Compare 1 ISR:
void__ISR(_OUTPUT_COMPARE_1_VECTOR, ipl7) OC1_IntHandler (void)
{
// insert user code here
IFS0CLR = 0x0040; // Clear the OC1 interrupt flag
}
Attachments
Puls 1.fcfx
(7.64 KiB) Downloaded 27 times

User avatar
Benj
Matrix Staff
Posts: 13989
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4253 times
Been thanked: 4008 times
Contact:

Re: Continuous Output Pulse at Compare 1 module

Postby Benj » Sat Aug 11, 2018 12:46 pm

Hello,

You can maybe use the PWM component to do the same thing without having to do things like clear the interrupt flag. Have a look here.

Puls 2.fcfx
(8.76 KiB) Downloaded 43 times

Speed64
Posts: 29
Joined: Sat Jul 16, 2016 12:08 pm
Contact:

Re: Continuous Output Pulse at Compare 1 module

Postby Speed64 » Sun Aug 12, 2018 8:52 am

Hello Benj,
Thank you very much.
It works, unfortunately I only come to 12.5Mhz.
How can you make it faster?

Sincerely
Speed64