Difference between revisions of "Internal Oscillator"

From Flowcode Help
Jump to navigationJump to search
 
(10 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.  
  
Here is an example to configure the internal oscillator to 8MHz on the PIC16F88.
+
[[file:InOscHelper1.png]]
  
[[File:16F88IntOsc1.jpg]]
+
'''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.
  
Here is an example to configure the internal oscillator to 1MHz on the PIC16F88.
+
E.g '''External Oscillator''' > '''Oscillator Off'''
  
[[File:16F88IntOsc2.jpg]]
+
'''Software Oscillator''' > '''HFINTOSC 32MHz'''
  
 +
2. Add '''IntOsc Helper''' to the 2D panel, right-click on the IntOsc Helper component and select properties.
  
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.
+
3. Enter the required speed in Hz e.g 1600000
  
[[File:16F88IntOscProj.jpg]]
+
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
 +
 
 +
[[file: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.

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.