BeRTOS
Functions
ntc.c File Reference

Driver for NTC (reads a temperature through an ADC) More...

#include "hw/hw_ntc.h"
#include "hw/ntc_map.h"
#include "cfg/cfg_ntc.h"
#include <cfg/log.h>
#include <cfg/debug.h>
#include <drv/ntc.h>

Go to the source code of this file.

Functions

static size_t upper_bound (const res_t *orig_table, size_t size, res_t val)
 Find in a table of values orig_table of size size, the index which value is less or equal to val.
deg_t ntc_read (NtcDev dev)
 Read the temperature for the NTC channel dev.
void ntc_init (void)
 Init NTC hardware.

Detailed Description

Driver for NTC (reads a temperature through an ADC)

Author:
Giovanni Bajo <rasky@develer.com>
Francesco Sacchi <batt@develer.com>

This module handles an external NTC bound to an AD converter. As usual, it relies on a low-level API (ntc_hw_*) (see below):

Definition in file ntc.c.


Function Documentation

void ntc_init ( void  )

Init NTC hardware.

Initialize the NTC module.

Definition at line 149 of file ntc.c.

deg_t ntc_read ( NtcDev  dev)

Read the temperature for the NTC channel dev.

Read a single temperature value from the NTC.

First read the resistence of the NTC through ntc_hw_read(), then, for the conversion from resistance to temperature, since the formula varies from device to device, we implemented a generic system using a table of data which maps temperature (index) to resistance (data). The range of the table (min/max temperature) and the step (temperature difference between two consecutive elements of the table) is variable and can be specified. Notice that values inbetween the table elements are still possible as the library does a linear interpolation using the actual calculated resistance to find out the exact temperature.

The low-level API provides a function to get access to a description of the NTC (ntc_hw_getInfo()), including the resistance table.

Definition at line 104 of file ntc.c.

static size_t upper_bound ( const res_t *  orig_table,
size_t  size,
res_t  val 
) [static]

Find in a table of values orig_table of size size, the index which value is less or equal to val.

Return values:
0When val is higher than the first table entry.
sizeWhen val is lower than the last table entry.
1..size-1When val is within the table.

Definition at line 67 of file ntc.c.