You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.1 KiB
55 lines
1.1 KiB
#include "muxer.h"
|
|
#include <avr/io.h>
|
|
|
|
|
|
/*****************
|
|
* themor-sensors are channels 0-3
|
|
*
|
|
* pt1000 is on channel 5
|
|
*/
|
|
|
|
void muxer_init(){
|
|
DDRC |= (_BV(0)|_BV(1)|_BV(2)|_BV(3)); // conf as outputs
|
|
PORTC |= _BV(3); // inhibit
|
|
// for good measure call the offset init, calling it twice doesn't hurt
|
|
offset_measure_init();
|
|
}
|
|
|
|
void muxer_set(uint8_t channel){
|
|
uint8_t selectbits = muxer_channel_to_selectbits(channel);
|
|
PORTC |= _BV(3); // engage inhibit
|
|
PORTC &= ~(0x07); //mask
|
|
PORTC |= selectbits & 0x07; //set
|
|
PORTC &= ~(_BV(3)); // disengage inhibit
|
|
//TODO: delays, check everything, mask in register
|
|
}
|
|
|
|
|
|
uint8_t inline muxer_channel_to_selectbits(uint8_t channel){
|
|
static uint8_t table[] = {2,1,0,3};
|
|
if(channel>=4){
|
|
return 0;
|
|
}
|
|
return(table[channel]);
|
|
}
|
|
|
|
void offset_measure_init(){
|
|
DDRD |= 0x0f; // first 4 pins as output
|
|
// PORTD = 0x00; // turn everything off
|
|
}
|
|
|
|
void offset_measure_start(uint8_t channel){
|
|
if(channel > 3){
|
|
return;
|
|
}
|
|
PORTD |= (1<<channel);
|
|
}
|
|
|
|
void offset_measure_start_all(){
|
|
PORTD |= 0x0f;
|
|
}
|
|
|
|
void offset_measure_stop(){
|
|
PORTD &= ~0x0f;
|
|
}
|