Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #include "msp430g2253.h"
  2. #include <stdbool.h>
  3. //timed interrupt every 10 seconds
  4. //check how many heartbeats
  5. //x6
  6. //send as display value
  7. //reset hb counter to 0
  8.  
  9.  
  10.  
  11.  
  12. // Variables
  13. int adc[1] = {0}; //Sets up an array of 10 integers and zero's the values
  14. int adcstore[100] = {0};
  15. int avg_adc = 0;
  16.  
  17. // Function prototypes
  18. void adc_Setup();
  19. void adc_Sam10();
  20.  
  21. int timercount = 0;
  22. int heartbeatcount = 0;
  23. int displayValue = 0;
  24.  
  25. void main()
  26. {
  27. int i = 0;
  28. bool beat = false;
  29. WDTCTL = WDTPW + WDTHOLD; // Stop WDT
  30. adc_Setup(); // Function call for adc_setup
  31.  
  32. while(1)
  33. {
  34. adc_Sam10(); // Function call for adc_samp
  35. if(adc[0] > 730 && !beat) {
  36. heartbeatcount++;
  37. beat = true;
  38. }
  39. if(adc[0] <= 630 && beat) {
  40. beat = false;
  41. }
  42. // _delay_cycles(100000);
  43. }
  44. }
  45.  
  46. // ADC10 interrupt service routine
  47. #pragma vector=ADC10_VECTOR
  48. __interrupt void ADC10_ISR(void)
  49. {
  50. __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
  51. }
  52.  
  53. // ADC set-up function
  54. void adc_Setup()
  55. {
  56. ADC10CTL1 = CONSEQ_2 + INCH_0; // Repeat single channel, A0
  57. ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE; // Sample & Hold Time + ADC10 ON + Interrupt Enable
  58. ADC10DTC1 = 0x01; // 100 conversions
  59. ADC10AE0 |= 0x01; // P1.0 ADC option select
  60. CCTL0 = CCIE; // CCR0 interrupt enabled
  61. TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode
  62. CCR0 = 62500; // 0.5 Hz
  63. }
  64.  
  65. // ADC sample conversion function
  66. void adc_Sam10()
  67. {
  68. ADC10CTL0 &= ~ENC; // Disable Conversion
  69. while (ADC10CTL1 & BUSY); // Wait if ADC10 busy
  70. ADC10SA = (int)adc; // Transfers data to next array (DTC auto increments address)
  71. ADC10CTL0 |= ENC + ADC10SC; // Enable Conversion and conversion start
  72. // __bis_SR_register(CPUOFF + GIE);// Low Power Mode 0, ADC10_ISR
  73. __bis_SR_register(GIE);// Low Power Mode 0, ADC10_ISR
  74.  
  75. }
  76.  
  77. #pragma vector=TIMER0_A0_VECTOR
  78. __interrupt void Timer_A (void)
  79. {
  80. timercount++;
  81. if(timercount >= 20) {
  82. displayValue = heartbeatcount * 6;
  83. heartbeatcount = 0;
  84. timercount = 0;
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement