Hello all. I was just wondering if someone can help post some tips for my project. My project involves a flex sensor (potentiometer that ranges from 60k to 100k ohms). Using external circuitry to send various voltage levels (from changes in the potentiometer) to the micro. I want to perform ADC on these voltage readings (0-2V). Then based on these voltage readings I want to implement PWM to drive a servo. The servo can function between 600us to 2400us.
I want to set it up such that:
In addition to these settings, I want every resistance in-between (the entire range of 60k-100k). One of my main problems is that I don’t know how to direct the reading from ADC (what port does that reading comes in on?) to begin PWM? Also, I’m not sure how to setup PWM. I know it involves timers but I don’t know much more than that.
Any/all help is much appreciated.
Also, below is my setup code for ADC. Comments appreciated on this as well.
#include <MSP430xg46x.h>
#include "intrinsics.h"
#include "io430.h"
#include "header_file.h"
//--- MAIN ---//
int main (void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog
//--- ADC --//
ADC12CTL0 = ADC12ON | REFON | REF2_5V | SHT0_7; // ADC12ON = enables ADC12
// REFON = enables reference voltage (for testing purposes)
// REF2_5V = 2.5 reference voltage
// SHT0_7 = 2^7 = 128 cycles
ADC12CTL1 = SHS0 | SHP | ADC12DIV0 | ADC12SSEL0 | CONSEQ0 ;
// SHS0 = ADC12OSC internal timer bit
// SHP = Sample/Hold Pulse Mode
// ADC12DIV0 = No clock divisions
// ADC12SSEL0 = ADC12OSC as source
// CONSEQ0 = Single-channel single-conversion
ADC12IE = BIT0; // Enable interrupt on bit0
ADC12MEM0 = ZERO; // Clear mem
asm (" EINT"); // Enable global interrupts
}