IperGATE
APRICANCELLO GSM IPERGATE
Controllo remoto GSM bidirezionale, 2 Ingressi ad autoapprendimento + 4 Relè di uscita
Tramite il vostro telefono cellulare è possibile attivare e disattivare, in modo permanente o impulsivo, apparati remoti tramite una chiamata senza costo o inviando un SMS al dispositivo (al numero di telefono della SIM inserita).
Il dispositivo risponde dando conferma dell’evento avvenuto tramite SMS di risposta o RING (squillo) di segnalazione.
IperGATE è stato progettato per un contenitore a montaggio su guida/barra DIN , ma può essere allogiato in qualsiasi contenitore
PRINCIPALI APPLICAZIONI GSM
- Apertura cancelli automatici eliminando il telecomando e senza costi di chiamata: effettuando una chiamata senza costi si attiva l’apertura del cancello.
- Avviso di allarme antifurto domestico, ufficio o automobilistico: il dispositivo Vi chiama in questi casi o invia un SMS.
- Qualsiasi altro tipo di attivazione e controllo domestico: Accensione riscaldamento, innaffiamento, luci, disattivazione allarmi.
- Controllo industriale di attivazione remota e verifica tramite SMS: è possibile avere una chiamata o un SMS in caso di allarme di qualsiasi tipo.
Schema Elettrico Apricancello
Lo schema elettrico può essere suddiviso in 5 blocchi:
Alimentazione
Il circuito accetta in ingresso tensioni di alimentazione in continua o alternata di 9V (AC/DC) oppure 12V solo in continua (DC).
Successivamente i 2 regolatori lineari LM340S ed LM317S forniscono le tensioni stabilizzate necessarie: 5V per il microcontrollore e 3V8 per il modulo GSM Telit GM862.
Microcontrollore
E' stato usato un PIC18F1220 piccolo, economico, ma molto performante. Infatti abbiamo a disposizione internamente, tra le altre periferiche, un oscillatore, il brown-out reset ed il modulo uart per la comunicazione seriale (TXD1/RXD1).
Tramite il connettore J3 è possibile collegare direttamente un ICD2 per la programmazione o il debug.
Ingressi
L'interfaccia di ingresso è stata realizzata con il classico pull-up a positivo ed autoapprendimento dello stato di ingresso. Un cambiamento dallo stato iniziale (chiuso a massa e poi aperto o viceversa) comporterà un allarme.
Il condensatore e la resistenza serie (R3/C3 e R5/C5) fungono da filtro e da limitatore di corrente di ingresso (la R ovviamente)
Uscite
Le uscite sono semplici relè pilotati da transistor. Quindi 4 relè di uscita a doppio scambio (Comune - Normalmente aperto - Normalmente chiuso) del tipo "Cubetto Automotive" in grado di sopportare correnti fino a 10A e tensioni di 250Vac.
GSM
Il blocco di trasmissione/ricesione GSM è costituito dal modulo Telit GM862, alloggiato su connettore Molex da 50 pin. L'adattamento dei livelli di segnale tra modulo Telit e Picmicro e stato realizzato cosi:
Segnali DAL microcontrollore Pic AL modulo GSM Telit --> Resistenza e Zener per abbassare la tensione (R15/DZ1)
Segnali DAL modulo Telit al Picmicro --> E' stato utilizzato il 74HC125 (Buffer quadruplo NON invertente)
Lo schema elettrico in Alta Risoluzione, insieme a tutta la documentazione del progetto, è disponibile nella sezione Download
Lista Parti Apricancello
| Itm |
Qty |
Reference | Part | Package | Description |
Note | CODE Farnell |
| 1 | 3 | C1,C12,C13 | 470uF/16V/EL/F | F | Cap.Electrolytic | 8.3x8.3x10.2 | 9695710 |
| 2 | 10 |
C2,C3,C4,C5,C6,C7, C8,C10,C11,C14 |
100nF | 0805 | Cap.Ceramic | 9406387 | |
| 3 | 1 | C9 | 1000nF | 0805 | Cap.Ceramic | 1301807 | |
| 4 | 1 | DB1 | 1A/200V | DIL smd | Bridge Diode | 7355467 | |
| 5 | 3 | DL1,DL2,DL3 | LED_RED | 0805 | Led Smd | Chatode sign | 8529949 |
| 6 | 1 | DZ1 | 2V7 ZENER | SOD-80C | Diode ZENER | BZV55-C2V7 | 1097194 |
| 7 | 4 | D1,D2,D3,D4 | 1N4148 smd | SMD | Diode | ||
| 8 | 1 | D5 | 12V TRANZORB | SMA | Diode TransientS | SMAJ12A | 9550801 |
| 9 | 1 | J1 | 50 PIN smd | Pitch0.5 | 53916-0508 MOLEX | GM862PCBCONNECT | SILVERSTAR |
| 10 | 1 | J2a | MORSETTIERA 9 | P5.08 | HEADER9 | 224960 | |
| 11 | 1 | J2b | MORSETTIERA 7 | P5.08 | HEADER7 | 109929 | |
| 12 | 5 | Q1,Q2,Q3,Q4,Q5 | BC847 | SOT23 | Transistor NPN | Alternative BC817-MMBT2222 ALT1 | 1081235 |
| 13 | 4 | RL1,RL2,RL3,RL4 | Rele G5LE-1-12V | RELE | Rele cube | Relè automotive type 12V OMRON | |
| 14 | 2 | R2,R4 | 47K/1% | 0805 | Resistor | Alternative 5% | 9333274 |
| 15 | 1 | R19 | 2K2/1% | 0805 | Resistor | Alternative 5% | 9330810 |
| 16 | 1 | R20 | 330/1% | 0805 | Resistor | 9331018 | |
| 17 | 7 | R1,R5,R7,R8,R11,R12 , R17 | 10K/1% | 0805 | Resistor | Alternative 5% | 9330399 |
| 18 | 4 | R15,R16,R18,R21 | 680/1% | 0805 | Resistor | 9333460 | |
| 19 | 2 | R3,R6 | 100K | 0805 | Resistor | ||
| 20 | 1 | U1 | PIC18F1220/SO | SOIC18 | Microcontroller | Soic300mils | |
| 21 | 1 | U2 | SN74HC125D | SOIC14 | Buffer | 74HC125 smd | 9591028 |
| 22 | 1 | U3 | LM340S-5.0 | TO-263 | Regulator 5V | 9494502 | |
| 23 | 1 | U4 | LM317S-ADJ | TO-263 | Regulator ADJ | 9494480 | |
| 24 | 1 | PCB | EMC002 -061103 -1 | FR4 | Circuit Board | Dual Layer 1.6mm Standard | CMT |
| 25 | 1 | GM862-QUAD | Modulo Telit | 50Pin | GSM-GPRS 4-BAND | SILVERSTAR | |
| 26 | 1 | Antenna 900 - 1800 - 1900 | MMCX Connector | Antenna x GM862 |
431333001919PHY (20cm) FMGB35025MR 10cm |
SILVERSTAR | |
| 27 | 4 | Viti autofilettanti | SelfTapping screw | Viti x PCB | M2.9x6.5 Verificare | FARNELL |
|
| 28 | 1 | Case | MR6/C | Case DIN | ELBAG |
Layout Apricancello
Il piano di montaggio evidenzia l'importanza del modulo GSM alloggiato sul connettore J1 con relativi condensatori di filtro sull'alimentazione nelle immediate vicinanza (C1 e C2).
Continuando il "giro" in senso orario, si possono notare i 4 relè (RL1,RL2,RL3,RL4) e la morsettiera J2 che sui pin iniziali riporta gli ingressi di alimentazione. I pin 3 e 4 della suddetta riportano gli ingressi di allarme.
Salendo verso l'alto troviamo i 2 regolatori lineari U3 e U4 con relativa dissipazione termica sullo stesso circuito stampato sfruttando il rame ed i fori passanti. E poi sempre piu in alto il microcontrollore U1 con alla sinistra il connettore J4, realizzato con un doppio passo, connettore Molex per ICD2 da montare in fase di sviluppo e debug e semplice (economica) strip-line per la produzione.
Infine, dulces in fundo, in alto, in neretto, EMCelettronica
Firmware Apricancello
Questa è la prima parte del codice sorgente, scritto in assembler, dell'apricancello GSM.
La parte iniziale comprende le direttive al compilatore e la configurazione dei registri della RAM.
Poi la programmazione nella EEPROM dei comandi AT usati per comandare il modulo GSM.
Finalmente il vettore di RESET, con l'inizio del programma.
Poi la routine di interrupt ISR ed il SETUP.
Infine (per questa prima parte) abbiamo il MAIN ed il MAIN_LOOP
Il tutto è sicuramente ottimizzabile, ma certamente FUNZIONANTE, quindi fatene buon uso!
;****************************************************************************** ; This file is a basic template for assembly code for a PIC18F1220. Copy * ; this file into your project directory and modify or add to it as needed. * ; * ; The PIC18FXXXX architecture allows two interrupt configurations. This * ; template code is written for priority interrupt levels and the IPEN bit * ; in the RCON register must be set to enable priority levels. If IPEN is * ; left in its default zero state, only the interrupt vector at 0x008 will * ; be used and the WREG_TEMP, BSR_TEMP and STATUS_TEMP variables will not * ; be needed. * ; * ; Refer to the MPASM User's Guide for additional information on the * ; features of the assembler. * ; * ; Refer to the PIC18F1220/1320 Data Sheet for additional information on the * ; architecture and instruction set. * ; * ;****************************************************************************** ; * ; Filename: ipergate_V1.asm * ; Date: 2008 * ; File Version: V1 * ; * ; Author: Emanuele Bonanni * ; Company: EMCelettronica Srl * ; * ;****************************************************************************** ; * ; Files required: P18F1220.INC * ; * ;****************************************************************************** LIST P=18F1220 ;directive to define processor #include;processor specific variable definitions ;****************************************************************************** ;Configuration bits CONFIG OSC = INTIO2 , WDT = OFF, LVP = OFF, FSCM = OFF, IESO = OFF, PWRT = ON, BOR = ON, BORV = 27, MCLRE = ON, CP0 = ON, CP1 = ON ;****************************************************************************** ;Variable definitions AUX EQU 0x00 TIM EQU 0x01 ; General Purpose TIM1 EQU 0x02 TIM2 EQU 0x03 ; index SM storage received SMS TIM3 EQU 0x04 ;STATUS_TEMP EQU 0x05 VOLTE1 EQU 0x06 VOLTE EQU 0x07 SMS_INDEX EQU 0x08 ; EQU 0x09 REG EQU 0x0A ;WREG_TEMPEQU 0x0B ;BSR_TEMP EQU 0x0C INGR EQU 0x0D ; Stato ingressi all'accensione AUTOAPPRENDIMENTO ; INGR,1 --> stato iniziale ingresso 1 ; INGR,2 --> stato iniziale ingresso 2 FLAG EQU 0x0E rele1 EQU 0x00 rele2 EQU 0x01 rele3 EQU 0x02 rele4 EQU 0x03 norisp EQU 0x04 ring EQU 0x05 stopfsr EQU 0x06 all EQU 0x07 FLAG2 EQU 0x0F ; SMS impulso EQU 0x00 attivo EQU 0x01 disattivo EQU 0x02 alarm1 EQU 0x03 alarm2 EQU 0x04 ;RAM50 EQU 0x50 ; tel.number SMS rx ; EQU 0x6F ; tel.number max 32 cifre ;************************************************************************ ; Buffer di risposta TELIT RAM80 EQU 0x80 RAM81 EQU 0x81 ; verifica OK ;O RAM82 EQU 0x82 ;K RAM87 EQU 0x87 RAM8A EQU 0x8A RAM8B EQU 0x8B RAM8C EQU 0x8C ;************************************************************************ ;****************************************************************************** #define IN_1 PORTA,4 ; Ingresso_1 #define IN_2 PORTA,1 ; Ingresso_2 #define RELE1 PORTA,2 ; Uscita RELE_1 #define RELE2 PORTA,7 ; Uscita RELE_2 #define RELE3 PORTA,3 ; Uscita RELE_3 #define RELE4 PORTA,6 ; Uscita RELE_4 #define POWER_ON PORTA,0 ; Power on TELIT #define RING_IND PORTB,0 ; Ring indicator TELIT #define PWRCTRL PORTB,2 ; verifica Modulo ON , Power Control _AT_ EQU 0x00 ; AT ;_ATH_ EQU 0x08 ; ATH _ATE_ EQU 0x10 ; ATE=0 _IPR_ EQU 0x20 ; AT+IPR=9600 _CMEE_ EQU 0x30 ; AT+CMEE=1 _CSMP_ EQU 0x40 _CMGF_ EQU 0x54 ; AT+CMGF=1 _CPIN_ EQU 0x60 ; AT+CPIN _CREG_ EQU 0x68 ; AT+CREG _CNMI_ EQU 0x70 ; AT+CNMI=0,0,0,0,0 _FCLASS_ EQU 0x84 ; _CLIP_ EQU 0x90 _CPAS_ EQU 0xA0 _CPBS_ EQU 0xB0 ;****************************************************************************** ;EEPROM data ; Data to be programmed into the Data EEPROM is defined here ; \r = carriage return \n = new line (cr lf) ; usare \r (CR) come verifica di fine stringa!!! ;------------------------------------------------------------------------ ; Attenction command: AT ; Response: OK ;------------------------------------------------------------------------ ORG 0xf00000 DE "AT\r" ;------------------------------------------------------------------------ ; ath OK ; HOOK HANG-UP attacca ;------------------------------------------------------------------------ ; ORG 0xf00008 ; DE "ATH\r" ; ;------------------------------------------------------------------------ ; Disable command echo: ATE=0 ; Response: OK ;------------------------------------------------------------------------ ORG 0xf00010 DE "ATE=0\r" ; ;------------------------------------------------------------------------ ; Fix baude rate: AT+IPR=9600 ; Response: OK ;------------------------------------------------------------------------ ORG 0xf00020 DE "AT+IPR=9600\r" ;------------------------------------------------------------------------ ; Enable extended error code: AT+CMEE=1 ; Response: OK ;------------------------------------------------------------------------ ORG 0xf00030 DE "AT+CMEE=1\r" ;------------------------------------------------------------------------ ; ; ;------------------------------------------------------------------------ ORG 0xf00040 DE "AT+CSMP=17,167,0,0\r" ;------------------------------------------------------------------------ ; SMS format type: AT+CMGF=1 ; Response: OK ;------------------------------------------------------------------------ ORG 0xf00054 DE "AT+CMGF=1\r" ;------------------------------------------------------------------------ ; SIM presence checking: AT+CPIN ; Response: +CPIN: READY OK ;------------------------------------------------------------------------ ORG 0xf00060 DE "AT+CPIN\r" ;------------------------------------------------------------------------ ; Network checking: AT+CREG ; Response: +CREG: 0,1 OK ;------------------------------------------------------------------------ ORG 0xf00068 DE "AT+CREG\r" ;------------------------------------------------------------------------ ; New message unsolecited indicaiton: AT+CNMI=0,0,0,0,0 ; Response: OK ;------------------------------------------------------------------------ ORG 0xf00070 DE "AT+CNMI=0,0,0,0,0\r" ;------------------------------------------------------------------------ ; ; ;------------------------------------------------------------------------ ORG 0xf00084 DE "AT+FCLASS=8\r" ;------------------------------------------------------------------------ ; ; ;------------------------------------------------------------------------ ORG 0xf00090 DE "AT+CLIP=1\r" ;------------------------------------------------------------------------ ; ; ;------------------------------------------------------------------------ ORG 0xf000A0 DE "AT+CPAS?\r" ;------------------------------------------------------------------------ ; ; ;------------------------------------------------------------------------ ORG 0xf000B0 DE "AT+CPBS=\"SM\"\r" ;****************************************************************************** ;Reset vector ; This code will start executing when a reset occurs. ORG 0x0000 ; processor reset vector movlw B'01101111' movwf OSCCON goto Setup ; go to beginning of program ;****************************************************************************** ;High priority interrupt vector ; This code will start executing when a high priority interrupt occurs or ; when any interrupt occurs if interrupt priorities are not enabled. ORG 0x0008 btfss PIR1,RCIF ; Interrupt USART flag bit? goto isrout ; no! bcf PIR1,RCIF ; yes, clear and go ahead goto ISR_routine ;****************************************************************************** ;Low priority interrupt vector and routine ORG 0x0018 retfie FAST ;****************************************************************************** ISR_routine: ; isr_routine RX serial_Data >> INDF0 (FSR) movf RCREG,w ; Scarica RCREG btfsc FLAG,stopfsr ; Incrementare FSR ? goto isrout ; NO! movf FSR0L,w ;\\ xorlw 0xF1 ; if FSR == 0xF1 BNZ isr1 ; then FSR == 0XF0 decf FSR0L isr1: movf RCREG,w xorlw 0x20;! ; elimina gli spazi dalla rx BZ isrout movf RCREG,w xorlw 0x0A;! ; elimina i ritorni a capo dalla rx BZ isrout movff RCREG,INDF0 ; Carica INDF0 con RCREG incf FSR0L,f ; Incrementa FSR isrout: retfie FAST ;****************************************************************************** ;****************************************************************************** Setup: clrf BSR clrf FSR0H clrf FSR0L clrf PORTA clrf PORTB clrf LATB setf ADCON1 movlw B'00010010' ; RA7 RA6 RA5 RA4 RA3 RA2 RA1 RA0 movwf TRISA ; RELE2 RELE4 MCLR IN_1 RELE3 RELE1 IN_2 POWER_ON movlw B'11110111' ; RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 movwf TRISB ; RXD GPLED PWRCTRL TXD RING_IND clrf ADCON0 ; config isr clrf INTCON2 ; PortB pullup-on clrf INTCON3 clrf PIE1 clrf PIE2 clrf PIR1 clrf PIR2 clrf IPR1 ; all low priority clrf IPR2 ; all low priority clrf RCON ;------------------------------------------------------------------------ call clear_ram ; clear ram call set_baude_rate ; 9600 N 8 1 + enable uart_ISR movlw b'11000000' ; set GIE,PEIE movwf INTCON ;-------------------------------------------autoadetect IN_1 & IN_2 bcf INGR,1 ; INGR,1=stato iniz. btfsc IN_1 ; ingresso_1 bsf INGR,1 bcf INGR,2 ; INGR,2=stato iniz.; btfsc IN_2 ; ingresso_2 bsf INGR,2 ;------------------------------------------------------------------------ setup1: call t3s ; Stabilize power supply ;----------------------------------------------------activate Modulo TELIT btfsc PWRCTRL ; modulo on? goto setup1_1 ; SI! go ahead bsf POWER_ON ; Power_on / off call t2s ; 2 Seconds Pulse bcf POWER_ON goto setup1 ; verify if ON ;------------------------------------------------------------------------ setup1_1: call t3s ; Stabilize on/off bcf FLAG,stopfsr ; Enable ISR --> FSR inc btfsc RCSTA,OERR ; check uart overrun call uart_overrun ; restore movlw _AT_ call ee_at ; at_command movlw _IPR_ call ee_at ; fix port rate @ 9600 movlw _ATE_ call ee_at ; Disable command echo movlw _CLIP_ call ee_at ; Enable calling line identification call check_ok ; verify OK btfss STATUS,Z ; Z=1 OK goto setup1 ; error --> no_ok off/on modulo! movlw _CMEE_ call ee_at ; Enable extended error code =1 numeric movlw _CPIN_ call ee_at ; SIM presence checking (PIN free) READY movlw _CREG_ call ee_at ; Network checking x,1 (home) or x,5 (roaming) movlw _CMGF_ call ee_at ; SMS format type 1=text movlw _CNMI_ call ee_at ; DISABLE New message unsolecited indication +CMTI: movlw _FCLASS_ call ee_at ; AT+FCLASS=8 Attiva Voice mode movlw _CSMP_ call ee_at ; 17,167,0,0 call check_ok ; verify OK BNZ setup1 ; error --> no_ok spegni e riaccendi il modulo! ; fare un contatore per setup2 e setup3 se dopo 30-60 secondi ; la SIM è ancora occupata, telit off setup2: movlw _CPBS_ call ee_at ; AT+CPBS="SM" setta phonebook normal SIM call check_ok ; verify OK BNZ setup2 ; error --> no_ok loop setup3: movlw '0' movwf VOLTE1 movlw '1' movwf VOLTE call clear_ram80 call _cpbr ; AT+CPBR=1 read phonebook position 1 only for setup SIM call t1s ; 1+1 second? --- Basta leggere SIM 1 per setup??? movf RAM8A,w xorlw ':' BNZ setup4 ; SIM not busy movf RAM8B,w xorlw '1' BNZ setup4 ; SIM not busy movf RAM8C,w xorlw '4' BZ setup3 ; SIM busy retry setup4: ; SIM not busy movlw '1' movwf SMS_INDEX ; in questo caso SMindex ininfluente call clear_ram80 bsf FLAG,all ; delete all message ,4 SMindex don't care call _cmgd ; delete sms bcf FLAG,all call t2s call clear_ram80 ; cancella ram 80 ;************************************************************************ main: call t1s bcf FLAG,stopfsr; attiva FSR inc sotto ISR movlw '0' ; preset SMS_INDEX for SMS READ SM 1-2-3 movwf SMS_INDEX main_loop: btfsc RCSTA,OERR ; check uart overrun call uart_overrun; restore btfss RING_IND ; Ring Indicator goto wait_ring ; RING IN PROGRESS! incf SMS_INDEX ; Read next SMS movlw 0x80 ; Set FSR movwf FSR0L call _cmgr ; at+cmgr= (read sms) SMS_INDEX = bsf FLAG,stopfsr; blocca FSR inc sotto ISR call cmserror ; qui verificare +CMSERROR:321 quindi no sms btfss STATUS,Z goto main2 ; Z=0 NON ricevuto +CMSERROR --> Cosa ho ricevuto? ; Z=1 ricevuto +CMSERROR quindi no sms ma OK bcf FLAG,stopfsr; attiva FSR inc sotto ISR movf SMS_INDEX,w ; se SMS_INDEX = '3' xorlw '3' BNZ main_loop ; MAIN_LOOP call statoz ; CONTROLLA STATO ZONE BNZ alarmz ; Z=0 alarm zone ; Z=1 ok goto main ; TORNA AL MAIN main2: call checkcmgr ; qui verificare +CMGR:..... quindi sms btfss STATUS,Z goto setup1 ; Z=0 NON ho ricevuto ne +CMSERROR ne +CMGR: ; Z=1 Ricevuto +CMGR goto wait_sms ; SMS! ricevuto +CMGR quindi SMS ;************************************************************************
Il progetto IPERGATE è disponibile a questa pagina, quindi potete realizzarlo da soli (fai-da-te) oppure potete scaricare tutti i codici sorgenti (Schema elettrico realizzato con Orcad, lista parti, circuito stampato realizzato con Orcad, file gerber, codice sorgente assembler realizzato su piattaforma Microchip) a questo link (apricancello gsm)
- blog di Emanuele
- 132362 letture






Invia nuovo commento