I need to synchronize the rising edge of a PWM with another signal pulse's falling edge on a LPC1114FN28 (trying to drive a TCD1304DG), but am failing to achieve this so far. I have tried the following:
while (LPC_GPIO0->MASKED_ACCESS[ClockMask]); //wait for the clock to go low while (!(LPC_GPIO0->MASKED_ACCESS[ClockMask])); //wait for the start of PWM cycle LPC_GPIO0->MASKED_ACCESS[ICGMask] = 0x0; //make the ICG pin go low
ClockMask is a mask of the corresponding PWM pin, running at 1MHz frequency, 50% duty cycle and
ICGMask a mask of the pin I'm trying to synchronize with the PWM.
The strange problem I encountered is that one of the two
whiles seem to block forever for some reason and any code after them does not get executed. When I remove them, it works OK.
This could be probably caused by the instructions for the
while lasting the same as is the PWM period and thus the condition would always see the pin in the same state, but that seems rather improbable to me...
I am running the chip at 48MHz from the IRC and the PWM measured with my oscilloscope is practically flawless.
So what could I be doing wrong? Is there any better way to do this? Would writing this part of code in assembler help with the timings (they need to be pretty precise)? If so, is there any tutorial for this?
Thanks in advance for any answers!
Even using interrupts I was unable to get sufficiently invariable results - the timing of the interrupt after the pulse edge changes. I will try more methods...
Other methods did not work at all. This is probably simpy unachievable, but I do not know, what else could I be doing wrong if not the timing (as the Toshiba CCD is still not responding).