0

I am trying to send integers from 0 to 255 to my Atmega8L AVR, and use that value as PWM and light up a LED for each pin (3 pins)...

I am doing this in Java (Android) to send data to my AVR via USART:

byte toSend[] = {(byte)intA, (byte)intB, (byte)intC};

bleService.writeMLDP(toSend); //sends data to AVR (byte[] or String, it's working fine)

In my AVR code I have the following:

int i = 0, filled_all = 0;
char bytes[3];

//ISR is called everytime data is received
ISR( USART_RXC_vect ) {
    bytes[i] = UDR; //UDR is the data received
    i++;
    if(i == 3) filled_all = 1;
    if(filled_all == 1) {
        OCR1A = bytes[0]; //sets 1st PWM
        OCR1B = bytes[1]; //sets 2nd PWM
        OCR2 = bytes[2];  //sets 3rd PWM
        i = 0;
        filled_all = 0;
    }
}

There is a lot of problems:

  • All LEDs are starting on full-power (it's not inverted and I'm setting it to 0x00 at the start of my "main()";
  • I have to send data twice to change the LEDs' power;
  • 1st and 2nd pins are inverted (as if data is being sent like toSend[1] -> toSend[0] -> toSend[2]).
  • 1
    You should configure timers and pins, see datasheet for details ;) http://www.atmel.com/Images/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet.pdf – LZ041 Jun 23 '17 at 06:58
  • Yes, there's a lot of code missing here to set up PWM with the timer(s). – TomServo Jun 23 '17 at 11:31
  • What PWM mode are you trying to use? What are your WGM bits set to? – TomServo Jun 23 '17 at 20:15
  • I'm, currently, using Fast-PWM mode... Setting bits to WGM10, WGM12, WGM20 and WGM21 – T. Lima Jun 25 '17 at 00:31

0 Answers0