Hey All,
A bit of a newbie in the arduino world, I only got my kit a week ago, I must admit. So I have an IC running at 370900Hz (it's a key encoder, over a composite video signal), and the matching decoder is buried in a rack so there's no chance of swapping out ICs.
Anyway, the IC is, as you would expect, encoding parallel to serial, and pumping it out over a tx. I have been given the task of replicating it entirely using an ATmega328PU. So that's capturing the serial data, with the intention of pumping it out at a later date completely independently from the encoder.
So my timer setting which gets us to the desired Khz:
void setup()
{
Serial.begin(9600);TCCR0A = (1 << WGM01);
TCCR0B = (1 << CS00);
OCR0A = 42;
//OCR0B = 42; // Flip Flop
TIMSK0 = (1 << OCIE0A); //| (1 << OCIE0B);
sei();DDRD = 0x00; //PORTD set as input
DDRB = 0xFF;
}
I've been toying with the idea of running two timers, but i'll digress about that later.
byte datas = 0x00;
ISR(TIMER0_COMPA_vect)
{
datas = PIND;
PORTB = datas;
This bit catches the vector/interrupt, and for testing purposes it's routing the 8bit register from PIND to PORTB. Direct pin extraction was a bit much for the arduino. So pin 2 on the arduino input, equals pin 11 output. I did this to test that the kHz is working, so i can use it in a live environment.
Now onto my question, am I fighting a losing battle here? I have read many people who say 370±Khz is a bit ambitious.
say if I do: data = PIND; i++; It is way out of sync.
My oscilloscope is reading around 370Khz, 15ms burst, and the datasheet for the IC says it waits for a bit before transmitting a simple 2 word serial transmission.
Is there a quick and efficient way to stream the bits directly to a memory address, like a stack? I was considering running the timer twice as fast, and every operation takes my byte and saves it. The whole timer operation activated by a FALLING interrupt.
e.g.:
> boolean flipflop = false;
> ISR(TIMER0_COMPB_vect)
> {
> if (flipflop)
> {
> data [ i ] = datas;
> }
>
> flipflop = !flipflop;
> }
Should I just wait use my oscilloscope to analyse the serial data and build my arrays from there?