Mac,
Many thanks indeed for your quick response !
Yes, the microseconds is a challenge to handle. Even my bus is 24Mhz, its not enough to calculate something between of pulses.
Basically the device send CRC at the and of sequence. 40 bit is a 5 byte. First four is data and last one is CRC. So, it will be easy to detect the failure. Also, project is not critical to the other interrupt ruitines during the reading of this particular sensor.
Here is what I have now:
This function looks exactly as you mention: set port to OUT, send logical zero, switch to input mode, turn on TPM CH0
to capture.
void HumStartSignal(void)
{
h_cnt=0;
TPM1C0SC = 0x0; // RESET counters for the channels,
TPM1C0SC_CH0F = 0; // Reset ELS0A/B to set port as regular port, Reset CH0F flag.
HUMportDD = 0xFF; // Switch port to OUT
HUMport = 0x00; // Clear port (set Low)
WaitNms(25); // Wait 25ms
HUMport = 0x01; // Set pin to HIGH
HUMportDD = 0x00; // Switch port to IN
// Set CH0 in Input Capture Mode on falling edges (this command reset counters as well)
// CHnF CHnIE MSnB MSnA ELSnB ELSnA 0 0
TPM1C0SC = 0x48;
}
Here is IRQ routine:
interrupt void TPM1C0_ISR(void)
{
TPM1C0SC_CH0F = 0; // ACK channel interrupt. Reading flag, then write a 0 to the bit.
h_var[h_cnt++] = TPM1C0V;
}
And here is external function to analyse the h_var array:
unsigned long HumReadByte(void)
{
unsigned char i;
unsigned long num = 0;
int delta;
for(i=0; i<h_cnt; i+=2){
delta = h_tik[i+1] - h_tik[i];
if(delta > 70 && delta < 110)
num = ((num << 1) | 1);
if(delta > 50 && delta < 70)
num = (num << 1);
}
return num;
}
Then in main loop I call them like this:
HumStartSignal();
WaitNms(50); // wait 50 ms
num = HumReadByte();
So, the idea is to use Interrupt to gather "time stamps" for each event. And then analyse it in the main program.
Unfortunately, for some uncertain reason this code cannot be handled by debugger. It goes through only if I commented out HumReadByte().
I did try various value for stack in PRM. The MAP file shows this one:
Summary of section sizes per section type:
READ_ONLY (R): 10CB (dec: 4299)
READ_WRITE (R/W): 599 (dec: 1433)
NO_INIT (N/I): AC (dec: 172)
I don't think its a memory issue, since JM60 has 60K ROM plus 4K RAM. There is no warnings. Its just hang.
Sometimes debugger jump to this line:
INIT_SP_FROM_STARTUP_DESC(); /*lint !e960 MISRA 14.3 REQ, not a null statement (instead: several HLI statements) */
Regards,
d0ct0r