voltage.c File Reference

#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "voltage.h"
#include "util.h"
#include <stdio.h>
Include dependency graph for voltage.c:

Functions

void pump_init ()
void pump_nomoar ()
 Terminate boost converter operation.
void pump_faster (int8_t dfreq)
void adc_init ()
void voltage_start ()
 Start voltage booster.
uint16_t voltage_getbcd ()
uint16_t voltage_get ()
void voltage_set (uint16_t setpoint)
 set voltage setpoint
uint16_t voltage_setpoint_get ()
 ISR (ADC_vect)

Variables

volatile uint16_t voltage
 voltage (magic units)

Function Documentation

void adc_init (  ) 

00044                 {
00045     voltage = 0;
00046     
00047     // PORTA.7 is the feedback input, AREF = AREF pin
00048     ADMUX = 7;  
00049     //DDRA &= ~_BV(7);
00050 
00051     // ADC enable, autotrigger, interrupt enable, prescaler = 111 (divide by 32)
00052     ADCSRA = BV6(ADEN, ADFR, ADIE, ADPS2, ADPS1, ADPS0); 
00053     //ADCSRA = BV5(ADEN, ADIE, ADPS2, ADPS1, ADPS0); 
00054 
00055     ADCSRA |= _BV(ADSC); 
00056 }

ISR ( ADC_vect   ) 

00080               {
00081     voltage = (voltage + ADC) / 2;
00082     if (voltage < voltage_setpoint) {
00083         OCR1A = ocr1a_reload;
00084     } else {
00085         OCR1A = 0;
00086     }
00087 }

void pump_faster ( int8_t  dfreq  ) 

00040                                {
00041     ICR1 += dfreq;
00042 }

void pump_init (  ) 

00014                  {
00015     // set fast pwm mode
00016     // COM1A1:0 = 10, clear oc1a on compare match, set at top
00017     // COM1B1:0 = 00, normal port operation
00018     // no FOC
00019     // WGM11:10 (WGM = Fast PWM, TOP=ICR1: 1110) = 11
00020     TCCR1A = BV2(COM1A1, WGM11);
00021     TCCR1B = BV2(WGM13,WGM12);
00022     
00023     OCR1A = ocr1a_reload; 
00024     ICR1 = 170;
00025     
00026     TCCR1B |= _BV(CS10); // clk/1 = 8MHz
00027     
00028     DDRHVPUMP |= BV2(1,2);
00029 }

void pump_nomoar (  ) 

Terminate boost converter operation.

00031                    {
00032     ADCSRA = 0;
00033     ADCSRA |= _BV(ADIF); 
00034 
00035     ICR1 = 255;
00036     OCR1A = 0;
00037     OCR1B = OCR1A;
00038 }

uint16_t voltage_get (  )  [inline]

00070                               {
00071     return voltage;
00072 }

uint16_t voltage_getbcd (  ) 

00064                           {
00065     // 1024 = 500V
00066     uint16_t val = (voltage * 32) / 65;
00067     return tobcd16(val);
00068 }

Here is the call graph for this function:

void voltage_set ( uint16_t  setpoint  ) 

set voltage setpoint

00074                                     {
00075     voltage_setpoint = setpoint;
00076 }

uint16_t voltage_setpoint_get (  )  [inline]

00078 { return voltage_setpoint; }

void voltage_start (  ) 

Start voltage booster.

00059                      {
00060     adc_init();
00061     pump_init();
00062 }

Here is the call graph for this function:


Variable Documentation

volatile uint16_t voltage

voltage (magic units)


Generated on Wed Jan 27 00:30:00 2010 for Patashnik by  doxygen 1.6.1