second try: adc interrupt
This commit is contained in:
parent
907fb78d62
commit
89a2aa041c
12
src/debug.txt
Normal file
12
src/debug.txt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// P1OUT |= BIT1;
|
||||||
|
// for (uint8_t i = 0; i < 16; i++) {
|
||||||
|
// P1OUT |= BIT3;
|
||||||
|
// uint16_t x = newPwm >> i;
|
||||||
|
// if ((x & 1) == 1) {
|
||||||
|
// P1OUT |= BIT2;
|
||||||
|
// } else {
|
||||||
|
// P1OUT &= ~BIT2;
|
||||||
|
// }
|
||||||
|
// P1OUT &= ~BIT3;
|
||||||
|
// }
|
||||||
|
// P1OUT &= ~BIT1;
|
@ -11,7 +11,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "pwm.h"
|
#include "pwm.h"
|
||||||
#include "adc.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -31,7 +30,6 @@ void init() {
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
init();
|
init();
|
||||||
adcInit();
|
|
||||||
pwmInit();
|
pwmInit();
|
||||||
|
|
||||||
__enable_interrupt();
|
__enable_interrupt();
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#define PARAMS_H_
|
#define PARAMS_H_
|
||||||
|
|
||||||
|
|
||||||
|
const uint32_t ADC_TIME_OUT = 100000;
|
||||||
|
const uint16_t ADC_MAX = 511;
|
||||||
|
|
||||||
const float Ctrl_P = 10.0;
|
const float Ctrl_P = 10.0;
|
||||||
const float Ctrl_I = 5.0;
|
const float Ctrl_I = 5.0;
|
||||||
|
34
src/pwm.cpp
34
src/pwm.cpp
@ -11,7 +11,6 @@
|
|||||||
#include "pwm.h"
|
#include "pwm.h"
|
||||||
#include "control.h"
|
#include "control.h"
|
||||||
#include "params.h"
|
#include "params.h"
|
||||||
#include "adc.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -24,6 +23,10 @@ volatile uint16_t newPwm = 0;
|
|||||||
|
|
||||||
|
|
||||||
void pwmInit() {
|
void pwmInit() {
|
||||||
|
ADC10CTL0 = ADC10SHT_0 | ADC10ON | SREF_0 | ADC10IE;
|
||||||
|
ADC10CTL1 = INCH_7 | ADC10SSEL_3 | ADC10DIV_2;
|
||||||
|
ADC10AE0 = BIT7;
|
||||||
|
|
||||||
P1DIR |= BIT6;
|
P1DIR |= BIT6;
|
||||||
P1SEL |= BIT6;
|
P1SEL |= BIT6;
|
||||||
P1OUT = 0;
|
P1OUT = 0;
|
||||||
@ -37,15 +40,12 @@ void pwmInit() {
|
|||||||
|
|
||||||
|
|
||||||
ISR(TIMER0_A0, TA0_ISR) {
|
ISR(TIMER0_A0, TA0_ISR) {
|
||||||
static uint8_t cycleCnt = 0;
|
ADC10CTL0 |= ENC | ADC10SC;
|
||||||
cycleCnt++;
|
}
|
||||||
|
|
||||||
if (cycleCnt >= CYCLE_DELAY) {
|
|
||||||
cycleCnt = 0;
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t adcIn = adcGet();
|
|
||||||
|
|
||||||
|
ISR(ADC10, ADC_ISR) {
|
||||||
|
uint16_t adcIn = ADC10MEM;
|
||||||
|
adcIn >>= 1;
|
||||||
|
|
||||||
float u_adc = ((float)adcIn) * U_ref / ((float)ADC_MAX);
|
float u_adc = ((float)adcIn) * U_ref / ((float)ADC_MAX);
|
||||||
u_curr = u_adc * (R_top + R_bottom) / R_bottom;
|
u_curr = u_adc * (R_top + R_bottom) / R_bottom;
|
||||||
@ -53,24 +53,8 @@ ISR(TIMER0_A0, TA0_ISR) {
|
|||||||
float newPwm_f = ctrl.cycle(u_des, u_curr);
|
float newPwm_f = ctrl.cycle(u_des, u_curr);
|
||||||
newPwm = (uint16_t) newPwm_f;
|
newPwm = (uint16_t) newPwm_f;
|
||||||
|
|
||||||
// P1OUT |= BIT1;
|
|
||||||
// for (uint8_t i = 0; i < 16; i++) {
|
|
||||||
// P1OUT |= BIT3;
|
|
||||||
// uint16_t x = newPwm >> i;
|
|
||||||
// if ((x & 1) == 1) {
|
|
||||||
// P1OUT |= BIT2;
|
|
||||||
// } else {
|
|
||||||
// P1OUT &= ~BIT2;
|
|
||||||
// }
|
|
||||||
// P1OUT &= ~BIT3;
|
|
||||||
// }
|
|
||||||
// P1OUT &= ~BIT1;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TACCR1 = newPwm;
|
TACCR1 = newPwm;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
float getDutyCycle() {
|
float getDutyCycle() {
|
||||||
__disable_interrupt();
|
__disable_interrupt();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user