Question

In: Computer Science

Embedded computer systems: Configure and code clock for Pic24e referring to the example C code given...

Embedded computer systems:

Configure and code clock for Pic24e referring to the example C code given below.

a) Write code on how to configure bits that uses its fast RC oscillator with PLL to run at 40MHz. Assume the RC's frequency is 7.5MHz.

b) Write code on how to configure bits that uses its primary crystal (XT) with PLL to run at 40MHz. Assume the external clock is a crystal oscillator of 8MHz.

====== Given C Code =======

#include "ConfigurationBits.h"

void initializeSystem() {

// Configure the device PLL to obtain 60 MIPS operation. The crystal

// frequency is 8MHz. Divide 8MHz by 2, multiply by 60 and divide by

// 2. This results in Fosc of 120MHz. The CPU clock frequency is

// Fcy = Fosc/2 = 60MHz.

PLLFBD = 58; /* M = 60 */

CLKDIVbits.PLLPRE = 0; /* N1 = 2 */

CLKDIVbits.PLLPOST = 0; /* N2 = 2 */

/* Initiate Clock Switch to Primary

* Oscillator with PLL (NOSC= 0x3)*/

__builtin_write_OSCCONH(0x03);

__builtin_write_OSCCONL(0x01);

while (OSCCONbits.COSC != 0x3);

// Wait for PLL to lock

while (OSCCONbits.LOCK != 1);

}

Solutions

Expert Solution

//Main.c
#include <stdint.h>
#include "Compiler.h"
#include "ConfigurationBits.h"

// leds are connected to port D1..3

void initLeds() {
    TRISD &= 0xFFF1;
}

void ledOn(uint8_t sel) {
    LATD |= 1<<(sel+1);
}

void ledOff(uint8_t sel) {
    LATD &= ~(1<<(sel+1));
}

void ledToggle(uint8_t sel) {
    LATD ^= (1<<(sel+1));
}

void ledSet(uint8_t val) {
    LATD = (LATD & 0xFFF1) | ((val & 0x7) <<1);
}

int main() {
    initLeds();
    ledOn(1);
    ledOff(1);
    ledToggle(1);
    ledSet(5);
    return 0;
}
// PIC24EP512GU810 Configuration Bit Settings

// 'C' source line config statements

#include <xc.h>

// FGS
#pragma config GWRP = OFF               // General Segment Write-Protect bit (General Segment may be written)
#pragma config GSS = OFF                // General Segment Code-Protect bit (General Segment Code protect is disabled)
#pragma config GSSK = OFF               // General Segment Key bits (General Segment Write Protection and Code Protection is Disabled)

// FOSCSEL
#pragma config FNOSC = FRC              // Initial Oscillator Source Selection bits (Internal Fast RC (FRC))
#pragma config IESO = ON                // Two-speed Oscillator Start-up Enable bit (Start up device with FRC, then switch to user-selected oscillator source)

// FOSC
#pragma config POSCMD = XT              // Primary Oscillator Mode Select bits (XT Crystal Oscillator Mode)
#pragma config OSCIOFNC = OFF           // OSC2 Pin Function bit (OSC2 is clock output)
#pragma config IOL1WAY = OFF            // Peripheral pin select configuration (Allow multiple reconfigurations)
#pragma config FCKSM = CSECMD           // Clock Switching Mode bits (Clock switching is enabled,Fail-safe Clock Monitor is disabled)

// FWDT
#pragma config WDTPOST = PS32768        // Watchdog Timer Postscaler bits (1:32,768)
#pragma config WDTPRE = PR128           // Watchdog Timer Prescaler bit (1:128)
#pragma config PLLKEN = ON              // PLL Lock Wait Enable bit (Clock switch to PLL source will wait until the PLL lock signal is valid.)
#pragma config WINDIS = OFF             // Watchdog Timer Window Enable bit (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = ON              // Watchdog Timer Enable bit (Watchdog timer always enabled)

// FPOR
#pragma config FPWRT = PWR128           // Power-on Reset Timer Value Select bits (128ms)
#pragma config BOREN = ON               // Brown-out Reset (BOR) Detection Enable bit (BOR is enabled)
#pragma config ALTI2C1 = OFF            // Alternate I2C pins for I2C1 (SDA1/SCK1 pins are selected as the I/O pins for I2C1)
#pragma config ALTI2C2 = OFF            // Alternate I2C pins for I2C2 (SDA2/SCK2 pins are selected as the I/O pins for I2C2)

// FICD
#pragma config ICS = PGD1               // ICD Communication Channel Select bits (Communicate on PGEC1 and PGED1)
#pragma config RSTPRI = PF              // Reset Target Vector Select bit (Device will obtain reset instruction from Primary flash)
#pragma config JTAGEN = OFF             // JTAG Enable bit (JTAG is disabled)

// FAS
#pragma config AWRP = OFF               // Auxiliary Segment Write-protect bit (Aux Flash may be written)
#pragma config APL = OFF                // Auxiliary Segment Code-protect bit (Aux Flash Code protect is disabled)
#pragma config APLK = OFF               // Auxiliary Segment Key bits (Aux Flash Write Protection and Code Protection is Disabled)

Related Solutions

After making a programming change in a major bank's computer systems, an employee forgot to configure...
After making a programming change in a major bank's computer systems, an employee forgot to configure the system correctly, resulting in 800,000 direct deposit requests not being posted until the next day. Is this computer error? If you were the bank president, how would you describe this problem?
Write the C code required to configure pin 0 on port B to be an input...
Write the C code required to configure pin 0 on port B to be an input with the pullup resistor enabled.
A pragma and an intrinsic function are both statements embedded in C source code. What is...
A pragma and an intrinsic function are both statements embedded in C source code. What is the primary difference in how the compiler handles these two types statements?
The following 3 instances of code was provided by my embedded systems course. Can you explain...
The following 3 instances of code was provided by my embedded systems course. Can you explain what is happening in each code segment? === code 1 === void foo() { uint8_t a=2; uint8_t b[]={b0, b1, b2}; // They are the last three digits of your A# uint8_t* c=b; uint8_t* d=&a; } === code 2 === __extension__ typedef struct tagT1CONBITS { union { struct { unsigned :1; unsigned TCS:1; unsigned TSYNC:1; unsigned :1; unsigned TCKPS:2; unsigned TGATE:1; unsigned :6; unsigned TSIDL:1;...
Can someone explain how to manipulate the clock in verilog code? For example, I do not...
Can someone explain how to manipulate the clock in verilog code? For example, I do not understand how to go from 100MHz to 68027Hz.
You are required to develop a computer code that that can solve systems of ODE. The...
You are required to develop a computer code that that can solve systems of ODE. The code should request the user to choose one of the following methods for solving the system: ? Euler ? 4th Order Runge Kutta  
Write Algoritm , code and output. In C++ In Operating Systems , Simulate with a program...
Write Algoritm , code and output. In C++ In Operating Systems , Simulate with a program to schedule disk in seek optimization.
code in c++ using the code given add a hexadecimal to binary converter and add a...
code in c++ using the code given add a hexadecimal to binary converter and add a binary to hexadecimal converter #include <iostream> #include <string> #include<cmath> #include<string> using namespace std; int main() { string again; do { int userChoice; cout << "Press 2 for Decimal to Binary"<< endl; cout << "Press 1 for Binary to Decimal: "; cin >> userChoice; if (userChoice == 1) { long n; cout << "enter binary number" << endl; cin>>n; int decnum=0, i=0, remainder; while(n!=0) {...
Code in C++ please You are going to write a program for Computer test which will...
Code in C++ please You are going to write a program for Computer test which will read 10 multiple choice questions from a file, order them randomly and provide the test to the user. When the user done the program must give the user his final score
The weighted voting systems for the voters A, B, C, ... are given in the form...
The weighted voting systems for the voters A, B, C, ... are given in the form q: w1, w2, w3, w4, ..., wn . The weight of voter A is w1, the weight of voter B is w2, the weight of voter C is w3, and so on. Calculate, if possible, the Banzhaf power index for each voter. Round to the nearest hundredth. (If not possible, enter IMPOSSIBLE.) {82: 53, 36, 24, 18} BPI(A) = BPI(B) = BPI(C) = BPI(D)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT