Difference between revisions of "Internal Oscillator"

From Flowcode Help
Jump to navigationJump to search
 
(7 intermediate revisions by 6 users not shown)
Line 3: Line 3:
 
The device datasheet should detail the type of oscillator available to the device.
 
The device datasheet should detail the type of oscillator available to the device.
  
Here we have the datasheet for the PIC16F88 device listing the options available for the internal oscillator.
+
To control the internal oscillator speed, a c code block will require adding at the very top of main, so its the first icon to be accessed.  
  
[[File:16F88OscCon.jpg]]
+
Luckily, we don't need to dive into the datasheet to work out the code to set the internal oscillator to the correct speed.
  
 +
The is an '''Internal Oscillator Helper''' component which is located in '''Components Libraries''' > '''Matrix Tools''' > '''IntOsc Helper'''
 +
Alternatively, Use the search magnifying glass option.
  
Using a C code icon at the very top of the Main macro we can specify which speed the microcontroller should start-up with.
+
This can be found on left of the '''Components Libraries''' and enter '''intos''' in the search bar.  
  
 +
[[file:InOscHelper1.png]]
  
To access a register using PIC use the register name in all lower case. e.g. "osccon"
+
'''Setting the hardware at the correct speed for PIC16F18877'''
  
For the PIC16 and AVR use the register name in all upper case. e.g. "OSCCON"
+
1. '''Build''' > '''Project Options...''' '''Other options''' > Clock speed (MHZ) [defines delay-related timings] & enter desired speed, e.g. 16MHz. This does not set the hardware speed, but it's required step.
 +
The '''Configure''' settings  must also be correct.
  
Remember to end the line of C code with a semicolon to mark the end of the instruction.
+
E.g '''External Oscillator''' > '''Oscillator Off'''
  
 +
'''Software Oscillator''' > '''HFINTOSC 32MHz'''
  
Here is an example to configure the internal oscillator to 8MHz on the PIC16F88.
+
2. Add '''IntOsc Helper''' to the 2D panel, right-click on the IntOsc Helper component and select properties.  
  
[[File:16F88IntOsc1.jpg]]
+
3. Enter the required speed in Hz e.g 1600000
  
 +
4. Copy the full contents next to the code window (OSCFRQ = 0x05;)
  
Here is an example to configure the internal oscillator to 1MHz on the PIC16F88.
+
5. add a C code command icon at the top of Main and paste the code that was copied in step 4
  
[[File:16F88IntOsc2.jpg]]
+
[[file:InOscHelper2.png]]
  
 +
The internal osc should now be set at 16NHz, assuming all the configuration settings are correct.
  
Be sure to set the clock speed in the project options to the same speed to allow your delays and any communications baud rates to be correct.
+
You should be aware that other target device use OSCCON instead of OSCFRQ, but the IntOsc Helper allows for that.
  
[[File:16F88IntOscProj.jpg]]
+
 
 +
A [[One second LED flasher]] test can be very useful to confirm if your device is actually running at the intended speed.

Latest revision as of 15:04, 5 October 2023

A lot of the devices have an inbuilt oscillator which can be used to reduce the number of devices required to drive the microcontroller.

The device datasheet should detail the type of oscillator available to the device.

To control the internal oscillator speed, a c code block will require adding at the very top of main, so its the first icon to be accessed.

Luckily, we don't need to dive into the datasheet to work out the code to set the internal oscillator to the correct speed.

The is an Internal Oscillator Helper component which is located in Components Libraries > Matrix Tools > IntOsc Helper Alternatively, Use the search magnifying glass option.

This can be found on left of the Components Libraries and enter intos in the search bar.

InOscHelper1.png

Setting the hardware at the correct speed for PIC16F18877

1. Build > Project Options... Other options > Clock speed (MHZ) [defines delay-related timings] & enter desired speed, e.g. 16MHz. This does not set the hardware speed, but it's required step. The Configure settings must also be correct.

E.g External Oscillator > Oscillator Off

Software Oscillator > HFINTOSC 32MHz

2. Add IntOsc Helper to the 2D panel, right-click on the IntOsc Helper component and select properties.

3. Enter the required speed in Hz e.g 1600000

4. Copy the full contents next to the code window (OSCFRQ = 0x05;)

5. add a C code command icon at the top of Main and paste the code that was copied in step 4

InOscHelper2.png

The internal osc should now be set at 16NHz, assuming all the configuration settings are correct.

You should be aware that other target device use OSCCON instead of OSCFRQ, but the IntOsc Helper allows for that.


A One second LED flasher test can be very useful to confirm if your device is actually running at the intended speed.