ATTINY IR carrier delay problems. - Page 1
Forum section: electronics / general

author: DaGlitch
author_rank: Contributor
timestamp: January 18, 2016, 06:09:09 pm
content: 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.cppCode:#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);}else {mark(buf);}}space(0); // Just to be sure}void IRsend::mark(int16_t time) {TCCR0A |= _BV(COM0B1); // Enable pin 6 (PB1) PWM outputdelayMicroseconds(time);}void IRsend::space(int16_t time) {TCCR0A &= ~(_BV(COM0B1)); // Disable pin 6 (PB1) PWM outputdelayMicroseconds(time);}void IRsend::enableIROut(uint8_t khz) {DDRB |= _BV(IRLED); // Set as outputPORTB &= ~(_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 prescalingTCCR0A = _BV(WGM00);TCCR0B = _BV(WGM02) | _BV(CS00);OCR0A = 8; //This should get me my ~460khz carrierOCR0B = OCR0A / 2; // 50% duty cycle}IRTinyTx.h:Code:#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//#endifclass 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);};#endifand my sketch:sketch.ino:Code:#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);}

author: bingo600
author_rank: Super Contributor
timestamp: January 18, 2016, 06:35:26 pm
content: Don't know the code lib you're using , but did you notice the variable is named hz not khz460KHz 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 clockLet's hope it's not build using the 'duinos DigitalWrite/Bingo

author: DaGlitch
author_rank: Contributor
timestamp: January 18, 2016, 06:39:12 pm
content: 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.Quote from: bingo600 on January 18, 2016, 06:35:26 pm

author: DaGlitch
author_rank: Contributor
timestamp: January 19, 2016, 01:04:14 am
content: Also, I am using the ATTinyCore by Spence Kondehttp://drazzy.com/package_drazzy.com_index.jsonAlso with the following added to the boards.txt file:Code:attinyx5.menu.clock.7external.bootloader.low_fuses=0xFFattinyx5.menu.clock.7external.build.f_cpu=7372800Lattinyx5.menu.clock.7external.bootloader.file=empty/empty_all.he