Hello,
There's an expansion board attached to the LPC2478 which contains a motor and a lightgate which can count the revolutions of the motor, connected to a counter (timer1).
My program is written to enable the user to select various motor speeds and receive feedback as to what the actual motor speed is, which is printed on the display.
The display contains various lines of text explaining the program and various speeds the user can select.
Essentially the problem I have is that for every line of 'lcd_putString' that is used, it multiplies the reading of the motor revolutions. There's 12 lines of lcd_putString which are used in the initialisation code of the program to print this text to the display and then never called upon again. If I comment these lines of text out, so that nothing other than the motor speed reading is display, the motor speed is displayed correctly on the display (tested using an oscilloscope).
To put it simply, if there is text printed to the display using lcd_putString, the counter reading is multiplied.
A lot of hours have gone into trying to sort this issue so any help is hugely appreciated.
This can't work unless the "toggle" variable is static or global - it needs to retain the state between each invocation of the function.
But you can also check the physical pin state directly when toggling.
void toggle_trace_capture_pin(void) //Pin 11 for ISR Monitoring static unsigned int toggle; if (toggle == 0) { FIO0SET |= (1<<11); toggle = 1; } else { FIO0CLR |= (1<<11); toggle = 0; } }
So have you checked how long time your print function takes with full text emitted?
1.6ms with the 14 lines of text enabled. The saw wave is also now visible on the scope with a frequency of 0.5hz.
Can it be assumed from the above information that the lcd_putString isn't causing a significant enough delay to cause the issue?
The delay shouldn't matter.
But have you looked at the flanks of the pulse signal, to make sure you don't get spurious extra-pulses when your code is performing display communication?
Slow flanks and some noise is all it takes to get extra pulses. And the noise is likely higher while you emit data to the display.
When monitoring the signal from the lightgate which is counting the pulses, it doesn't appear to be carrying a lot of noise so I don't think it's reading extra pulses.
Does anyone have any further suggestions on this? Many other people have managed to achieve this so I can only assume there's an error in the code order or initialization.
I've now managed to narrow this down to the number of characters being rather than the lcd_putString function.
The simplified code below demonstrates the issue. The lcd_putString function prints 1 full line of characters, roughly, to the display. Removing some of the words from that, so it only covers about half a line, prints a more representative revolution count.
#include <lpc24xx.h> #include <textDisplay.h> #include <lcd_grph.h> int main(void) { int countval = 0; textInit(); lcd_init(); PINSEL2 |= (3<<6); PWM0PCR |= (1<<10); PWM0MR0 = 120000; PWM0MCR |= (1<<1); PWM0MR2 = 10000; PWM0TCR = 9; PINSEL3 |= (3<<6); T1TCR = 2; T1CTCR = 5; T1TCR = 1; lcd_putString(10,30, "This is a test to check if characters"); while(1) { countval = T1TC; textSetCursor(1,1); simplePrintf("%u", countval); } }