Variable Timer assistance
Hi there, i'm very new to c programming and i have an assignment to create a datalogger. The datalogger is sample voltages at a set time (i've set it for every second) . Now i have completed this and got it to work on the microcontroller i am supposed to use however i've recently been told that i can also make the timer variable which i would like to experiment with however i have very little idea of how to do this. i imagine it would be along the lines of making an array and changing the frequency of sampling this way. any assistance would be appreciated.
Code:
#include <stdio.h>
#include <LPC23xx.H> /* LPC23xx definitions */
#include "adc.h"
/* Import external functions from Serial.c file */
extern void Serial_init (void);
int main (void)
{
int i = 0;
int clock = 0;
int ADC0value[ADC_NUM];
int pushbutton;
int x[20];
ADCInit( ADC_CLK );
Serial_init(); /* Init UART */
FIO2DIR &= ~(1<<10);
printf("Data Logger\n");
while(1)
{
for ( i = 0; i < ADC_NUM; )
{
T0MR0 = 1200000;
T0MCR = 3;
T0TCR = 1;
while(1)
{
//wait for pushbutton to be pressed
printf("Press the button now to begin sampling\n");
while ((FIO2PIN & (1<<10)) != 0 )
{
;
}
pushbutton ++;
FIO2PIN = pushbutton;
while ((FIO2PIN & (1<<10)) == 0 )
{
;
}
while(1)
{
/* Timer0 Enable */
if ((clock == 0) || (clock == 8))
{
ADC0value[i] = ADC0Read(i);
printf("ADC channel %d = %d\n", i, ADC0value[i]);
}
clock++;
if (clock == 8)
{
clock = 0;
}
// wait for the time period to elapse
while((T0IR & 0x01) == 0)
{
;
}
T0IR |= 0x01 ;
}
}
}
}
}