hi everyone
I am realy not gud programmer.I am trying to make dc postion control system.i am using vee pro software inwhich i hav implemented PID algorithm so now I want to use arduino as data acquisition device which sends and receives data.i have mixed up two individual sketches which sends and receives data.but it wont work
wht should be the reason?
the code is as follows
#include <avr/io.h>
#include <avr/interrupt.h>
#define BAUD_RATE 115200
#define INPUT_PIN 3
#define LED_PIN 13
//#define TEST_MODE // comment out to read analog pin, uncomment for test ramp wave
volatile int j;
int ledPin=9;
int val;
void setup()
{
pinMode(ledPin,OUTPUT);
Serial.begin(BAUD_RATE);
pinMode(LED_PIN, OUTPUT);
cli(); // disable interrupts while messing with their settings
TCCR1A = 0x00; // clear default timer settings, this kills the millis() funciton
TCCR1B = 0x00;
TCCR1B |= (1 << WGM12); // Configure timer 1 for CTC mode
TCCR1B |= (0 << CS12); // Set timer prescaling by setting 3 bits
TCCR1B |= (1 << CS11); // 001=1, 010=8, 011=64, 101=1024
TCCR1B |= (1 << CS10);
TIMSK1 |= (1 << OCIE1A); // Enable CTC interrupt
OCR1A = 50; // Set CTC compare value
sei(); // turn interrupts back on
}
void loop() {if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255)
val = Serial.read();
// set the brightness of the LED
analogWrite(ledPin, val);
}
// nothing to do, its all in the interrupt handler!
}
ISR(TIMER1_COMPA_vect) // when timer counts down it fires this interrupt
{
#ifdef TEST_MODE
//Serial.print((j%64)*4 , DEC); // test mode, generate a ramp wave
j++;
#else
Serial.println( analogRead(INPUT_PIN), DEC); // real mode, sample analog pin
#endif
}
can anyone having any other idea?
thank you all in advance