Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "msp430g2253.h"
- #include <stdbool.h>
- //timed interrupt every 10 seconds
- //check how many heartbeats
- //x6
- //send as display value
- //reset hb counter to 0
- // Variables
- int adc[1] = {0}; //Sets up an array of 10 integers and zero's the values
- int adcstore[100] = {0};
- int avg_adc = 0;
- // Function prototypes
- void adc_Setup();
- void adc_Sam10();
- int timercount = 0;
- int heartbeatcount = 0;
- int displayValue = 0;
- void main()
- {
- int i = 0;
- bool beat = false;
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- adc_Setup(); // Function call for adc_setup
- while(1)
- {
- adc_Sam10(); // Function call for adc_samp
- if(adc[0] > 730 && !beat) {
- heartbeatcount++;
- beat = true;
- }
- if(adc[0] <= 630 && beat) {
- beat = false;
- }
- // _delay_cycles(100000);
- }
- }
- // ADC10 interrupt service routine
- #pragma vector=ADC10_VECTOR
- __interrupt void ADC10_ISR(void)
- {
- __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
- }
- // ADC set-up function
- void adc_Setup()
- {
- ADC10CTL1 = CONSEQ_2 + INCH_0; // Repeat single channel, A0
- ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE; // Sample & Hold Time + ADC10 ON + Interrupt Enable
- ADC10DTC1 = 0x01; // 100 conversions
- ADC10AE0 |= 0x01; // P1.0 ADC option select
- CCTL0 = CCIE; // CCR0 interrupt enabled
- TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode
- CCR0 = 62500; // 0.5 Hz
- }
- // ADC sample conversion function
- void adc_Sam10()
- {
- ADC10CTL0 &= ~ENC; // Disable Conversion
- while (ADC10CTL1 & BUSY); // Wait if ADC10 busy
- ADC10SA = (int)adc; // Transfers data to next array (DTC auto increments address)
- ADC10CTL0 |= ENC + ADC10SC; // Enable Conversion and conversion start
- // __bis_SR_register(CPUOFF + GIE);// Low Power Mode 0, ADC10_ISR
- __bis_SR_register(GIE);// Low Power Mode 0, ADC10_ISR
- }
- #pragma vector=TIMER0_A0_VECTOR
- __interrupt void Timer_A (void)
- {
- timercount++;
- if(timercount >= 20) {
- displayValue = heartbeatcount * 6;
- heartbeatcount = 0;
- timercount = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement