Escolar Documentos
Profissional Documentos
Cultura Documentos
Set the clock to run at 40MhZ using the PLL and 16MHz external crystal
now initialize the Events and Services Framework and start it running
}
InitGPIO
{
Port B
Enable the clock to Port B
Set as digital
Set as outputs
Set as inputs
Port C
Enable the clock to Port C
Wait till clock for Port C is ready
Set as digital
Set as outputs
Set as inputs
Port D
Enable the clock to Port D
Wait till clock for Port B is ready
Set as digital
Set as outputs
Set as inputs
Port E
Clock enable for Port E included within function
Init analog inputs for magnetic line following and Sharp sensor
InitInterrupts
{
WIDE TIMER 0A
start by enabling the clock to the timer (Wide Timer 0)
we want to use the full 32 bit count, so initialize the Interval Load
register to 0xffff.ffff (its default value :-)
To set the event to rising edge, we need to modify the TAEVENT bits
in GPTMCTL. Rising edge = 00, so we clear the TAEVENT bits
Now Set up the port to do the capture (clock was enabled earlier)
start by setting the alternate function for Port C bit 4 (WT0CCP0)
now kick the timer off by enabling it and enabling the timer to
stall while stopped by the debugger
now kick the timer off by enabling it and enabling the timer to
stall while stopped by the debugger
we want to use the full 32 bit count, so initialize the Interval Load
register to 0xffff.ffff (its default value :-)
To set the event to rising edge, we need to modify the TBEVENT bits
in GPTMCTL. Rising edge = 00, so we clear the TBEVENT bits
Now Set up the port to do the capture (clock was enabled earlier)
start by setting the alternate function for Port C bit 7 (WT1CCP1)
now kick the timer off by enabling it and enabling the timer to
stall while stopped by the debugger
we want to use the full 32 bit count, so initialize the Interval Load
register to 0xffff.ffff (its default value :-)
we want to use the full 32 bit count, so initialize the Interval Load
register to 0xffff.ffff (its default value :-)
To set the event to rising edge, we need to modify the TAEVENT bits
in GPTMCTL. Rising edge = 00, so we clear the TAEVENT bits
To set the event to rising edge, we need to modify the TBEVENT bits
in GPTMCTL. Rising edge = 00, so we clear the TBEVENT bits
Now Set up the port to do the capture (clock was enabled earlier)
start by setting the alternate function for Port D bit 2 (WT3CCP0)
Now Set up the port to do the capture (clock was enabled earlier)
start by setting the alternate function for Port D bit 3 (WT3CCP1)
now kick the timer off by enabling it and enabling the timer to
stall while stopped by the debugger
now kick the timer off by enabling it and enabling the timer to
stall while stopped by the debugger
}
InitPWM
{
Enable the clock to Module 0 of PWM
Select the PWM clock as System Clock / 32
Wait until the clock has started
Disable PWM3 (PD0 and PD1) while initializing NOT USING PD1
program generators to go to 1 at rising compare A/B, 0 on falling compare A/B
Set period
Set value at which pin changes state
Set the Duty cycle on A by programming the compare value
to the required duty cycle of Period/2 - DesiredHighTime/2
Dont enable PWM output to flywheel (0V across leads when MOSFET is off)
Select alternate functions for PB6 and PB7 and PB4 and PB5
Map PWM to PB6 and PB7 and PB4 and PB5. 4 comes from Table 23-5 on Page 1351 of TIVA datasheet
Set PB6 and PB7 and PB4 and PB5 as digital
Set PB6 and PB7 and PB4 and PB5 as outputs
InitSPI
{
Enable the clock to the GPIO port A
Enable the clock to SSI module
Wait for the GPIO port to be ready
Program the GPIO to use the alternate functions on the SSI pins
Set mux position in GPIOPCTL to select the SSI use of the pins
Program the port lines for digital I/O
Program the required data directions on the port lines
If using SPI mode 3, program the pull-up on the clock line
Wait for the SSI0 to be ready
Make sure that the SSI is disabled before programming mode bits
Select master mode (MS) & TXRIS indicating End of Transmit (EOT)
Configure the SSI clock source to the system clock
Configure the clock pre-scaler: max frequency 961kHz
SSInClk = SysClk / (CPSDVSR *(1+SCR)), we want CPSDVSR*(1+SCR) > 2642 (CPSR = 54, SCR = 50)
Configure clock rate (SCR), phase & polarity (SPH, SPO), mode (FRF), data size (DSS)
Locally enable interrupts (TXIM in SSIIM)
Make sure that the SSI is enabled for operation
}