Hi,
I’ve gotten the ucontroller reset problem fixed. However, my readings from the lastHighPulse of the struct PulseInputStruct does not make sense. I am expecting values that increase or decrease corresponding to the physical turn of the encoder clockwise and counterclockwise. What I am getting is a value that keeps incrementing like a timer, independent of the encoder. Is there more documentation on the Orangutan PWM functions that just pololu.com/docs/0J18/8
main.c
[code]struct abs_enc enc1; //data structure representing encoder values
struct abs_enc enc2; //data structure representing encoder values
volatile struct PulseInputStruct pd_4; //struct containing PWM values
volatile struct PulseInputStruct pd_6; //struct containing PWM values
int main (void) {
pulse_in_start((unsigned char[]) {IO_D4, IO_D6}, 2);
while(1) {
get_pulse_info(0, &pd_4);
get_pulse_info(1, &pd_6);
read_abs_enc(&pd_4, &enc1, 0);
read_abs_enc(&pd_6, &enc2, 1);
…}}[/code]
encoder.h
struct abs_enc {
volatile unsigned long travel; //represents encoder travel since last reset [counts]
volatile unsigned long cur_pulse_width;
volatile unsigned long past_pulse_width;
};
void set_abs_encoder (struct abs_enc *enc, struct PulseInputStruct *pulse); //sets encoder values
void set_abs_encoder2 (struct abs_enc *enc, struct PulseInputStruct *pulse);
void read_abs_enc (struct PulseInputStruct *pulse, struct abs_enc *enc, unsigned char ch);
encoder.c
[code]void set_abs_encoder (struct abs_enc *enc, struct PulseInputStruct *pulse) {
if(enc->past_pulse_width == pulse->lastHighPulse) {
lcd_goto_xy(0, 2);
//print(“Same!”);
//printf("%08lu", enc->past_pulse_width);
printf(" %08lu", pulse->lastHighPulse);
enc->past_pulse_width = pulse->lastHighPulse;
enc->travel = enc->travel;
} else if(pulse->lastHighPulse > enc->past_pulse_width) {
direction = 1;
lcd_goto_xy(0, 2);
//printf("%d", direction);
//printf("%08lu", enc->past_pulse_width);
printf(" %08lu", pulse->lastHighPulse);
enc->past_pulse_width = pulse->lastHighPulse;
} else {
direction = 0;
lcd_goto_xy(0, 2);
printf("%d", direction);
//printf("%08lu",enc-> past_pulse_width);
printf(" %08lu", pulse->lastHighPulse);
enc->past_pulse_width = pulse->lastHighPulse;
}
if(direction == 1) {
enc->travel = enc->travel + ticks_to_microseconds(pulse->lastHighPulse);
} else {
enc->travel = enc->travel - ticks_to_microseconds(pulse->lastHighPulse);
}
}
void set_abs_encoder2 (struct abs_enc *enc, struct PulseInputStruct *pulse) {
if(enc->past_pulse_width == pulse->lastHighPulse) {
lcd_goto_xy(0, 3);
//print(“Same!”);
//printf("%08lu", enc->past_pulse_width);
printf(" %08lu", pulse->lastHighPulse);
enc->past_pulse_width = pulse->lastHighPulse;
enc->travel = enc->travel;
} else if(pulse->lastHighPulse > enc->past_pulse_width) {
direction = 1;
lcd_goto_xy(0, 3);
//printf("%d", direction);
//printf("%08lu", enc->past_pulse_width);
printf(" %08lu", pulse->lastHighPulse);
enc->past_pulse_width = pulse->lastHighPulse;
} else {
direction = 0;
lcd_goto_xy(0, 3);
//printf("%d", direction);
//printf("%08lu",enc-> past_pulse_width);
printf(" %08lu", pulse->lastHighPulse);
enc->past_pulse_width = pulse->lastHighPulse;
}
if(direction == 1) {
enc->travel = enc->travel + ticks_to_microseconds(pulse->lastHighPulse);
} else {
enc->travel = enc->travel - ticks_to_microseconds(pulse->lastHighPulse);
}
}
void read_abs_enc (struct PulseInputStruct *pulse, struct abs_enc *enc, unsigned char ch) {
if (ch == 0) {
if (pulse->newPulse & HIGH_PULSE) {
set_abs_encoder(&enc, &pulse);
} else {
lcd_goto_xy(0, 2);
print(“No Pulse!”);
}
}
if(ch == 1) {
if (pulse->newPulse & HIGH_PULSE) {
set_abs_encoder2(&enc, &pulse);
} else {
lcd_goto_xy(0, 3);
print(“No Pulse!”);
}
}
}[/code]
Thank you