Projekt: Lirc-Transmitter mit PIC10F20x

Im Unterforum Microcontroller - Beschreibung: Hardware - Software - Ideen - Projekte

Elektronik Forum Nicht eingeloggt       Einloggen       Registrieren




[Registrieren]      --     [FAQ]      --     [ Einen Link auf Ihrer Homepage zum Forum]      --     [ Themen kostenlos per RSS in ihre Homepage einbauen]      --     [Einloggen]

Suchen


Serverzeit: 20 4 2024  15:55:51      TV   VCR Aufnahme   TFT   CRT-Monitor   Netzteile   LED-FAQ   Osziloskop-Schirmbilder            


Elektronik- und Elektroforum Forum Index   >>   Microcontroller        Microcontroller : Hardware - Software - Ideen - Projekte


Autor
Projekt: Lirc-Transmitter mit PIC10F20x

    







BID = 740181

Bartholomew

Inventar



Beiträge: 4681
 

  


Hoi,

Habe ein Programm für den PIC10F200/PIC10F202/PIC10F204/PIC10F206 geschrieben, dass aus dem Chip einen sicheren 36kHz-Oszillator mit 25% Dutycycle macht (ideal für RC-5). Damit kann man, in Verwendung mit LIRC, die IR-LED(s) mit relaitv hohen Strömen pulsen, ohne Angst zu haben, dass die LED gegrillt wird, wenn der serielle Port mal nicht das macht, was er soll, und die LED eingeschaltet lässt. Außerdem wird der UART entlastet, weil er den Träger nicht mehr übermitteln muss (die Trägerwellengenerierung übernimmt der PIC).
Der 10F206 ist als DIP billig bei Reichelt zu bekommen (64ct, die kleineren Brüder sind auch nicht billiger, man sollte sich also eigentlich nur 206er kaufen) und verfügt über einen auf +-1% stabilen internen 4MHz-Takt. Die Trägerfrequemz ist standardmäßig per zweifach-Mäuseklavier zwischen 4 Werten umschaltbar: 34,5kHz, 35,7kHz, 37kHz, 38,5kHz. Die üblichen Empfänger-ICs (TSOP17xx, SFH5110-xx) bekommen ein Signal mit +-2kHz Abweichung vom Nennträger noch ganz passabel empfangen (etwa 90% Signalstärke), also sollte der Transmitter auf jeden Fall gut empfangen werden können.

Im Anhang der Quellcode. Habe den Code leider noch nicht in Hardware getestet, da ich gerade keine 10F20x-Testplatine zur Hand habe.
Würde mich über Kritik zum Programmierstil freuen.
Ist mein zweites größeres selbstgeschriebenes Programm, das erste läuft auf einer 16F628-Testplatine und kann LEDs im Multiplex mit verschiedenen Helligkeitsstufen ansteuern (wird als nächstes ausgebaut).

Ich habe im ASM die Standard-MPLAB-Tabulatorbreite von 4 Leerzeichenbreiten benutzt, die Forensoftware (oder vielmehr mein Browser?) verwendet leider 8 Zeichenbreiten. Zur besseren Lesbarkeit also evtl. den Code in einen Texteditor mit einstellbarer Tabulatorbreite kopieren.


Gruß, Bartho




Code :

;**********************************************************************

; This file is a basic code template for assembly code generation *
; on the PIC10F206. This file contains the basic code *
; building blocks to build upon. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: LIRC-Transmitter.asm *
; Date: 11.01.2011 *
; File Version: V0.1 *
; *
; Author: Bartholomew *
; Company: *
; *
; *
;**********************************************************************
; *
; Files Required: P10F206.INC *
; *
;**********************************************************************
; *
; Notes: This code is "open source" and is released *
; under the GPL. *
; The code wasn't testet in hardware yet! *
; This code ist written for the 10F206, but *
; should also work on 10F200/10F202/10F204. *
; *
;**********************************************************************
;
;######################################################################
;Circuit schematic:
; [PGIO,0]---[switch1]---[GND] PWM frequency setting DIP switch 1
; [PGIO,1]---[switch2]---[GND] PWM frequency setting DIP switch 2
; [PGIO,2]---[OUTPUT] controlls LED, high=on
; [PGIO,3]---[ R ]---[INPUT] connect to sending Pin of RS-232
;######################################################################


list p=10F206 ; list directive to define processor
#include <p10F206.inc> ; processor specific variable definitions

__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.


;***** VARIABLE DEFINITIONS
#define max_count .70 ;max_count+1 = maximal pulses for the LED
;before input has to go low again
;(this protects the LED from overheating
;if input stays accidentially high)
;
;RC-5 will normally use max. 2*32 pulses/carrier peaks in
;a row, so .70 is a good max_count value.

;temp EQU 0x08 ;example variable definition
;start here for backwards-compatibility to 10F200/10F204
count EQU 0x10 ;pulse counter for LED overheat protection
delay_on EQU 0x11 ;set additional ontime-delay for PWM frequency
delay_off EQU 0x12 ;set additional offtime-delay for PWM frequency

;**********************************************************************
ORG 0x1FF ; processor reset vector

; Internal RC calibration value is placed at location 0x1FF by Microchip
; as a movlw k, where the k is a literal value.

ORG 0x000 ; coding begins here
movwf OSCCAL ; update register with factory cal value
;important note: 0x1FF must contain valid calibration data
;(especially with '0' als LSB/FOSC4), else frequency will be wrong
;and gpio,2 won't work as output!
movlw b'10011111' ;enable pull-ups, T0CS int. (allows GPIO,2 to work as output)
OPTION ;/
bcf CMCON0,CMPON ;disable Comparator (disable for use with 10F200/10F202)
bcf GPIO,2 ;set GPIO,2 low
movlw B'00001011' ;set GPIO,2 out
TRIS GPIO
clrf count ;init pulse counter

;####################
;PWM calculation
;
;TSOP17xx receiver vary up to +-5% from their nominal value and have pretty good
;signal detection +-2kHz from that value, so the PWM frequency of the transmitter
;is not that critical.
;SFH5110 arent't that picky, too.
;Here's a table that shows frequency and pulse width for a 25%-PWM
;(good for RC-5):
;
; >=25% <=75%
; kHz on off total DIP- DIP- GPIO GPIO
; cycl. cycl. cycl. sw1 sw2 0 1
; ------------------------------------------------------------
; 40 7 18 25
; 38.5 7 19 26 1 1 0 0
; 37 7 20 27 1 0 0 1
; 35.7 7 21 28 0 1 1 0
; 34.5 8 21 29 0 0 1 1
; 33.3 8 22 30
;
;On the right side are the standard DIP switch values in this code.
;You may alter them to your needs, but most receivers should work just fine.
;The delay_on/off value defines how many NOPs are skipped in the waiting code
;(just look at the waiting code in the main routine).
;
;The recommended value for RC-5 ist 7us on, 21us off. So set
;DIPswitch1 to 0 and DIPswitch2 to 1 for initial testing.
;
;set PWM
btfsc GPIO,0
goto PWM1x
btfsc GPIO,1
goto PWM01
;PWM00
movlw .1 ; 8-1= 7
movwf delay_on
movlw .3 ;22-3=19
movwf delay_off
goto main
PWM01
movlw .1 ; 8-1= 7
movwf delay_on
movlw .2 ;22-2=20
movwf delay_off
goto main
PWM1x
btfsc GPIO,1
goto PWM11
;PWM10
movlw .1 ; 8-1= 7
movwf delay_on
movlw .1 ;22-1=21
movwf delay_off
goto main
PWM11
movlw .0 ; 8-0= 8
movwf delay_on
movlw .1 ;22-1=21
movwf delay_off
;####################

main
btfss GPIO,3 ;if input=low, reset pulse counter
clrf count ;/
waitforaction
btfss GPIO,3 ;as long as input=low, wait
goto waitforaction ;/

movlw max_count ;check if counter>max_count (sets carry bit);
subwf count,w ;if so, don't turn on LED again,
btfsc STATUS,C ;go back and wait for input=low
goto main

bsf GPIO,2 ;set LED on
incf count,f ;increase pulse counter
movf delay_on,w ;wait the right time (7-8 cycles total),
addwf PCL,f ;skip the right amount of NOPs (0-1);
;modifying PCL needs 2 cycles
nop
nop

bcf GPIO,2 ;set LED off
movf delay_off,w ;wait the right time (19-21 cycles total),
addwf PCL,f ;skip the right amount of NOPs (1-3);
;modifying PCL needs 2 cycles
nop
nop
nop
nop
nop
nop

goto main

END ; directive 'end of program'




Nachtrag:
Wenn ich per addwf den PCL verändere, braucht der Befehl dann 1 oder 2 Zyklen? Bin mir da nicht mehr ganz sicher.

[ Diese Nachricht wurde geändert von: Bartholomew am 11 Jan 2011 21:43 ]

BID = 740243

Bartholomew

Inventar



Beiträge: 4681

 

  

Habe die Stopwatch-Funktion des Simulators für mich entdeckt und weiß nun: Änderung des PCL per addwf braucht zwei Zyklen.
Hier Version 0.11 vom Code. Die länge derWarteschleifen waren fehlerhaft und wurden berichtigt.
Außerdem habe ich die maximal erlaubte Pulsanzahl (max_count) bei Dauer-Ein etwas erhöht, damit es auch zuverlässig mit 40kHz funktioniert.

Gruß, Bartho



Code :

;**********************************************************************

; This file is a basic code template for assembly code generation *
; on the PIC10F206. This file contains the basic code *
; building blocks to build upon. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: LIRC-Transmitter.asm *
; Date: 11.01.2011 *
; File Version: V0.11 *
; *
; Author: Bartholomew *
; Company: *
; *
; *
;**********************************************************************
; *
; Files Required: P10F206.INC *
; *
;**********************************************************************
; *
; Notes: This code is "open source" and is released *
; under the GPL. *
; The code wasn't testet in hardware yet! *
; This code ist written for the 10F206, but *
; should also work on 10F200/10F202/10F204. *
; *
;**********************************************************************
;
;######################################################################
;Circuit schematic:
; [PGIO,0]---[switch1]---[GND] PWM frequency setting DIP switch 1
; [PGIO,1]---[switch2]---[GND] PWM frequency setting DIP switch 2
; [PGIO,2]---[OUTPUT] controlls LED, high=on
; [PGIO,3]---[ R ]---[INPUT] connect to sending Pin of RS-232
;######################################################################


list p=10F206 ; list directive to define processor
#include <p10F206.inc> ; processor specific variable definitions

__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.


;***** VARIABLE DEFINITIONS
#define max_count .74 ;max_count = maximal pulses for the LED
;before input has to go low again
;(this protects the LED from overheating
;if input stays accidentially high)
;
;RC-5 will use max. 2*32 pulses/carrier peaks @36kHz
;and 2*36 pulses @40kHz in a row, so .74 is a
;good max_count value.

;temp EQU 0x08 ;example variable definition
;start here for backwards-compatibility to 10F200/10F204
count EQU 0x10 ;pulse counter for LED overheat protection
delay_on EQU 0x11 ;set additional ontime-delay for PWM frequency
delay_off EQU 0x12 ;set additional offtime-delay for PWM frequency

;**********************************************************************
ORG 0x1FF ; processor reset vector

; Internal RC calibration value is placed at location 0x1FF by Microchip
; as a movlw k, where the k is a literal value.

ORG 0x000 ; coding begins here
movwf OSCCAL ; update register with factory cal value
;important note: 0x1FF must contain valid calibration data
;(especially with '0' als LSB/FOSC4), else frequency will be wrong
;and gpio,2 won't work as output!
movlw b'10011111' ;enable pull-ups, T0CS int. (allows GPIO,2 to work as output)
OPTION ;/
bcf CMCON0,CMPON ;disable Comparator (disable for use with 10F200/10F202)
bcf GPIO,2 ;set GPIO,2 low
movlw B'00001011' ;set GPIO,2 out
TRIS GPIO
clrf count ;init pulse counter

;####################
;PWM calculation
;
;TSOP17xx receiver vary up to +-5% from their nominal value and have pretty good
;signal detection +-2kHz from that value, so the PWM frequency of the transmitter
;is not that critical.
;SFH5110 arent't that picky, too.
;Here's a table that shows frequency and pulse width for a 25%-PWM
;(good for RC-5):
;
; >=25% <=75%
; kHz on off total DIP- DIP- GPIO GPIO
; cycl. cycl. cycl. sw1 sw2 0 1
; ------------------------------------------------------------
; 40 7 18 25
; 38.5 7 19 26 1 1 0 0
; 37 7 20 27 1 0 0 1
; 35.7 7 21 28 0 1 1 0
; 34.5 8 21 29 0 0 1 1
; 33.3 8 22 30
;
;On the right side are the standard DIP switch values in this code.
;You may alter them to your needs, but most receivers should work just fine.
;The delay_on/off value defines how many NOPs are skipped in the waiting code
;(just look at the waiting code in the main routine).
;
;The recommended value for RC-5 ist 7us on, 21us off. So set
;DIPswitch1 to 0 and DIPswitch2 to 1 for initial testing.
;
;set PWM
btfsc GPIO,0
goto PWM1x
btfsc GPIO,1
goto PWM01
;PWM00
movlw .1 ; 8-1= 7
movwf delay_on
movlw .3 ;22-3=19
movwf delay_off
goto main
PWM01
movlw .1 ; 8-1= 7
movwf delay_on
movlw .2 ;22-2=20
movwf delay_off
goto main
PWM1x
btfsc GPIO,1
goto PWM11
;PWM10
movlw .1 ; 8-1= 7
movwf delay_on
movlw .1 ;22-1=21
movwf delay_off
goto main
PWM11
movlw .0 ; 8-0= 8
movwf delay_on
movlw .1 ;22-1=21
movwf delay_off
;####################

main
btfss GPIO,3 ;if input=low, reset pulse counter
clrf count ;/

waitforaction
btfss GPIO,3 ;as long as input=low, wait
goto waitforaction ;/

movlw max_count ;check if counter>max_count (sets carry bit);
subwf count,w ;if so, don't turn on LED again,
btfsc STATUS,C ;go back and wait for input=low
goto main

bsf GPIO,2 ;set LED on
incf count,f ;increase pulse counter
movf delay_on,w ;wait the right time (7-8 cycles total),
addwf PCL,f ;skip the right amount of NOPs (0-1);
;modifying PCL needs 2 cycles
nop
nop
nop

bcf GPIO,2 ;set LED off
movf delay_off,w ;wait the right time (19-21 cycles total),
addwf PCL,f ;skip the right amount of NOPs (1-3);
;modifying PCL needs 2 cycles
nop
nop
nop
nop
nop
nop
nop
nop

goto main

END ; directive 'end of program'



[ Diese Nachricht wurde geändert von: Bartholomew am 12 Jan 2011  0:06 ]

BID = 740261

Bartholomew

Inventar



Beiträge: 4681

Habe den Code erfolgreich auf die 16F628-Testplatine portiert. Der PIC tut, was er soll.
Einzig der Takt ist etwas langsamer als erwartet, aber der 628 hat ja auch keinen Korrekturwert für den internen Takterzeuger wie der 10F200 (der gar keinen Anschluss für eine externe Taktquelle hat).

Code ist angehängt.


Gruß, Bartho



Code :

;**********************************************************************

; This file is a basic code template for assembly code generation *
; on the PIC16F628A. This file contains the basic code *
; building blocks to build upon. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files Required: P16F628A.INC *
; *
;**********************************************************************
; *
; Notes: *
; *
;**********************************************************************
;
; Pinbelegung
;
; +\- RA3 RA4
; RB1 grün rot1
; RB0 gelb rot2
;
; [RB3/CCP1]---[LED]---[270 Ohm]---[VCC]
; [RA1]---(Poti 0-5V)
;
;
;**************************************************************

list p=16f628A ; list directive to define processor
#include <p16F628A.inc> ; processor specific variable definitions

errorlevel -302 ; suppress message 302 from list file

__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.

;***** CONSTANT DEFINITIONS
#define max_count .74 ;max_count = maximal pulses for the LED
;before input has to go low again
;(this protects the LED from overheating
;if input stays accidentially high)
;
;RC-5 will use max. 2*32 pulses/carrier peaks @36kHz
;and 2*36 pulses @40kHz in a row, so .74 is a
;good max_count value.

;***** VARIABLE DEFINITIONS
w_temp EQU 0x7E ; variable used for context saving
status_temp EQU 0x7F ; variable used for context saving

cblock H'20'
count ;pulse counter for LED overheat protection
delay_on ;set additional ontime-delay for PWM frequency
delay_off ;set additional offtime-delay for PWM frequency
endc

;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program


ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register

; isr code can go here or be located as a call subroutine elsewhere


movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt

main
; remaining code goes here
bsf CMCON,CM0
bsf CMCON,CM1
bsf CMCON,CM2
bsf PORTB,3 ;LED aus
banksel TRISB
bcf TRISB,3 ;LED Output
banksel PORTB
clrf count ;init pulse counter

;####################
;PWM calculation
;
;TSOP17xx receiver vary up to +-5% from their nominal value and have pretty good
;signal detection +-2kHz from that value, so the PWM frequency of the transmitter
;is not that critical.
;SFH5110 arent't that picky, too.
;Here's a table that shows frequency and pulse width for a 25%-PWM
;(good for RC-5):
;
; >=25% <=75%
; kHz on off total
; cycl. cycl. cycl.
; ------------------------------
; 40 7 18 25
; 38.5 7 19 26
; 37 7 20 27
; 35.7 7 21 28
; 34.5 8 21 29
; 33.3 8 22 30
;
;On the right side are the standard DIP switch values in this code.
;You may alter them to your needs, but most receivers should work just fine.
;The delay_on/off value defines how many NOPs are skipped in the waiting code
;(just look at the waiting code in the main routine).
;
;The recommended value for RC-5 ist 7us on, 21us off.
;
;set PWM
movlw .1 ; 8-1= 7
movwf delay_on
movlw .1 ;22-1=21
movwf delay_off

mainloop
btfss PORTA,1 ;if input=low, reset pulse counter
clrf count ;/

waitforaction
btfss PORTA,1 ;as long as input=low, wait
goto waitforaction ;/

movlw max_count ;check if counter>max_count (sets carry bit);
subwf count,w ;if so, don't turn on LED again,
btfsc STATUS,C ;go back and wait for input=low
goto mainloop

bcf PORTB,3 ;set LED on
incf count,f ;increase pulse counter
movf delay_on,w ;wait the right time (7-8 cycles total),
addwf PCL,f ;skip the right amount of NOPs (0-1);
;modifying PCL needs 2 cycles
nop
nop
nop

bsf PORTB,3 ;set LED off
movf delay_off,w ;wait the right time (19-21 cycles total),
addwf PCL,f ;skip the right amount of NOPs (1-3);
;modifying PCL needs 2 cycles
nop
nop
nop
nop
nop
nop
nop
nop

goto mainloop ;loop forever, remove this instruction, for test only

; initialize eeprom locations
; ORG 0x2100
; DE 0x00, 0x01, 0x02, 0x03

END ; directive 'end of program'



[ Diese Nachricht wurde geändert von: Bartholomew am 12 Jan 2011  2:06 ]

BID = 740265

perl

Ehrenmitglied



Beiträge: 11110,1
Wohnort: Rheinbach


Zitat :
Würde mich über Kritik zum Programmierstil freuen.
Soetwas
Zitat :

; initialize eeprom locations

; ORG 0x2100

; DE 0x00, 0x01, 0x02, 0x03


haut mich nicht gerade vom Hocker.
Ich finde auch keinerlei Information im Programm was es macht, und demnach natürlich auch nicht, wie es das macht.


BID = 740306

Bartholomew

Inventar



Beiträge: 4681

Genau das dachte ich mir auch, als ich diesen Code in der mitgelieferten 16F628A-Skelettdatei von MPLAB fand
Ich habe ihn vorerst nur auskommentiert, statt ihn ganz zu löschen.
Die (hier unnütze) Standard-Interruptserviceroutine ist auch noch drin. Ist ja "bloß" der Code für die Experimentierplatine.


Gruß, Bartho


Zurück zur Seite 0 im Unterforum          Vorheriges Thema Nächstes Thema 


Zum Ersatzteileshop


Bezeichnungen von Produkten, Abbildungen und Logos , die in diesem Forum oder im Shop verwendet werden, sind Eigentum des entsprechenden Herstellers oder Besitzers. Diese dienen lediglich zur Identifikation!
Impressum       Datenschutz       Copyright © Baldur Brock Fernsehtechnik und Versand Ersatzteile in Heilbronn Deutschland       

gerechnet auf die letzten 30 Tage haben wir 24 Beiträge im Durchschnitt pro Tag       heute wurden bisher 7 Beiträge verfasst
© x sparkkelsputz        Besucher : 180937744   Heute : 5086    Gestern : 9165    Online : 462        20.4.2024    15:55
10 Besucher in den letzten 60 Sekunden        alle 6.00 Sekunden ein neuer Besucher ---- logout ----viewtopic ---- logout ----
xcvb ycvb
0.0275869369507