Skip to content

Commit 4f0d9f0

Browse files
Erling Holten WikenErling Holten Wiken
authored andcommitted
MPAE-12175: updated to Melody v1.37.26, updated readme
1 parent 6e22821 commit 4f0d9f0

File tree

10 files changed

+220
-69
lines changed

10 files changed

+220
-69
lines changed

.main-meta/main.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"compiler": [
1616
{
1717
"name": "XC8",
18-
"semverRange": "^2.31.0"
18+
"semverRange": "^2.32.0"
1919
}
2020
],
2121
"dfp": {

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
This code example shows how to use single slope Pulse-Width Modulation (PWM) in the Timer/Counter A (TCA) on the AVR® DB Family of microcontrollers to generate overflow interrupts that toggle a LED. The time between each overflow interrupt is determined by the TCA clock prescaler selection and the value loaded into the period register. Then the overflow interrupt is enabled, and the TCA is started. Inside the interrupt handler function, the LED is toggled. The result is that the amber LED0 on the AVR128DB48 Curiosity Nano development board is blinking with an equal period on and off (50% duty cycle).
77

8-
![cnano](images/avr128db48_cnano_board.png)
8+
![cnano](images/avr128db48_cnano_board.png | width=1000)
99

1010
## Related Documentation
1111

1212
- [AVR128DB48 device page](https://www.microchip.com/wwwproducts/en/AVR128DB48)
13+
- [MPLAB Code Configurator](https://www.microchip.com/en-us/development-tools-tools-and-software/embedded-software-center/mplab-code-configurator)
14+
- [AVR128DB48 Curiosity Nano Hardware User Guide](https://www.microchip.com/DevelopmentTools/ProductDetails/PartNO/EV35L43A)
1315

1416

1517
## Software Used
@@ -18,9 +20,9 @@ Microchip’s free MPLAB X IDE, compiler and MPLAB Code Configurator (MCC) graph
1820

1921
- [MPLAB® X IDE v5.45](https://www.microchip.com/mplab/mplab-x-ide) or newer
2022
- [MPLAB® Xpress IDE](https://www.microchip.com/xpress) (alternative to MPLAB X IDE)
21-
- [XC8 Compiler v2.31](https://www.microchip.com/mplab/compilers) or newer
23+
- [XC8 Compiler v2.32](https://www.microchip.com/mplab/compilers) or newer
2224
- [MPLAB® Code Configurator (MCC) v4.1.0](https://www.microchip.com/mplab/mplab-code-configurator) or newer
23-
- [MPLAB® Melody Library 1.37.24 or newer](https://www.microchip.com/mplab/mplab-code-configurator) or newer
25+
- [MPLAB® Melody Library 1.37.26 or newer](https://www.microchip.com/mplab/mplab-code-configurator) or newer
2426
- [MCC Device Libraries 8-bit AVR MCUs 2.7.0](https://www.microchip.com/mplab/mplab-code-configurator) or newer
2527
- [Microchip AVR128DB48 Device Support Pack AVR-Dx_DFP 1.2.98](https://packs.download.microchip.com/) or newer
2628

@@ -42,9 +44,9 @@ Add the required peripherals: Timer Counter A (TCA0), Interrupt Manager, and Pi
4244

4345
### System Configuration: INTERRUPT MANAGER
4446

45-
In the INTERRUPT MANAGER, global interrupts is enabled. The interrupt associated with TCA0 (overflow) is enabled in the TCA0 configuration.
47+
In the INTERRUPT MANAGER, global interrupts is enabled. The interrupt associated with TCA0 (overflow) is enabled in the TCA0 configuration, so we will leave that alone in this view.
4648

47-
![Interrupts](images/interrupt_manager_needupdate.png)
49+
![Interrupts](images/interrupt_manager.png)
4850

4951
### System Configuration: PINS
5052

@@ -73,7 +75,7 @@ In the *Pins* configuration box, now the pin you added will show (Pin Name = PB3
7375
- Requested Timeout used in this example is 0.25s. For different periods, use a combination of Clock Selection and Requested Timeout to create the desired period (based on the Clock Selection prescaler value, the possible range for Requested Timeout will change, higher prescaler gives longer timeout options. The actual timeout will be calculated and shown in next line (this should be identical to Requested Timeout in normal mode).
7476
- Turn on "Enable Overflow Interrupt" button to enable overflow interrupts from TCA0.
7577

76-
![tca0](images/TCA0_needsupdate.png)
78+
![tca0](images/TCA0.png)
7779

7880
Now all configuration is complete. You have now enabled global interrupts, set PB3 as output in order to blink the LED and configured the timer (TCA0) to count up to a given value that gives you a certain time period (250 ms), then trigger an overflow interrupt. Next steps are setting up the hardware and programming the device.
7981

avr128db48-blink-with-timer-mplab-mcc.X/avr128db48-cnano-led-blink-pwm-mcc.mc3

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

avr128db48-blink-with-timer-mplab-mcc.X/avr128db48-cnano-led-blink-pwm-mcc.mc3.bak

Lines changed: 175 additions & 0 deletions
Large diffs are not rendered by default.

avr128db48-blink-with-timer-mplab-mcc.X/mcc_generated_files/system/pins.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,6 @@
1414
#include <avr/io.h>
1515
#include "./port.h"
1616

17-
//get/set IO_PA2 aliases
18-
#define IO_PA2_SetHigh() do { PORTA_OUTSET = 0x4; } while(0)
19-
#define IO_PA2_SetLow() do { PORTA_OUTCLR = 0x4; } while(0)
20-
#define IO_PA2_Toggle() do { PORTA_OUTTGL = 0x4; } while(0)
21-
#define IO_PA2_GetValue() (VPORTA.IN & (0x1 << 2))
22-
#define IO_PA2_SetDigitalInput() do { PORTA_DIRCLR = 0x4; } while(0)
23-
#define IO_PA2_SetDigitalOutput() do { PORTA_DIRSET = 0x4; } while(0)
24-
#define IO_PA2_SetPullUp() do { PORTA_PIN2CTRL |= PORT_PULLUPEN_bm; } while(0)
25-
#define IO_PA2_ResetPullUp() do { PORTA_PIN2CTRL &= ~PORT_PULLUPEN_bm; } while(0)
26-
#define IO_PA2_SetInverted() do { PORTA_PIN2CTRL |= PORT_INVEN_bm; } while(0)
27-
#define IO_PA2_ResetInverted() do { PORTA_PIN2CTRL &= ~PORT_INVEN_bm; } while(0)
28-
#define IO_PA2_DisableInterruptOnChange() do { PORTA.PIN2CTRL = (PORTA.PIN2CTRL & ~PORT_ISC_gm) | 0x0 ; } while(0)
29-
#define IO_PA2_EnableInterruptForBothEdges() do { PORTA.PIN2CTRL = (PORTA.PIN2CTRL & ~PORT_ISC_gm) | 0x1 ; } while(0)
30-
#define IO_PA2_EnableInterruptForRisingEdge() do { PORTA.PIN2CTRL = (PORTA.PIN2CTRL & ~PORT_ISC_gm) | 0x2 ; } while(0)
31-
#define IO_PA2_EnableInterruptForFallingEdge() do { PORTA.PIN2CTRL = (PORTA.PIN2CTRL & ~PORT_ISC_gm) | 0x3 ; } while(0)
32-
#define IO_PA2_DisableDigitalInputBuffer() do { PORTA.PIN2CTRL = (PORTA.PIN2CTRL & ~PORT_ISC_gm) | 0x4 ; } while(0)
33-
#define IO_PA2_EnableInterruptForLowLevelSensing() do { PORTA.PIN2CTRL = (PORTA.PIN2CTRL & ~PORT_ISC_gm) | 0x5 ; } while(0)
34-
3517
//get/set LED0_PIN aliases
3618
#define LED0_PIN_SetHigh() do { PORTB_OUTSET = 0x8; } while(0)
3719
#define LED0_PIN_SetLow() do { PORTB_OUTCLR = 0x8; } while(0)
@@ -51,8 +33,6 @@
5133
#define LED0_PIN_EnableInterruptForLowLevelSensing() do { PORTB.PIN3CTRL = (PORTB.PIN3CTRL & ~PORT_ISC_gm) | 0x5 ; } while(0)
5234

5335
void PIN_MANAGER_Initialize();
54-
void PA2_DefaultInterruptHandler(void);
55-
void PA2_SetInterruptHandler(void (* interruptHandler)(void)) ;
5636
void PB3_DefaultInterruptHandler(void);
5737
void PB3_SetInterruptHandler(void (* interruptHandler)(void)) ;
5838
#endif /* PINS_H_INCLUDED */

avr128db48-blink-with-timer-mplab-mcc.X/mcc_generated_files/system/src/pins.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@
3737

3838
#include "../pins.h"
3939

40-
static void (*PA2_InterruptHandler)(void);
4140
static void (*PB3_InterruptHandler)(void);
4241
void PORT_Initialize(void);
4342

4443
void PIN_MANAGER_Initialize()
4544
{
4645
PORT_Initialize();
4746
/* DIR Registers Initialization */
48-
PORTA.DIR = 0x4;
47+
PORTA.DIR = 0x0;
4948
PORTB.DIR = 0x8;
5049
PORTC.DIR = 0x0;
5150
PORTD.DIR = 0x0;
@@ -150,7 +149,6 @@ void PIN_MANAGER_Initialize()
150149
PORTMUX.ZCDROUTEA = 0x0;
151150

152151
// register default ISC callback functions at runtime; use these methods to register a custom function
153-
PA2_SetInterruptHandler(PA2_DefaultInterruptHandler);
154152
PB3_SetInterruptHandler(PB3_DefaultInterruptHandler);
155153
}
156154

@@ -186,19 +184,6 @@ void PORT_Initialize(void)
186184
}
187185

188186
}
189-
/**
190-
Allows selecting an interrupt handler for PA2 at application runtime
191-
*/
192-
void PA2_SetInterruptHandler(void (* interruptHandler)(void))
193-
{
194-
PA2_InterruptHandler = interruptHandler;
195-
}
196-
197-
void PA2_DefaultInterruptHandler(void)
198-
{
199-
// add your PA2 interrupt custom code
200-
// or set custom function using PA2_SetInterruptHandler()
201-
}
202187
/**
203188
Allows selecting an interrupt handler for PB3 at application runtime
204189
*/
@@ -215,10 +200,6 @@ void PB3_DefaultInterruptHandler(void)
215200
ISR(PORTA_PORT_vect)
216201
{
217202
// Call the interrupt handler for the callback registered at runtime
218-
if(VPORTA.INTFLAGS & PORT_INT2_bm)
219-
{
220-
PA2_InterruptHandler();
221-
}
222203

223204
/* Clear interrupt flags */
224205
VPORTA.INTFLAGS = 0xff;

avr128db48-blink-with-timer-mplab-mcc.X/mcc_generated_files/timer/src/tca0.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,62 +142,71 @@ ISR(TCA0_OVF_vect)
142142
*/
143143
void TCA0_Initialize(void) {
144144
// Compare 0
145-
TCA0.SINGLE.CMP0 = 0x0;
145+
TCA0.SINGLE.CMP0 = 0xF423;
146146

147147
// Compare 1
148-
TCA0.SINGLE.CMP1 = 0x0;
148+
TCA0.SINGLE.CMP1 = 0xF423;
149149

150150
// Compare 2
151-
TCA0.SINGLE.CMP2 = 0x0;
151+
TCA0.SINGLE.CMP2 = 0xF423;
152152

153153
// Count
154154
TCA0.SINGLE.CNT = 0x0;
155155

156-
// ALUPD undefined; CMP0EN disabled; CMP1EN disabled; CMP2EN disabled; WGMODE SINGLESLOPE;
156+
// ALUPD disabled; CMP0EN disabled; CMP1EN disabled; CMP2EN disabled; WGMODE SINGLESLOPE;
157157
TCA0.SINGLE.CTRLB = 0x3;
158158

159-
// CMP0OV undefined; CMP1OV undefined; CMP2OV undefined;
159+
// CMP0OV disabled; CMP1OV disabled; CMP2OV disabled;
160160
TCA0.SINGLE.CTRLC = 0x0;
161161

162162
// SPLITM disabled;
163163
TCA0.SINGLE.CTRLD = 0x0;
164164

165-
// CMD undefined; LUPD undefined; DIR UP;
165+
// CMD NONE; DIR disabled; LUPD disabled;
166166
TCA0.SINGLE.CTRLECLR = 0x0;
167167

168-
// CMD undefined; LUPD undefined; DIR UP;
168+
// CMD NONE; DIR UP; LUPD disabled;
169169
TCA0.SINGLE.CTRLESET = 0x0;
170170

171-
// CMP0BV undefined; CMP1BV undefined; CMP2BV undefined; PERBV undefined;
171+
// CMP0BV disabled; CMP1BV disabled; CMP2BV disabled; PERBV disabled;
172172
TCA0.SINGLE.CTRLFCLR = 0x0;
173173

174-
// CMP0BV undefined; CMP1BV undefined; CMP2BV undefined; PERBV undefined;
174+
// CMP0BV disabled; CMP1BV disabled; CMP2BV disabled; PERBV disabled;
175175
TCA0.SINGLE.CTRLFSET = 0x0;
176176

177-
// DBGRUN undefined;
177+
// DBGRUN disabled;
178178
TCA0.SINGLE.DBGCTRL = 0x0;
179179

180-
// CNTAEI undefined; CNTBEI undefined; EVACTA undefined; EVACTB undefined;
180+
// CNTAEI disabled; CNTBEI disabled; EVACTA CNT_POSEDGE; EVACTB NONE;
181181
TCA0.SINGLE.EVCTRL = 0x0;
182182

183183
// CMP0 disabled; CMP1 disabled; CMP2 disabled; OVF enabled;
184184
TCA0.SINGLE.INTCTRL = 0x1;
185185

186-
// CMP0 undefined; CMP1 undefined; CMP2 undefined; OVF undefined;
186+
// CMP0 disabled; CMP1 disabled; CMP2 disabled; OVF disabled;
187187
TCA0.SINGLE.INTFLAGS = 0x0;
188188

189-
// Period = 250ms; 4MHz/16 = 250kHz -> t_TCA = 1/250k = 4us;
190-
// PER = 250ms/4us = 62500 = 0xF424
191-
TCA0.SINGLE.PER = 0xF424;
189+
// Period
190+
TCA0.SINGLE.PER = 0xF423;
192191

193192
// Temporary data for 16-bit Access
194193
TCA0.SINGLE.TEMP = 0x0;
195194

196-
// RUNSTDBY disabled; CLKSEL DIV16; ENABLE enabled;
195+
// CLKSEL DIV16; ENABLE enabled; RUNSTDBY disabled;
197196
TCA0.SINGLE.CTRLA = 0x9;
198197

199198
}
200199

200+
void TCA0_Start(void)
201+
{
202+
TCA0.SINGLE.CTRLA|= TCA_SINGLE_ENABLE_bm;
203+
}
204+
205+
void TCA0_Stop(void)
206+
{
207+
TCA0.SINGLE.CTRLA&= ~TCA_SINGLE_ENABLE_bm;
208+
}
209+
201210
void TCA0_Write(uint16_t timerVal)
202211
{
203212
TCA0.SINGLE.CNT=timerVal;

avr128db48-blink-with-timer-mplab-mcc.X/mcc_generated_files/timer/tca0.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ extern "C" {
6363

6464
typedef void (*TCA0_cb_t)(void);
6565

66+
extern const struct TMR_INTERFACE TCA0_Interface;
67+
6668
void TCA0_Initialize(void);
69+
void TCA0_Start(void);
70+
void TCA0_Stop(void);
6771
void TCA0_OverflowCallbackRegister(TCA0_cb_t cb);
6872
void TCA0_Compare0CallbackRegister(TCA0_cb_t cb);
6973
void TCA0_Compare1CallbackRegister(TCA0_cb_t cb);

images/TCA0.png

36.2 KB
Loading

images/interrupt_manager.png

19.4 KB
Loading

0 commit comments

Comments
 (0)