View previous topic :: View next topic |
Author |
Message |
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Mon Jul 13, 2020 2:33 pm |
|
|
I'm trying to run a stepper motor synchronized to a sector scan on an LCD (Sonar display).
I have to send a pattern of 4 bits in sequence, either forward or backward, in step with the scan. The pattern is in an array
Code: | char step[4] = {0x03,0x06,0x24,0x21}; |
the following does not interfere
Code: | output_high(PIN_C5); |
but requires many statements.
Or I could use another port but it does not answer the basic question of how to handle mixed I/O |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Mon Jul 13, 2020 2:48 pm |
|
|
#use fast_io(c) stops freezing the I2C but nothing is Output even the simple
I have LEDs to see the states. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 13, 2020 3:09 pm |
|
|
#fast_io tells the compiler to not set the TRIS. You must manually do it
with a line of code. If you don't see your LEDs light up, then the TRIS is not
set to be output pins. |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Mon Jul 13, 2020 4:26 pm |
|
|
Sorry, I had set tris to 0xff while testing.
Now the program seems to be working but not if I comment out the #use fast_io(c).
What is happening without fast_io and why does it freeze the I2C? The tris is set to 0x18 so the C4, C3 are inputs.
Why does it work with fast_io? I read the manual but don't fully understand what is happening. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1903
|
|
Posted: Mon Jul 13, 2020 5:33 pm |
|
|
Without fast_io, the compiler sees that you're trying to set port C to some specific 8 bit value, so it automatically makes all of the pins of port C an output for you. Including your i2c lines (it doesn't care that you originally set them to be inputs). Which, by the way, must be left as inputs. But it doesn't really know/care because this convenient automatic feature trumps all.
Then some time later the i2c code must execute but the compiler isn't intelligent enough to set those two pins back to an input first. Result: code hangs in the first i2c routine.
I'll admit, for those new to PICs and the compiler, having these things taken care of automatically is kind of cool. For anything else, take control yourself: no surprises that way. |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Mon Jul 13, 2020 6:34 pm |
|
|
That really surprises me because without fast_io I had set Tris to 0x18 (mixed I/O).
Does that mean the compiler set them all to output at the first output_c()
??
I'm sure I have written programs without fast_io that used input and output pins and I never had any trouble. Perhaps I read them individually.
Thanks, I will watch that carefully.
My stepper is running nicely and I'm trying to find out how many degrees per step. It appears to be 1000 steps for 180 degrees and I have suspected it had gears from the shape, so 0.18 deg/step. |
|
|
|