Sunteți pe pagina 1din 6

Arduino (http://arduino.

cc)
Search the Arduino Forum
search

(http://forum.arduino.cc/index.php? Advanced Search (http://forum.arduino.cc/index.php?PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&action=search;advanced) PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&) | Arduino Forum (http://forum.arduino.cc/index.php? PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&) :: Using Arduino (http://forum.arduino.cc/index.php?PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&#2) :: Networking, Protocols, and Devices (http://forum.arduino.cc/index.php?PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&board=11.0) :: DECODING HT6P20 WITH attachinterrupt previous topic (http://forum.arduino.cc/index.php?PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&topic=175557.0;prev_next=prev#new) next topic (http://forum.arduino.cc/index.php? PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&topic=175557.0;prev_next=next#new)
Print (http://forum.arduino.cc/index.php? PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&action=printpage;topic=175557.0)

Pages: [1] Go Down Author Topic: DECODING HT6P20 WITH attachinterrupt (Read 531 times) 0 Members and 1 Guest are viewing this topic.

bugalaws (http://forum.arduino.cc/index.php? DECODING HT6P20 WITH attachinterrupt (http://forum.arduino.cc/ind PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&action=profile;u=193409) (http://forum.arduino.cc/index.php? PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&topic=175557.msg130273 PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&topic=175557.msg1302732#msg1302732) on: July 03, 2013, 09:33:58 pm Offline Newbie Karma: 0 Posts: 1 ////////////////////////////////// ENGLISH //////////////////////////////////////////////////// /* DECODER WITH ARDUINO HT6P20B 2M2 RESISTOR IN OSC. (http://forum.arduino.cc/index.php? USE THIS CODE NO TIMER, INTERRUPTION OR FOREIGN AND PIN SET INPUT. PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&action=profile;u=193409) IT MEASURES OF PILOT TIME PERIOD AND COMPARE IF YOU ARE INSIDE TRACK SET, IF HE GOES TO CODE AND MAKING MEDIDES PERIOD OF TIME IN HIGH LEVEL IF YOU HAVE INSIDE TRACK ACRECENTA BIT 1 0 OR VARIABLE IN NO EVENT _DATA ZERA VARIABLES AND RE-START AFTER RECEIVING ALL IT TAKES THE BITS BITS 4 CODE OF ANTE AND TESTS TO KNOW IF THE CODE WAS RECEIVED CORRECTLY, IF HE RECEIVED RIGHT PLACE IN A VARIABLE ANTCODE 1. CREATED BY: JACQUES DANIEL MORESCO DATE: 28/02/2012 USING ARDUINO 0022. PHONES: 54 3324 2251 54 9206 7168 E-MAIL: ibisul@ibisul.com.br (mailto:ibisul@ibisul.com.br) Allowed public use, but should keep the author's name. /////////////////////////////////////////////////////////////////////////////////////////////// CHANGES MADE TO WORK WITH STOP USING TIMER attachInterrupt LEAVING THE RELEASED FOR ARDUINO OTHER TASKS /////////////////////////////////////////////////////////////////////////////////////////////// ALTERED BY MARCELO LOPES SIQUEIRA DATE 03/07/2013 USING ARDUINO 1.0.5 E-MAIL: bugalaws@hotmail.com (mailto:bugalaws@hotmail.com) Allowed public use, but should keep the authorship. */ ///////////////////////////////////////////////////////////////////////////////////////// int x,startbit, startbit1,ctr,dataok,t1,larpulso,larpulso1,larpulso2,larpulso3,larpulso4,bt1,bt2,antcode=0; unsigned long _data, _data2=0; // DATA o Cdigo recebido do HT6p20 todos os 28 BITS onde, 22 do coodigo+2 dos botes+4 do anti-codigo; unsigned long _dur,_dur1; // Durao do Pulso byte _pinIn = 2; // Pino que vai receber o sinal RF digital.

#define PPM_Pin 2 //this must be 2 or 3 void setup() { Serial.begin(9600); Serial.println("ready"); pinMode(PPM_Pin, INPUT); pinMode(13, OUTPUT); digitalWrite(13, LOW); attachInterrupt(PPM_Pin - 2, read_ppm, CHANGE); TCCR1A = 0; //reset timer1 TCCR1B = 0; TCCR1B |= (1 << CS11); //set timer1 to increment every 0,5 us

} void loop() { Serial.println("Conteudo _data2 - " + String(_data2,BIN)); delay(500); } void read_ppm(){ //leave this alone static unsigned long counter; //1020 ciclos equivalem a um pulso 510us //2000 1000us //20000 10000us // x 12000 counter = TCNT1; //Adicion a quantidade de ciclos TCNT1 = 0;

_dur = counter; // Testa o tempo piloto at o Bit de inicio; if(_dur > 20000 && _dur < 24000 && startbit==0) { digitalWrite(13,!digitalRead(13)); larpulso=_dur/23; larpulso1=larpulso-100; larpulso2=larpulso+100; larpulso3=larpulso+larpulso-50; larpulso4=larpulso+larpulso+50; startbit=1; _dur=0; _data=0; dataok=0; ctr=0; }//Fim da condio do time pilot(inicio dos bites) if(startbit == 1) { startbit++; }else if (startbit==2 && dataok==0 && ctr < 28 && digitalRead(2) == HIGH) //Se possui um bit inicial vlido { ++ctr; _dur1 = counter; if(_dur1 > larpulso1 && _dur1 < larpulso2) // Se a largura de pulso entre 1/4000 e 1/3000 segundos { //startbit = 1; _data = (_data << 1) ; // anexar um * 1 * para a extremidade mais direita do buffer } else if(_dur1 > larpulso3 && _dur1 < larpulso4) // Se a largura de pulso entre 2/4000 e 2/3000 segundos { //startbit = 1; _data = (_data << 1) + 1; // anexar um * 0 * para a extremidade mais direita do buffer } else { /* fora finalizao do lao */ startbit=0; } } if (ctr==28) { if (bitRead(_data,0)==1 && bitRead(_data,1)==0 && bitRead(_data,2)==1 && bitRead(_data,3)==0) { antcode=1; } else { ctr = 0; //Serial.println(_data,BIN); } if (antcode==1) {// Se foram recebidos todos os 28 Bits, o valor vai para a variavel _data e pode ser usada como exemplo abaixo. dataok=1; //Serial.println("Antecode OK - " + String(_data,BIN)); _data2 = _data; ctr=0;

startbit=0; antcode=0; //delay(200); } } }//Fim da funo read_ppm()

///////em portugus brasil //////////////////////////////////////// /* ARDUINO DECODIFICADOR HT6P20B COM RESISTOR DE 2M2 NO OSC. ESTE CDIGO NO USA TIMER, INTERRUPO EXTERNA E NEM PINO DEFINIDO DE ENTRADA. ELE MEDE O TEMPO DO PILOT PERIOD E COMPARA SE EST DENTRO DA FAIXA DEFINIDA, SE TIVER ELE PASSA PARA CODE PERIOD E FAZ AS MEDIDES DE TEMPO EM NIVEL ALTO SE TIVER DENTRO DA FAIXA ACRECENTA BIT 1 OU 0 NA VARIAVEL _DATA CASO NO ZERA AS VARIVEIS E RE-INICIA APOS RECEBER TODOS OS BITS ELE PEGA OS 4 BITS DO ANTE CODE E TESTA PARA SABER SE O CDIGO FOI RECEBIDO CORRETAMENTE, CASO RECEBIDO CERTO ELE COLOCA A VARIAVEL ANTCODE EM 1. CRIADO POR: JACQUES DANIEL MORESCO DATA: 28/02/2012 USANDO ARDUINO 0022. FONES:54 3324 2251 54 9206 7168 E-MAIL: ibisul@ibisul.com.br (mailto:ibisul@ibisul.com.br) Permitido o uso pblico, mas deve-se manter o nome do autor. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// FEITA ALTERAO PARA FUNCIONAR COM INTERRUPO UTILIZANDO TIMER ATTACHINTERRUPT DEIXANDO LIBERADO O ARDUINO PARA AS OUTRAS TAREFAS ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// ALTERADO POR: MARCELO SIQUEIRA LOPES DATA 03/07/2013 USANDO ARDUINO 1.0.5 E-MAIL: bugalaws@hotmail.com (mailto:bugalaws@hotmail.com) Permitido o uso pblico, mas deve-se manter as autorias. */ int x,startbit, startbit1,ctr,dataok,t1,larpulso,larpulso1,larpulso2,larpulso3,larpulso4,bt1,bt2,antcode=0; unsigned long _data, _data2=0; // DATA o Cdigo recebido do HT6p20 todos os 28 BITS onde, 22 do coodigo+2 dos botes+4 do anti-codigo; unsigned long _dur,_dur1; // Durao do Pulso byte _pinIn = 2; // Pino que vai receber o sinal RF digital.

#define PPM_Pin 2 //this must be 2 or 3 void setup() { Serial.begin(9600); Serial.println("ready"); pinMode(PPM_Pin, INPUT); pinMode(13, OUTPUT); digitalWrite(13, LOW); attachInterrupt(PPM_Pin - 2, read_ppm, CHANGE); TCCR1A = 0; //reset timer1 TCCR1B = 0; TCCR1B |= (1 << CS11); //set timer1 to increment every 0,5 us } void loop() { Serial.println("Conteudo _data2 - " + String(_data2,BIN)); delay(500); } void read_ppm(){ //leave this alone static unsigned long counter; //1020 ciclos equivalem a um pulso 510us //2000 1000us //20000 10000us // x 12000 counter = TCNT1; //Adicion a quantidade de ciclos TCNT1 = 0;

_dur = counter; // Testa o tempo piloto at o Bit de inicio; if(_dur > 20000 && _dur < 24000 && startbit==0) { digitalWrite(13,!digitalRead(13)); larpulso=_dur/23; larpulso1=larpulso-100; larpulso2=larpulso+100; larpulso3=larpulso+larpulso-50; larpulso4=larpulso+larpulso+50; startbit=1; _dur=0; _data=0; dataok=0; ctr=0; }//Fim da condio do time pilot(inicio dos bites) if(startbit == 1) { startbit++; }else if (startbit==2 && dataok==0 && ctr < 28 && digitalRead(2) == HIGH) //Se possui um bit inicial vlido { ++ctr; _dur1 = counter; if(_dur1 > larpulso1 && _dur1 < larpulso2) // Se a largura de pulso entre 1/4000 e 1/3000 segundos { //startbit = 1; _data = (_data << 1) ; // anexar um * 1 * para a extremidade mais direita do buffer } else if(_dur1 > larpulso3 && _dur1 < larpulso4) // Se a largura de pulso entre 2/4000 e 2/3000 segundos { //startbit = 1; _data = (_data << 1) + 1; // anexar um * 0 * para a extremidade mais direita do buffer } else { /* fora finalizao do lao */ startbit=0; } } if (ctr==28) { if (bitRead(_data,0)==1 && bitRead(_data,1)==0 && bitRead(_data,2)==1 && bitRead(_data,3)==0) { antcode=1; } else { ctr = 0; //Serial.println(_data,BIN); } if (antcode==1) {// Se foram recebidos todos os 28 Bits, o valor vai para a variavel _data e pode ser usada como exemplo abaixo. dataok=1; //Serial.println("Antecode OK - " + String(_data,BIN)); _data2 = _data; ctr=0; startbit=0; antcode=0; //delay(200); } } }//Fim da funo read_ppm() Logged

Nick Gammon (http://forum.arduino.cc/index.php? Re: DECODING HT6P20 WITH attachinterrupt (http://forum.arduino.cc PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&action=profile;u=36095) (http://forum.arduino.cc/index.php? PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&topic=175557.msg130291 PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&topic=175557.msg1302914#msg1302914) Reply #1 on: July 04, 2013, 02:38:03 am Global Moderator Offline

Brattain Member Karma: 452 Posts: 18694 How to use this forum (http://arduino.cc/forum/index.php/topic,148850.0.html)

Code tags, please.

(http://forum.arduino.cc/index.php? PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&action=profile;u=36095)

Logged

Nick Gammon (http://forum.arduino.cc/index.php? Re: DECODING HT6P20 WITH attachinterrupt (http://forum.arduino.cc PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&action=profile;u=36095) (http://forum.arduino.cc/index.php? PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&topic=175557.msg130291 PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&topic=175557.msg1302916#msg1302916) Reply #2 on: July 04, 2013, 02:38:33 am Global Moderator Offline Brattain Member Karma: 452 Posts: 18694 And what was the question, exactly?

(http://forum.arduino.cc/index.php? PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&action=profile;u=36095)

Logged

mohandtome (http://forum.arduino.cc/index.php? Re: DECODING HT6P20 WITH attachinterrupt (http://forum.arduino.cc PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&action=profile;u=196726) (http://forum.arduino.cc/index.php? PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&topic=175557.msg133320 PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&topic=175557.msg1333209#msg1333209) Reply #3 on: July 28, 2013, 08:47:30 pm Offline Newbie Karma: 0 Posts: 1 i was wondering for what the pin 13 is used for, and if i can change it to other pin, and if you can describe your hardware. Logged

(http://forum.arduino.cc/index.php? PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&action=profile;u=196726)

acturcato (http://forum.arduino.cc/index.php? Re: DECODING HT6P20 WITH attachinterrupt (http://forum.arduino.cc PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&action=profile;u=228116) (http://forum.arduino.cc/index.php? PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&topic=175557.msg153301 PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&topic=175557.msg1533019#msg1533019) Reply #4 on: January 04, 2014, 01:59:51 pm Offline Newbie Karma: 0 Posts: 9

Hi Guys!

(http://forum.arduino.cc/index.php? I developed a sketch based on the nice code above and many others.. PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&action=profile;u=228116) For all "remote controls" that use the encoder HT6P20 I tested, it worked! See the links below: English: http://acturcato.wordpress.com/2014/01/04/decoder-for-ht6p20b-encoder-on-arduino-board-english/ (http://acturcato.wordpress.com/2014/01/04/decoderfor-ht6p20b-encoder-on-arduino-board-english/) Portuguese: http://acturcato.wordpress.com/2013/12/20/decodificador-para-o-encoder-ht6p20b-em-arduino/ (http://acturcato.wordpress.com/2013/12/20/decodificador-para-o-encoder-ht6p20b-em-arduino/) Logged

Pages: [1] Go Up

Print (http://forum.arduino.cc/index.php? PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&action=printpage;topic=175557.0)

previous topic (http://forum.arduino.cc/index.php?PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&topic=175557.0;prev_next=prev#new) next topic (http://forum.arduino.cc/index.php? PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&topic=175557.0;prev_next=next#new) (http://forum.arduino.cc/index.php?PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&) | Arduino Forum (http://forum.arduino.cc/index.php? PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&) :: Using Arduino (http://forum.arduino.cc/index.php?PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&#2) :: Networking, Protocols, and Devices (http://forum.arduino.cc/index.php?PHPSESSID=i29n6l2gfijbq40eutpa5ng0c4&board=11.0) :: DECODING HT6P20 WITH attachinterrupt Jump to:
=> Networking, Protocols, and Devices go

Powered by SMF 1.1.19 (http://www.simplemachines.org/) | SMF 2013, Simple Machines (http://www.simplemachines.org/about/copyright.php)


Ne wsle tte r

Enter your email to sign up

Subscribe

2014 Arduino

Copyright Notice (http://arduino.cc/en/Main/CopyrightNotice)

Contact us (http://arduino.cc/en/Main/ContactUs)

(https://twitter.com/arduino) (http://www.facebook.com/official.arduino) (https://plus.google.com/+Arduino) (http://www.flickr.com/photos/arduino_cc) (http://youtube.com/arduinoteam)

S-ar putea să vă placă și