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
#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:
#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:
#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);
}