Ma ktoś kod jak skonfigurować timer do pomiaru częstotliwości (to chyba w trybie PWC) oraz konfigurację do pomiaru PWM .
Resztę sobie dopiszę ale trzeba mi tych konfiguracji timerów.
Timer mierzenie częstotliwości (PWC)
- tomaszdko
- Posty: 78
- Rejestracja: 06 gru 2018, 19:58
- tomaszdko
- Posty: 78
- Rejestracja: 06 gru 2018, 19:58
Re: Timer mierzenie częstotliwości (PWC)
Mój sposób na mierzenie długości impulsu chodzi ale jednak przydał by się w pełni sprzętowy na timerze . Ten kod używa timera ale też przerwań na pinie .
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $REGFILE = "XM128A3UDEF.DAT"
- $CRYSTAL = 50000000 '50MHz
- $HWSTACK = 500
- $SWSTACK = 500
- $FRAMESIZE = 500
- $LIB "XMEGA.LIB"
- ENABLE INTERRUPTS
- '-------------------------------------------------------------------------------------------------------------------------------------------
- 'CONFIG OSC = ENABLED , PLLOSC = ENABLED , PLLMUL = 29
- 'CONFIG SYSCLOCK = PLL
- '-------------------------------------------------------------------------------------------------------------------------------------------
- CONFIG OSC = ENABLED , EXTOSC = ENABLED , PLLOSC = ENABLED , _
- RANGE = 9MHZ_12MHZ , STARTUP = XTAL_16KCLK , PLLSOURCE = EXTCLOCK , PLLMUL = 5 '5 X 10MHZ = 50MHZ
- CONFIG SYSCLOCK = PLL , PRESCALEA = 1 , PRESCALEBC = 1_1
- CONFIG PRIORITY = STATIC , VECTOR = APPLICATION , HI = ENABLED , MED = ENABLED , LO = ENABLED
- '*******************************************************************************************************************************************
- '*** UART-COM5 *****************************************************************************************************************************
- '*******************************************************************************************************************************************
- CONFIG COM5 = 115200 , MODE = ASYNCHRONEOUS , PARITY = NONE , STOPBITS = 1 , DATABITS = 8
- OPEN "COM5:" FOR BINARY AS #5
- CONFIG SERIALIN4 = BUFFERED , SIZE = 30 , BYTEMATCH = 13
- ENABLE USARTe0_RXC, LO
- DIM RS232_5 AS STRING * 20
- DIM COM5 AS LONG
- '*******************************************************************************************************************************************
- '*** LCD 240x320 ILI9341 *******************************************************************************************************************
- '*******************************************************************************************************************************************
- CONFIG VPORT0 = E 'NIE TRZEBA PODLACZYC/DODACNA "-" Cs1=CS) Rst=RESET A0=DC Si=SDI Sclk=SCK
- CONFIG GRAPHLCD = COLOR , CS1 = PORT0.0 , RST = PORT0.6 , A0 = PORT0.5 , SI = PORT0.4 , SCLK = PORT0.7
- CONST PORTRAIT=0
- CONST ROTATE_180 = 1
- DIM OFFSET256 AS BYTE
- $LIB "glcd-ILI9341_2R8_240x320.lib"
- INITLCD
- CLS
- CONST BLACK = &B0000_0000
- CONST RED = &B1110_0000
- CONST GREEN = &B0001_1100
- CONST BLUE = &B0000_0011
- CONST MAGENTA = &B1110_0011
- CONST YELLOW = &B1111_1100
- CONST CYAN = &B0001_1111
- CONST WHITE = &B1111_1111
- CONST ORANGE = &B1111_0100
- CONST BRIGHTGREEN = &B0011_1110
- CONST BRIGHTBLUE = &B0001_1111
- CONST DARKRED = &B1100_0000
- CONST DARKGREEN = &B0001_0100
- CONST DARKBLUE = &B0000_0010
- OFFSET256 = 1
- BOXFILL (0 , 0) - (64 , 240) , BLACK
- OFFSET256 = 0
- BOXFILL (0 , 0) - (255 , 240) , BLACK
- SETFONT COLOR8X8
- 'SETFONT COLOR16X16
- '*******************************************************************************************************************************************
- '*** PIN / PORT ****************************************************************************************************************************
- '*******************************************************************************************************************************************
- CONFIG portC.0=INPUT : CONFIG XPIN = PortC.0 , OUTPULL = PULLUP , SENSE = BOTH
- PORTC_INT0MASK = &B0000_0001 'przerwanie dla pinu 0
- ON PORTC_INT0 PRZERWANIE_PINC0
- ENABLE PORTC_INT0 , LO
- '*******************************************************************************************************************************************
- '*** TCc0 OVF ******************************************************************************************************************************
- '*******************************************************************************************************************************************
- CONFIG TCC0 = NORMAL , PRESCALE = 1 ' 1 , 2, 4, 8, 64, 256, 1024
- TCC0_PER = 65535
- STOP TCC0
- '*******************************************************************************************************************************************
- '*** ZMIENNE *******************************************************************************************************************************
- '*******************************************************************************************************************************************
- DIM XX AS WORD
- '*******************************************************************************************************************************************
- '*** PROGRAM *******************************************************************************************************************************
- '*******************************************************************************************************************************************
- DO
- LCDAT 0 ,0 , "XX :" ; XX ;" " , WHITE, BLACK
- LOOP
- END
- '-------------------------------------------------------------------------------------------------------------------------------------------
- '$INCLUDE "COLOR16x16.FONT"
- $INCLUDE "COLOR8x8.FONT"
- '-------------------------------------------------------------------------------------------------------------------------------------------
- SERIAL4CHARMATCH:
- PUSHALL
- INPUT #5 , RS232_5 NOECHO
- COM5 = VAL(RS232_5)
- POPALL
- RETURN
- '-------------------------------------------------------------------------------------------------------------------------------------------
- PRZERWANIE_PINC0:
- IF PINC.0 = 1 THEN
- START TCC0
- END IF
- IF PINC.0 = 0 THEN
- STOP TCC0
- XX = TCC0_CNT
- TCC0_CNT = 0
- END IF
- RETURN