Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example
init_timer1.c
1
/*
2
* File: init_timer1.c
3
* Author: M91406
4
*
5
* Created on July 8, 2019, 2:47 PM
6
*/
7
8
#include <xc.h>
9
#include <stdint.h>
10
#include <stdbool.h>
11
12
#include "config/hal.h"
13
#include "config/init/init_timer1.h"
14
22
40
volatile
uint16_t
sysOsTimer_Initialize
(
void
)
41
{
42
volatile
uint16_t retval=1;
43
44
T1CONbits.TON = 0;
// Timer1 On: Stops 16-bit Timer1 during configuration
45
T1CONbits.TSIDL = 0;
// Timer1 Stop in Idle Mode: Continues module operation in Idle mode
46
T1CONbits.TMWDIS = 0;
// Asynchronous Timer1 Write Disable: Back-to-back writes are enabled in Asynchronous mode
47
T1CONbits.TMWIP = 0;
// Asynchronous Timer1 Write in Progress: Write to the timer in Asynchronous mode is complete
48
T1CONbits.PRWIP = 0;
// Asynchronous Period Write in Progress: Write to the Period register in Asynchronous mode is complete
49
T1CONbits.TECS = 0b11;
// Timer1 Extended Clock Select: FRC clock
50
T1CONbits.TGATE = 0;
// Timer1 Gated Time Accumulation Enable: Gated time accumulation is disabled when TCS = 0
51
T1CONbits.TCKPS = 0;
// Timer1 Input Clock Prescale Select: 1:1
52
T1CONbits.TSYNC = 0;
// Timer1 External Clock Input Synchronization Select: Does not synchronize the External Clock input
53
T1CONbits.TCS = 0;
// Timer1 Clock Source Select: Internal peripheral clock
54
55
// Reset Timer Counter Register TMR to Zero;
56
TMR1 = 0x00;
57
//Period = 0.0001 s; Frequency = 100000000 Hz; PR 9999;
58
PR1 =
MAIN_EXEC_PER
;
59
60
// Reset interrupt and interrupt flag bit
61
_OSTIMER_IP
=
_OSTIMER_PRIORITY
;
// Set interrupt priority to DEFAULT
62
_OSTIMER_IF
= 0;
// Reset interrupt flag bit
63
_OSTIMER_IE
= 0;
// Disable Timer1 interrupt
64
65
return
(retval);
66
}
67
68
81
volatile
uint16_t
sysOsTimer_Enable
(
volatile
bool
interrupt_enable,
volatile
uint8_t interrupt_priority)
82
{
83
volatile
uint16_t retval=1;
84
85
// Enable Timer1
86
_OSTIMER_IP
= interrupt_priority;
// Set interrupt priority to zero
87
_OSTIMER_IF
= 0;
// Reset interrupt flag bit
88
_OSTIMER_IE
= interrupt_enable;
// Enable/Disable Timer1 interrupt
89
T1CONbits.TON = 1;
// Turn on Timer1
90
retval &= T1CONbits.TON;
// Add timer enable bit to list of checked bits
91
92
return
(retval);
93
}
94
// end of group os-timer-initialization
96
97
// end of file
_OSTIMER_IF
#define _OSTIMER_IF
interrupt flag bit
Definition:
dpsk3_hwdescr.h:177
sysOsTimer_Enable
volatile uint16_t sysOsTimer_Enable(volatile bool interrupt_enable, volatile uint8_t interrupt_priority)
Definition:
init_timer1.c:81
MAIN_EXEC_PER
#define MAIN_EXEC_PER
Global state-machine user-settings conversion macros.
Definition:
dpsk3_hwdescr.h:160
_OSTIMER_PRIORITY
#define _OSTIMER_PRIORITY
interrupt priority (1 ... 7, default = 2)
Definition:
dpsk3_hwdescr.h:178
_OSTIMER_IP
#define _OSTIMER_IP
interrupt priority register
Definition:
dpsk3_hwdescr.h:175
sysOsTimer_Initialize
volatile uint16_t sysOsTimer_Initialize(void)
Initializes the timer used as time-base for the task scheduler.
Definition:
init_timer1.c:40
_OSTIMER_IE
#define _OSTIMER_IE
interrupt enable bit
Definition:
dpsk3_hwdescr.h:176
dpsk_buck_vmc.X
sources
config
init
init_timer1.c
© 2021, Microchip Technology Inc.