NRZ coding who to start

Hi!.
I need to decode a Rs-232 signal who is encoded using a modified NRZ coding.

This is easy, the 0 from the Rs-232 are coded in a 5uSeg pulse, and the 1 logic is only GND. So when a 0 value starts, a 5Useg pulse apears.

Now i want to decode this signal, for that i need to use INTs and a Timmer?.
SoftSerial will be the point to start? other thing that use a similar coding?

Best Regards
Frank

Some interface to some device use a similar coding?, only to beging to learn who works the timers and how to rebuild or decode this RS-232 signal.

I think that you are talking about NRZ-L (right?)

Have you though about just using an inverter logic gate? (make sure data rate is ok)

Yes is NRZ left, but if i use 2400Bps as speed, i need to change that 5uS for a 216uS pulse to fit in the 2400Bps timming.

1)So the idea is or decode this 5uS pulse directly by the arduino.
2)Or use a trigger and a RC timmer to get this 216uS pulse when a 5uS pulse apears.

Ideas??
Best Regards
Frank

If you really wanted to do it not using hardware, you can set up a timer interrupt

void SetupTimerISR() {
  // Disable interrupts while setting registers
  cli();

  // Reset control registers
  TCCR2A = 0;
  TCCR2B = 0;

  // Clear Timer on Compare Match (CTC) Mode
  TCCR2A |= (1 << WGM21);

  // Prescaler x1
  TCCR2B |= (1 << CS20);

  // Interrupt every 160/16e6 = 10 usec
  OCR2A = 159;

  // Use system clock for Timer/Counter2
  ASSR &= ~(1 << AS2);

  // Reset Timer/Counter2 Interrupt Mask Register
  TIMSK2 = 0;

  // Enable Output Compare Match A Interrupt
  TIMSK2 |= (1 << OCIE2A);

  // Enable interrupts once registers have been update
  sei();
}

// This ISR is run when Timer/Counter2 reaches OCR2A
ISR(TIMER2_COMPA_vect)
{
  Interrupt_flag = 1;
}

and store the input to a pin by using something like...

_byte = (_byte << 1) + !(PINx & (1 << Pxn));

... Where PINx is PORTx's reading register (pg 78 of datasheet), and Pxn is the bit you want to look at.

You would then need to do some sort of error check, because missing a bit in this situation would be a catastrophic outcome for the message.

Very Thank you Apple, yes this data have a CRC inside the data stream so i must use it to check if the packet is or not valid.

I gonna to start with it, in few days i write with the results.

Best Regards
Frank

This 5uS pulse comes from a IR led. What i do to pick this 5us pulse is use a BP104 photodiode. What i see playing with severals configurations (a NPN transistor and a Hex Inv) and several R values to pol. the diode is this.

The rising edge change with the distance and position from the IR led to the photodiode. The falling edge never change.

I meen the start of the 5us pulse varies with the diode position and with the current through it. With a small current the pulse looks complete, but with more current the pulse go small and only the falling edge keeps the same position the start moves to the stop position of the edge.

Now, i select a bad IR receiver?, i must use a phototransistor and not a photodiode (for me are the same), the speed of this diode is 100nSeg so i hope this is not the problem. :stuck_out_tongue:

My idea is use only the falling edge of the pulse, and waits for this edge to start the conter/delay to recovery the 416uS to generate the correct serial baud rate.

My theory is valid? :o
Best Regards
Frank

Issue ready!, using the falling edge of the IR signal works great!.

Now i want to use the interrupt.h and the timers to analize the data.

But i'm using a Mega 8 not the 168, so what are the changes at the registers names to get it working in a mega 8 device? :stuck_out_tongue:

Best Regards
Frank