GlobLib
HAL and API libraries for MCUs and hardware.

This module contains low level functions modifying clock parameters. More...

Files

file  attiny13a_clock.h
 Header file for attiny13a CLOCK.
 

Macros

#define CLOCK_BASE   9.6e6
 Maximum clock speed for internal RC oscillator.
 
#define CLOCK_DIV_64   F_CPU/64
 Clock speed divided by 64.
 
#define CLOCK_DIV_1024   F_CPU/1024
 Clock speed divided by 1024.
 

Functions

uint32_t CLOCK_getSpeed (void)
 Get the current clock speed of the device. More...
 
uint8_t CLOCK_getSpeedAlternate (void)
 Get the current clock divisor. More...
 

Detailed Description

This module contains low level functions modifying clock parameters.

There are four options for clock speeds on the ATTiny13A using the internal RC oscillator. This speed is set by CLOCK parameter in the ** Makefile **. Although it is possible to adjust the clock speed using software. This module doesn't include this function.

The four available clock speeds are

Note that lower clock speeds result in lower power consumption.

Clock speeds have effects on the following modules:

Their documentation details the effects.

Author
Stuart Ianna
Version
0.1
Date
October 2018
Warning
Clock speed needs to be set in the Makefile.
Bug:
Compilers
  • avr-gcc 4.9.2
Example Usage
#include <stm32f103cb_core.h>
#include <coms128.h>
#include <mpu6050.h>
//Create a data structure for the device
MPU6050 mpu;
int main(void)
{
//This should be done before other peripherals are set up
CLOCK_setSpeed(CLOCK_EX_8_OUT_72);
//Serial communications
USART_setup(USART_1);
COMS(USART_1);
//Print out clock freuqency
prints("Clock speed =");
printl(CLOCK_getSpeed());
//Done
while (1);
return 0;
}

Function Documentation

uint32_t CLOCK_getSpeed ( void  )

Get the current clock speed of the device.

Returns
The current speed of the CPU bus in hertz. (Clock frequency)

Definition at line 19 of file attiny13a_clock.c.

uint8_t CLOCK_getSpeedAlternate ( void  )

Get the current clock divisor.

This can be used to return the clock divisor for division in the main application.

A sample usage of this application is in delayms() of attiny13a_core.h

Returns
The current speed of the CPU clock bus.
  • CPU = 9.6MHz - Divisor = 1
  • CPU = 4.8MHz - Divisor = 2
  • CPU = 1.2MHz - Divisor = 8
  • CPU = 0.6MHz - Divisor = 16

Definition at line 26 of file attiny13a_clock.c.