Hi All ,
I am trying to port my daikin AC remote control application to Attiny85 , but currently stuck as I am not expert at all.
To switch on AC I need to send the following sequence
unsigned int power_ON[] ={ 3420 , 1660 , 460 , 1220 , 460 , 380 , 480 , 360 , 500 , 340 , 500 , 1200 , 460 , 380 , 480 , 360 , 460 , 380 , 480 , 360 , 460 , 1240 , 460 , 380 , 460 , 1220 , 460 , 1240 , 480 , 360 , 480 , 1200 , 460 , 1240 , 480 , 1200 , 460 , 1220 , 500 , 1200 , 480 , 360 , 460 , 380 , 500 , 1180 , 500 , 360 , 480 , 360 , 460 , 380 , 480 , 360 , 460 , 380 , 460 , 380 , 460 , 1240 , 460 , 1220 , 480 , 1200 , 500 , 1200 , 460 , 380 , 460 , 380 , 460 , 380 , 460 , 380 , 480 , 360 , 500 , 360 , 460 , 380 , 460 , 380 , 460 , 380 , 460 , 380 , 460 , 380 , 460 , .. , 460 , 1240 , 460 , 380 , 460 , 380 , 460 , 380 , 460 , 380 , 460 , 1220 , 460 , 1240 , 460 , 380 , 460 , 1220 , 460 , 400 , 440 , 400 , 460 , 380 , 460 , 380 , 460 , 380 , 460 , 380 , 460 , 380 , 460 , 380 , 460 , 380 , ..};
I am using the following code available
// This procedure sends a 38KHz pulse to the IRledPin
// for a certain # of microseconds. We'll use this whenever we need to send codes
void pulseIR(long microsecs) {
// we'll count down from the number of microseconds we are told to wait
cli(); // this turns off any background interrupts
while (microsecs > 0) {
// 38 kHz is about 13 microseconds high and 13 microseconds low
digitalWrite(IRledPin, HIGH); // this takes about 3 microseconds to happen
delayMicroseconds(10); // hang out for 10 microseconds
digitalWrite(IRledPin, LOW); // this also takes about 3 microseconds
delayMicroseconds(10); // hang out for 10 microseconds
// so 26 microseconds altogether
microsecs -= 26;
}
sei(); // this turns them back on
}
void sendDaikinOn()
{
int i1;
for (i1 = 0; i1 < size_off; i1++)
{
pulseIR(power_ON[i1]);
i1++;
delayMicroseconds(power_ON[i1]);
}
}
As per the advice from , dc42 using the following code ,
void setup()
{
PORTB = 0;
DDRB = 0b00000010; // set PB1 (= OCR1A) to be an output
setFrequency(38000) ;
}
// Set the frequency that we will get on pin OCR1A but don't turn it on
void setFrequency(uint16_t freq)
{
uint32_t requiredDivisor = (F_CPU/2)/(uint32_t)freq;
uint16_t prescalerVal = 1;
uint8_t prescalerBits = 1;
while ((requiredDivisor + prescalerVal/2)/prescalerVal > 256)
{
++prescalerBits;
prescalerVal <<= 1;
}
uint8_t top = ((requiredDivisor + (prescalerVal/2))/prescalerVal) - 1;
TCCR1 = (1 << CTC1) | prescalerBits;
GTCCR = 0;
OCR1C = top;
}
// Turn the frequency on
void on()
{
TCNT1 = 0;
TCCR1 |= (1 << COM1A0);
}
// Turn the frequency off and turn off the IR LED.
// We let the counter continue running, we just turn off the OCR1A pin.
void off()
{
TCCR1 &= ~(1 << COM1A0);
}
void loop() {
delay(10000);
sendDaikinOn();
delay(10000);
}
void sendDaikinOn()
{
int i1;
for (i1 = 0; i1 < size_on; i1++)
{
on ();
delayMicroseconds(power_ON[i1]);
// pulseIR(power_ON[i1]);
i1++;
off ();
delayMicroseconds(power_ON[i1]);
}
}
But this is not working , can some one please help me on this.
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.