Help help help!

Discussion in 'Embedded Systems and Microcontrollers' started by allahjane, Jan 13, 2013.

  1. allahjane

    Thread Starter Member

    Sep 19, 2012

    The setup:

    two atmega8L-PU on seperate boards .. independent power supply and other components including 4 LEDs on each

    The first atmega8 has a ASK 434MHZ RF Transmitter module connected to its Tx pin

    The second one has a ASK 434MHZ RF Receiver module connected to its Rx pin

    both tuned to same Baud rate & have appropriate antenna's attached

    also both atmega 8 have same 1MHz internal clock

    NOTE:- the circuit path goes close to each other (I dont think it is causing any cross talk ! is it?)

    The Algorithm

    the atmega8 with the transmitter makes few ADC conversions and selects a byte from group of 4 pre defined bytes on basis of the result and sends it to the Uart ...directly writing the byte to UDR and then polling(waiting) till it is sent the sent byte is also shown by its LED.. then it repeats the procedure from ADC calcuations

    the second atmega8(receiver) has 4 LED that light up on basis of received data byte.. each corresponding to one byte from the 4;

    Transmitter LOGIC
    Code ( (Unknown Language)):
    4. for(i=1;i<5;i++)
    5. {
    6. if(getADC(i)>((max[i-1]+min[i-1])/2))
    7. {
    8.     switch(i){
    9.     case 1:
    10.     byte=0xff;
    11.     break;
    12.     case 2:
    13.     byte=0xfe;
    14.     break;
    15.     case 3:
    16.     byte|=0xfd;
    17.     break;
    18.     case 4:
    19.     byte|=0xfc;
    20.     break;
    21.     };
    22.     dpadSelective(i,1);
    23. }
    24. else
    25. dpadSelective(i,0);
    26. }//end for
    27. if(state==transmitting)
    28. sendByte( byte);
    30. }
    34.     void sendByte(int byte){
    35. UDR = byte;
    36. while (( UCSRA & (1 << TXC )) == 0) {};
    37. }


    the receiver listens sometime and sometime it ignores the transmitter completely.

    one of the LED corresponding to byte 0xff will mostly light up but others only flicker (error in received data causing rapid on/off) while some may never light up

    and sometimes the wrong LED lights up for the byte

    however if I send a single byte repeatedly without any ADC and other calculation it works fine!

    that said the link between RF modules are correct!

    But the data gets out of sync quickly

    I tried different baudrates,internal clock frequencies,stop bits as well as different data bytes and even changing between polling and interrupt methods (interuppt made it worse) and hell! also changed the optimisation levels


    The thinking :rolleyes:

    I think there are two major culprits the internal clock and the noise prone transmission

    I have heard the ATMEGA8 has a bad Internal clock a so they both get out of sync quickly

    also as I increase the BAUD rate the situation becomes worse

    on the noise side the byte with more ONES (1) in upper nibble are received more than those having mostly 0

    I think since its ASK there is a probablity that if you transmit zeros there is more room for noise to take over (ASK only)

    HELP ME :(
    Last edited by a moderator: Jan 13, 2013
  2. MrChips


    Oct 2, 2009
    First rule of posting. Use a title that is relevant to the question.

    Think what would happen if half the questions had titles like "Help help help!"
    allahjane likes this.
  3. spinnaker

    AAC Fanatic!

    Oct 29, 2009

    Second rule of posting. Use a capital letter to start your sentences.

    Third rule post a schematic.

    Fourth rule

    You need to be able to debug your own code and narrow the problem done some more. Few people have the time to read through a giant post like yours and give you an answer. The only thing worse than not enough information is too much information.

    One way to help trouble shoot and debug is to create a new program that targets your specific issue. That way you can concentrate on the problem and better show the issue to forum members.
  4. kubeek

    AAC Fanatic!

    Sep 20, 2005
    First check how it works when connected straight tx to rx.
    For the future, when developing something like this it is almost mandatory to have a spare USART so you can print debug messages, this can make debugging so much easier.
    The trasmitter and receiver that you use, are those just simple analog transmitters? Then you will need to send much more than a signle byte to be sure you get the right data on the other end. Something like a start byte, data payload and checksum should improve it. This also means you will have to transmit multiple times to have some chance of getting the data to the other side.