ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
fw_pca.h
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef ___FW_PCA_H___
16#define ___FW_PCA_H___
17
18#include "fw_conf.h"
19#include "fw_types.h"
20
21typedef enum
22{
32
33typedef enum
34{
35 PCA_WorkMode_None = 0x00, // n/a
36 PCA_WorkMode_PWM_NonInterrupt = 0x42, // 6/7/8/10-bit PWM, no interrupt
37 PCA_WorkMode_PWM_RiseInterrupt = 0x63, // 6/7/8/10-bit PWM, rising interrupt
38 PCA_WorkMode_PWM_FallInterrupt = 0x53, // 6/7/8/10-bit PWM, falling interrupt
39 PCA_WorkMode_PWM_EdgeInterrupt = 0x73, // 6/7/8/10-bit PWM, both edge interrupt
40 PCA_WorkMode_CAP_16bitRising = 0x20, // 16-bit Capture Mode, capture triggered by rising edge on CCPn/PCAn
41 PCA_WorkMode_CAP_16bitFalling = 0x10, // 16-bit Capture Mode, capture triggered by falling edge on CCPn/PCAn
42 PCA_WorkMode_CAP_16bitEdge = 0x30, // 16-bit Capture Mode, capture triggered by both edge on CCPn/PCAn
43 PCA_WorkMode_CAP_16bitTimer = 0x48, // 16-bit software timer
44 PCA_WorkMode_CAP_16bitPulseOut = 0x4C, // 16-bit high-speed pulse output
46
47typedef enum
48{
49 PCA_PWM_BitWidth_8 = 0x00, // {EPCnH, CCAPnH[7:0]} {EPCnL, CCAPnL[7:0]}
50 PCA_PWM_BitWidth_7 = 0x01, // {EPCnH, CCAPnH[6:0]} {EPCnL, CCAPnL[6:0]}
51 PCA_PWM_BitWidth_6 = 0x02, // {EPCnH, CCAPnH[5:0]} {EPCnL, CCAPnL[5:0]}
52 PCA_PWM_BitWidth_10 = 0x03, // {EPCnH, XCCAPnH[1:0], CCAPnH[7:0]} {EPCnL, XCCAPnL[1:0], CCAPnL[7:0]}
54
55typedef enum
56{
57 // ECI CCP0 CCP1 CCP2
62
63typedef enum
64{
65 // ECI CCP0 CCP1 CCP2
70
71typedef enum
72{
73 // ECI CCP0 CCP1 CCP2
78
79
80#define PCA_SetCounterState(__STATE__) SBIT_ASSIGN(CR, __STATE__)
81#define PCA_ClearCounterOverflowInterrupt() SBIT_RESET(CF)
82#define PCA_PCA0_ClearInterrupt() SBIT_RESET(CCF0)
83#define PCA_PCA1_ClearInterrupt() SBIT_RESET(CCF1)
84#define PCA_PCA2_ClearInterrupt() SBIT_RESET(CCF2)
85
86#define PCA_SetStopCounterInIdle(__STATE__) SFR_ASSIGN(CMOD, 7, __STATE__)
87#define PCA_SetClockSource(__SOURCE___) (CMOD = CMOD & ~(0x07 << 1) | ((__SOURCE___) << 1))
88#define PCA_EnableCounterOverflowInterrupt(__STATE__) SFR_ASSIGN(CMOD, 0, __STATE__)
89
90#define PCA_PCA0_SetWorkMode(__MODE__) (CCAPM0 = (__MODE__))
91#define PCA_PCA1_SetWorkMode(__MODE__) (CCAPM1 = (__MODE__))
92#define PCA_PCA2_SetWorkMode(__MODE__) (CCAPM2 = (__MODE__))
93
94#define PCA_PWM0_SetBitWidth(__BIT_WIDTH__) (PCA_PWM0 = PCA_PWM0 & ~(0x03 << 6) | ((__BIT_WIDTH__) << 6))
95#define PCA_PWM1_SetBitWidth(__BIT_WIDTH__) (PCA_PWM1 = PCA_PWM1 & ~(0x03 << 6) | ((__BIT_WIDTH__) << 6))
96#define PCA_PWM2_SetBitWidth(__BIT_WIDTH__) (PCA_PWM2 = PCA_PWM2 & ~(0x03 << 6) | ((__BIT_WIDTH__) << 6))
100#define PCA_PCA0_SetCompareValue(__VALUE__) do{CCAP0H = (__VALUE__); CCAP0L = (__VALUE__);}while(0)
101#define PCA_PCA1_SetCompareValue(__VALUE__) do{CCAP1H = (__VALUE__); CCAP1L = (__VALUE__);}while(0)
102#define PCA_PCA2_SetCompareValue(__VALUE__) do{CCAP2H = (__VALUE__); CCAP2L = (__VALUE__);}while(0)
106#define PCA_PCA0_ChangeCompareValue(__VALUE__) (CCAP0H = (__VALUE__))
107#define PCA_PCA1_ChangeCompareValue(__VALUE__) (CCAP1H = (__VALUE__))
108#define PCA_PCA2_ChangeCompareValue(__VALUE__) (CCAP2H = (__VALUE__))
109
113#define PCA_PCA0_SetCompareValue10bit(__VALUE__) do{ \
114 PCA_PWM0 = PCA_PWM0 & ~(0x0F << 2) | (((__VALUE__) >> 4) & 0x30) | (((__VALUE__) >> 6) & 0x0C); \
115 CCAP0H = ((__VALUE__) & 0xFF); CCAP0L = ((__VALUE__) & 0xFF); \
116 }while(0)
117#define PCA_PCA1_SetCompareValue10bit(__VALUE__) do{ \
118 PCA_PWM1 = PCA_PWM1 & ~(0x0F << 2) | (((__VALUE__) >> 4) & 0x30) | (((__VALUE__) >> 6) & 0x0C); \
119 CCAP1H = ((__VALUE__) & 0xFF); CCAP1L = ((__VALUE__) & 0xFF); \
120 }while(0)
121#define PCA_PCA2_SetCompareValue10bit(__VALUE__) do{ \
122 PCA_PWM2 = PCA_PWM2 & ~(0x0F << 2) | (((__VALUE__) >> 4) & 0x30) | (((__VALUE__) >> 6) & 0x0C); \
123 CCAP2H = ((__VALUE__) & 0xFF); CCAP2L = ((__VALUE__) & 0xFF); \
124 }while(0)
125
131#define PCA_PCA0_ChangeCompareValue10bit(__VALUE__) do{ \
132 PCA_PWM0 = PCA_PWM0 & ~(0x03 << 4) | (((__VALUE__) >> 4) & 0x30); \
133 CCAP0H = ((__VALUE__) & 0xFF); \
134 }while(0)
135#define PCA_PCA1_ChangeCompareValue10bit(__VALUE__) do{ \
136 PCA_PWM1 = PCA_PWM1 & ~(0x03 << 4) | (((__VALUE__) >> 4) & 0x30); \
137 CCAP1H = ((__VALUE__) & 0xFF); \
138 }while(0)
139#define PCA_PCA2_ChangeCompareValue10bit(__VALUE__) do{ \
140 PCA_PWM2 = PCA_PWM2 & ~(0x03 << 4) | (((__VALUE__) >> 4) & 0x30); \
141 CCAP2H = ((__VALUE__) & 0xFF); \
142 }while(0)
143
147#define PCA_SetPort(__ALTER_PORT__) (P_SW1 = P_SW1 & ~(0x03 << 4) | ((__ALTER_PORT__) << 4))
148
149#endif
PCA_AlterPort_G1K08A_t
Definition: fw_pca.h:64
@ PCA_AlterPort_G1K08A_P55_P32_P33_P54
Definition: fw_pca.h:66
@ PCA_AlterPort_G1K08A_P31_P32_P33_P55
Definition: fw_pca.h:68
@ PCA_AlterPort_G1K08A_P55_P31_P33_P54
Definition: fw_pca.h:67
PCA_PWM_Bitwidth_t
Definition: fw_pca.h:48
@ PCA_PWM_BitWidth_7
Definition: fw_pca.h:50
@ PCA_PWM_BitWidth_6
Definition: fw_pca.h:51
@ PCA_PWM_BitWidth_8
Definition: fw_pca.h:49
@ PCA_PWM_BitWidth_10
Definition: fw_pca.h:52
PCA_WorkMode_t
Definition: fw_pca.h:34
@ PCA_WorkMode_None
Definition: fw_pca.h:35
@ PCA_WorkMode_CAP_16bitTimer
Definition: fw_pca.h:43
@ PCA_WorkMode_PWM_EdgeInterrupt
Definition: fw_pca.h:39
@ PCA_WorkMode_CAP_16bitPulseOut
Definition: fw_pca.h:44
@ PCA_WorkMode_CAP_16bitEdge
Definition: fw_pca.h:42
@ PCA_WorkMode_PWM_NonInterrupt
Definition: fw_pca.h:36
@ PCA_WorkMode_PWM_FallInterrupt
Definition: fw_pca.h:38
@ PCA_WorkMode_CAP_16bitRising
Definition: fw_pca.h:40
@ PCA_WorkMode_PWM_RiseInterrupt
Definition: fw_pca.h:37
@ PCA_WorkMode_CAP_16bitFalling
Definition: fw_pca.h:41
PCA_ClockSource_t
Definition: fw_pca.h:22
@ PCA_ClockSource_SysClk
Definition: fw_pca.h:27
@ PCA_ClockSource_SysClkDiv12
Definition: fw_pca.h:23
@ PCA_ClockSource_Timer0Overflow
Definition: fw_pca.h:25
@ PCA_ClockSource_SysClkDiv4
Definition: fw_pca.h:28
@ PCA_ClockSource_SysClkDiv8
Definition: fw_pca.h:30
@ PCA_ClockSource_ExtClock
Definition: fw_pca.h:26
@ PCA_ClockSource_SysClkDiv2
Definition: fw_pca.h:24
@ PCA_ClockSource_SysClkDiv6
Definition: fw_pca.h:29
PCA_AlterPort_G1K08T_t
Definition: fw_pca.h:72
@ PCA_AlterPort_G1K08T_P34_P35_P36_P37
Definition: fw_pca.h:75
@ PCA_AlterPort_G1K08T_P54_P13_P14_P15
Definition: fw_pca.h:76
@ PCA_AlterPort_G1K08T_P13_P11_P10_P37
Definition: fw_pca.h:74
PCA_AlterPort_t
Definition: fw_pca.h:56
@ PCA_AlterPort_P12_P11_P10_P37
Definition: fw_pca.h:58
@ PCA_AlterPort_P34_P35_P36_P37
Definition: fw_pca.h:59
@ PCA_AlterPort_P24_P25_P26_P27
Definition: fw_pca.h:60