Timer mierzenie częstotliwości (PWC)

Rodzina procesorów bogatszych w wiele nowych rozwiązań i dlatego warto po nie sięgnąć.
ODPOWIEDZ
Awatar użytkownika
tomaszdko
Posty: 78
Rejestracja: 06 gru 2018, 19:58

Timer mierzenie częstotliwości (PWC)

Post autor: tomaszdko » 14 lut 2024, 10:28

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.
Awatar użytkownika
tomaszdko
Posty: 78
Rejestracja: 06 gru 2018, 19:58

Re: Timer mierzenie częstotliwości (PWC)

Post autor: tomaszdko » 14 lut 2024, 22:19

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 .
  1. $REGFILE = "XM128A3UDEF.DAT"
  2. $CRYSTAL = 50000000   '50MHz
  3. $HWSTACK = 500
  4. $SWSTACK = 500
  5. $FRAMESIZE = 500
  6. $LIB "XMEGA.LIB"
  7. ENABLE INTERRUPTS
  8. '-------------------------------------------------------------------------------------------------------------------------------------------
  9. 'CONFIG OSC = ENABLED , PLLOSC = ENABLED , PLLMUL =  29
  10. 'CONFIG SYSCLOCK = PLL
  11. '-------------------------------------------------------------------------------------------------------------------------------------------
  12. CONFIG OSC = ENABLED , EXTOSC = ENABLED , PLLOSC = ENABLED , _
  13. RANGE = 9MHZ_12MHZ , STARTUP = XTAL_16KCLK , PLLSOURCE = EXTCLOCK , PLLMUL = 5 '5 X 10MHZ = 50MHZ
  14. CONFIG SYSCLOCK = PLL , PRESCALEA = 1 , PRESCALEBC = 1_1
  15. CONFIG PRIORITY = STATIC , VECTOR = APPLICATION , HI = ENABLED , MED = ENABLED , LO = ENABLED
  16. '*******************************************************************************************************************************************
  17. '*** UART-COM5 *****************************************************************************************************************************
  18. '*******************************************************************************************************************************************
  19. CONFIG COM5 = 115200 , MODE = ASYNCHRONEOUS , PARITY = NONE , STOPBITS = 1 , DATABITS = 8
  20. OPEN "COM5:" FOR BINARY AS #5
  21. CONFIG SERIALIN4 = BUFFERED , SIZE = 30 , BYTEMATCH = 13
  22. ENABLE USARTe0_RXC, LO
  23. DIM RS232_5 AS STRING * 20
  24. DIM COM5 AS LONG
  25. '*******************************************************************************************************************************************
  26. '*** LCD 240x320 ILI9341 *******************************************************************************************************************
  27. '*******************************************************************************************************************************************
  28. CONFIG VPORT0 = E    'NIE TRZEBA PODLACZYC/DODACNA "-" Cs1=CS)  Rst=RESET    A0=DC  Si=SDI    Sclk=SCK
  29. CONFIG GRAPHLCD = COLOR , CS1 = PORT0.0 , RST = PORT0.6 , A0 = PORT0.5 , SI = PORT0.4 , SCLK = PORT0.7
  30. CONST PORTRAIT=0
  31. CONST ROTATE_180 = 1
  32. DIM OFFSET256 AS BYTE
  33. $LIB "glcd-ILI9341_2R8_240x320.lib"
  34. INITLCD
  35. CLS
  36. CONST BLACK = &B0000_0000
  37. CONST RED = &B1110_0000
  38. CONST GREEN = &B0001_1100
  39. CONST BLUE = &B0000_0011
  40. CONST MAGENTA = &B1110_0011
  41. CONST YELLOW = &B1111_1100
  42. CONST CYAN = &B0001_1111
  43. CONST WHITE = &B1111_1111
  44. CONST ORANGE = &B1111_0100
  45. CONST BRIGHTGREEN = &B0011_1110
  46. CONST BRIGHTBLUE = &B0001_1111
  47. CONST DARKRED = &B1100_0000
  48. CONST DARKGREEN = &B0001_0100
  49. CONST DARKBLUE = &B0000_0010
  50. OFFSET256 = 1
  51. BOXFILL (0 , 0) - (64 , 240) , BLACK
  52. OFFSET256 = 0
  53. BOXFILL (0 , 0) - (255 , 240) , BLACK
  54. SETFONT COLOR8X8
  55. 'SETFONT COLOR16X16
  56. '*******************************************************************************************************************************************
  57. '*** PIN / PORT ****************************************************************************************************************************
  58. '*******************************************************************************************************************************************
  59. CONFIG portC.0=INPUT : CONFIG XPIN = PortC.0 , OUTPULL = PULLUP  , SENSE = BOTH
  60. PORTC_INT0MASK = &B0000_0001         'przerwanie dla pinu 0
  61. ON PORTC_INT0 PRZERWANIE_PINC0
  62. ENABLE PORTC_INT0 , LO
  63. '*******************************************************************************************************************************************
  64. '*** TCc0 OVF ******************************************************************************************************************************
  65. '*******************************************************************************************************************************************
  66. CONFIG TCC0 = NORMAL , PRESCALE = 1               ' 1 , 2, 4, 8, 64, 256, 1024
  67. TCC0_PER = 65535
  68. STOP TCC0
  69. '*******************************************************************************************************************************************
  70. '*** ZMIENNE *******************************************************************************************************************************
  71. '*******************************************************************************************************************************************
  72. DIM XX AS WORD
  73. '*******************************************************************************************************************************************
  74. '*** PROGRAM *******************************************************************************************************************************
  75. '*******************************************************************************************************************************************
  76. DO
  77.  
  78. LCDAT  0 ,0 , "XX     :" ; XX            ;"      " , WHITE, BLACK
  79.  
  80. LOOP
  81. END
  82. '-------------------------------------------------------------------------------------------------------------------------------------------
  83. '$INCLUDE "COLOR16x16.FONT"
  84. $INCLUDE "COLOR8x8.FONT"
  85. '-------------------------------------------------------------------------------------------------------------------------------------------
  86. SERIAL4CHARMATCH:
  87. PUSHALL
  88. INPUT #5 , RS232_5 NOECHO
  89. COM5 = VAL(RS232_5)
  90. POPALL
  91. RETURN
  92. '-------------------------------------------------------------------------------------------------------------------------------------------
  93. PRZERWANIE_PINC0:
  94. IF PINC.0 = 1 THEN
  95. START TCC0
  96. END IF
  97.  
  98. IF PINC.0 = 0 THEN
  99. STOP TCC0
  100. XX = TCC0_CNT
  101. TCC0_CNT = 0
  102. END IF
  103. RETURN
ODPOWIEDZ