Author Topic: ATTINY IR carrier delay problems.  (Read 1963 times)

0 Members and 1 Guest are viewing this topic.

Offline DaGlitchTopic starter

  • Contributor
  • Posts: 21
  • Country: us
ATTINY IR carrier delay problems.
« on: January 18, 2016, 06:09:09 pm »
Was just looking for some extra help to figure out what I'm doing wrong. The carrier frequency looks right but it doesn't seem to be delaying by microseconds properly. I think I have a timer set up wrong, but can't figure it out. For instance, If i set the rawcode to all 1uS, the output on my scope is closer to steps of something like 33us. If I have a "10" in the raw codes, I want a 460khz pulse for 10us.

IRTinyTX.cpp
Code: [Select]
#include "IRTinyTX.h"

void IRsend::sendRaw(unsigned int buf[], int len, int khz)
{
    enableIROut(khz);
    for (int i = 0; i < len; i++) {
        if (i & 1) {
            space(buf[i]);
        }
        else {
            mark(buf[i]);
        }
    }
    space(0); // Just to be sure
}

void IRsend::mark(int16_t time) {
    TCCR0A |= _BV(COM0B1); // Enable pin 6 (PB1) PWM output       
    delayMicroseconds(time);   
}

void IRsend::space(int16_t time) {
    TCCR0A &= ~(_BV(COM0B1)); // Disable pin 6 (PB1) PWM output
    delayMicroseconds(time);   
}

void IRsend::enableIROut(uint8_t khz) {
  DDRB |= _BV(IRLED); // Set as output

  PORTB &= ~(_BV(IRLED)); // When not sending PWM, we want it low

  // Normal port operation, OC0A/OC0B disconnected 
  // COM0A = 00: disconnect OC0A
  // COM0B = 00: disconnect OC0B; to send signal set to 10: OC0B non-inverted   
  // WGM0 = 101: phase-correct PWM with OCR0A as top
  // CS0 = 000: no prescaling
  TCCR0A = _BV(WGM00);
  TCCR0B = _BV(WGM02) | _BV(CS00);

  OCR0A = 8; //This should get me my ~460khz carrier
  OCR0B = OCR0A / 2; // 50% duty cycle
}

IRTinyTx.h:
Code: [Select]
#ifndef IRTinyTX_h
#define IRTinyTX_h

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#define IRLED PB1 // (Used as OC0B) - pin 6 on ATtiny25
//#ifndef F_CPU
#define F_CPU 7372800UL  // 7.3728 MHz

//#endif

class IRsend
{
public:
  IRsend() {}
  void enableIROut(uint8_t khz);
  void sendRaw(unsigned int buf[], int len, int khz);
private:
  void mark(int16_t usec);
  void space(int16_t usec);
};

#endif

and my sketch:
sketch.ino:
Code: [Select]
#include <IRTinyTX.h>

unsigned int rawCodes[] = {10,50,10,50,10,50,10,50,10,50};             

IRsend irsend;

void setup()
{
   
}

void loop()
{
     irsend.sendRaw(rawCodes, 10, 460);
}
« Last Edit: January 18, 2016, 06:49:26 pm by DaGlitch »
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1989
  • Country: dk
Re: ATTINY IR carrier delay problems.
« Reply #1 on: January 18, 2016, 06:35:26 pm »
Don't know the code lib you're using , but did you notice the variable is named hz not khz

460KHz in a "controlled" software loop would be hard to achieve on an avr , unless in a tight loop.
Leaves around 44 cycles pr. Hz on a 20Mhz clock

Let's hope it's not build using the 'duinos DigitalWrite


/Bingo
 

Offline DaGlitchTopic starter

  • Contributor
  • Posts: 21
  • Country: us
Re: ATTINY IR carrier delay problems.
« Reply #2 on: January 18, 2016, 06:39:12 pm »
Yea, this was a mistake with my copy and paste. That is actually not used any more since I just manually defined OCR0A. I had it where I would just define the khz I was targetting, but decided to just hard code it.

I get the 460khz carrier just fine. It's just that it stays on far longer than I expect.

Don't know the code lib you're using , but did you notice the variable is named hz not khz

460KHz in a "controlled" software loop would be hard to achieve on an avr , unless in a tight loop.
Leaves around 44 cycles pr. Hz on a 20Mhz clock

Let's hope it's not build using the 'duinos DigitalWrite


/Bingo
« Last Edit: January 18, 2016, 06:41:39 pm by DaGlitch »
 

Offline DaGlitchTopic starter

  • Contributor
  • Posts: 21
  • Country: us
Re: ATTINY IR carrier delay problems.
« Reply #3 on: January 19, 2016, 01:04:14 am »
Also, I am using the ATTinyCore by Spence Konde http://drazzy.com/package_drazzy.com_index.json

Also with the following added to the boards.txt file:
Code: [Select]
attinyx5.menu.clock.7external.bootloader.low_fuses=0xFF
attinyx5.menu.clock.7external.build.f_cpu=7372800L
attinyx5.menu.clock.7external.bootloader.file=empty/empty_all.he
« Last Edit: January 19, 2016, 01:06:02 am by DaGlitch »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf