Hi,
I am revisiting an old project where a T4.1 is controlling ancient IC's on an 8-bit parallel bus with 1MHz clock generated by a PWM on pin 33. So far I have toggled the CS asynchronous to the clock. This works, but sometimes waste write cycles. And more importantly, I dont like how the oscilloscope image looks ;-) The hardware is fixed so I cant just wire up the clock to another pin.
So I a trying to get at least some synchronization to the PWM clock signal. Looking at old posts the suggestion was to compare the correct i.Mx PWM counter registers to understand where the PWM is in its cycle. However I have tried a lot of combinations without much luck.
I deduced that pin 33 is FLEXPWM2.0 (possibly wrong?) but not sure if it is PWM A, B or X. Nevertheless I tried all VALx with no effect. It looks like the sequence stays more or less unsynced to the PWM.
Below is the write sequence (a bit messy due to experimentation but I think the concept is simple). Any suggestions?
I am revisiting an old project where a T4.1 is controlling ancient IC's on an 8-bit parallel bus with 1MHz clock generated by a PWM on pin 33. So far I have toggled the CS asynchronous to the clock. This works, but sometimes waste write cycles. And more importantly, I dont like how the oscilloscope image looks ;-) The hardware is fixed so I cant just wire up the clock to another pin.
So I a trying to get at least some synchronization to the PWM clock signal. Looking at old posts the suggestion was to compare the correct i.Mx PWM counter registers to understand where the PWM is in its cycle. However I have tried a lot of combinations without much luck.
I deduced that pin 33 is FLEXPWM2.0 (possibly wrong?) but not sure if it is PWM A, B or X. Nevertheless I tried all VALx with no effect. It looks like the sequence stays more or less unsynced to the PWM.
Below is the write sequence (a bit messy due to experimentation but I think the concept is simple). Any suggestions?
Code:
void BusManager::_write()
{
uint8_t CSpin = _nextEvent->CSpin;
if (_stage == 0)
{
uint8_t address = _nextEvent->address;
uint8_t data = _nextEvent->data;
if (_oldAddress != address)
{
_oldAddress = address;
digitalWriteFast(SID_A0, bitRead(address, 0));
digitalWriteFast(SID_A1, bitRead(address, 1));
digitalWriteFast(SID_A2, bitRead(address, 2));
digitalWriteFast(SID_A3, bitRead(address, 3));
digitalWriteFast(SID_A4, bitRead(address, 4));
}
if (_oldData != data)
{
_oldData = data;
digitalWriteFast(SID_D0, bitRead(data, 0));
digitalWriteFast(SID_D1, bitRead(data, 1));
digitalWriteFast(SID_D2, bitRead(data, 2));
digitalWriteFast(SID_D3, bitRead(data, 3));
digitalWriteFast(SID_D4, bitRead(data, 4));
digitalWriteFast(SID_D5, bitRead(data, 5));
digitalWriteFast(SID_D6, bitRead(data, 6));
digitalWriteFast(SID_D7, bitRead(data, 7));
}
// check if passed first trigger point
_triggerTime = FLEXPWM2_SM0VAL4;
_currentTimer = FLEXPWM2_SM0VAL1;
while ( _currentTimer < _triggerTime ) delayNanoseconds(10); // wait for suitable first trigger point
// set CS
_setCS(CSpin, LOW);
// should check here for a second trigger point, then delay to ~100ns after clock goes low
delayNanoseconds(100);
//delayNanoseconds(990); // note: this works without any timing checks
_stage = 1;
}
if (_stage == 1)
{
_setCS(CSpin, HIGH);
_nrBufferedItems--;
_movePtr();
_stage = 0;
}
}
Last edited: