SimpleFOClibrary 2.4.0
Loading...
Searching...
No Matches
samd_mcu.h
Go to the documentation of this file.
1
2#ifndef SAMD_MCU_H
3#define SAMD_MCU_H
4
5
6// uncomment to enable debug output from SAMD driver
7// can set this as build-flag in Arduino IDE or PlatformIO
8// #define SIMPLEFOC_SAMD_DEBUG
9
10#include "../../hardware_api.h"
11
12
13#if defined(__SAME51J19A__) || defined(__ATSAME51J19A__)
14#ifndef _SAME51_
15#define _SAME51_
16#endif
17#endif
18
19
20#if defined(_SAMD21_)||defined(_SAMD51_)||defined(_SAME51_)
21
22
23#include "Arduino.h"
24#include "variant.h"
25#include "wiring_private.h"
26
27
28#ifndef SIMPLEFOC_SAMD_PWM_RESOLUTION
29#define SIMPLEFOC_SAMD_PWM_RESOLUTION 1000
30#endif
31
32#define SIMPLEFOC_SAMD_DEFAULT_PWM_FREQUENCY_HZ 24000
33// arbitrary maximum. On SAMD51 with 120MHz clock this means 2kHz minimum pwm frequency
34#define SIMPLEFOC_SAMD_MAX_PWM_RESOLUTION 30000
35// lets not go too low - 400 with clock speed of 120MHz on SAMD51 means 150kHz maximum PWM frequency...
36// 400 with 48MHz clock on SAMD21 means 60kHz maximum PWM frequency...
37#define SIMPLEFOC_SAMD_MIN_PWM_RESOLUTION 400
38// this is the most we can support on the TC units
39#define SIMPLEFOC_SAMD_PWM_TC_RESOLUTION 250
40
41#ifndef SIMPLEFOC_SAMD_MAX_TCC_PINCONFIGURATIONS
42#define SIMPLEFOC_SAMD_MAX_TCC_PINCONFIGURATIONS 24
43#endif
44
45
46
47struct tccConfiguration {
48 uint8_t pin;
49 EPioType peripheral; // 1=true, 0=false
50 uint8_t wo;
51 union tccChanInfo {
52 struct {
53 int8_t chan;
54 int8_t tccn;
55 };
56 uint16_t chaninfo;
57 } tcc;
58 uint16_t pwm_res;
59};
60
61
62
63
64
65
66struct wo_association {
67 EPortType port;
68 uint32_t pin;
69 ETCChannel tccE;
70 uint8_t woE;
71 ETCChannel tccF;
72 uint8_t woF;
73#if defined(_SAMD51_)||defined(_SAME51_)
74 ETCChannel tccG;
75 uint8_t woG;
76#endif
77};
78
79
80
81typedef struct SAMDHardwareDriverParams {
82 tccConfiguration* tccPinConfigurations[6];
83 uint32_t pwm_frequency;
84 float dead_zone;
85} SAMDHardwareDriverParams;
86
87
88
89
90#if defined(_SAMD21_)
91#define NUM_PIO_TIMER_PERIPHERALS 2
92#elif defined(_SAMD51_)||defined(_SAME51_)
93#define NUM_PIO_TIMER_PERIPHERALS 3
94#endif
95
96
97
98/**
99 * Global state
100 */
101extern struct wo_association WO_associations[];
102extern uint8_t TCC_CHANNEL_COUNT[];
103extern tccConfiguration tccPinConfigurations[SIMPLEFOC_SAMD_MAX_TCC_PINCONFIGURATIONS];
104extern uint8_t numTccPinConfigurations;
105extern bool SAMDClockConfigured;
106extern bool tccConfigured[TCC_INST_NUM+TC_INST_NUM];
107
108
109
110struct wo_association& getWOAssociation(EPortType port, uint32_t pin);
111void writeSAMDDutyCycle(tccConfiguration* info, float dc);
112void configureSAMDClock();
113void configureTCC(tccConfiguration& tccConfig, long pwm_frequency, bool negate=false, float hw6pwm=-1);
114__inline__ void syncTCC(Tcc* TCCx) __attribute__((always_inline, unused));
115EPioType getPeripheralOfPermutation(int permutation, int pin_position);
116
117#ifdef SIMPLEFOC_SAMD_DEBUG
118void printTCCConfiguration(tccConfiguration& info);
119void printAllPinInfos();
120#endif
121
122
123
124#endif
125
126
127#endif
__attribute__((weak)) float _sin(float a)
Definition foc_utils.cpp:7