Hard Lessons Re-Learned
After the I2C was working I moved on to PWM for the motors and the single LED controlled by the PIC32. This seemed very easy from looking at the examples in the Microchip Harmony Framework. I used my Digilent Analog Discovery 2 USB device to watch the signal. These are great devices that can be a 2 ch scope, 16 input logic analyzer, waveform generator, etc. For looking at signals under 2MHz, this much easier than pulling out my Tek Scope. See here for more information https://www.analogdiscovery.com/
And here is where the fun began. The circuit I was testing was a single pin driving a FET with 196 ohm current limiting resistor in the path as shown here.
I was
using the Digilent USB device hooked up as logic analyzer. Nothing would
show up at the two pins where the LED connects, J13. Then using another lead
and probing the gate and the source pin on the FET, the expected signal
was there. But on the other side of the current limiting resistor
nothing. After a few hours, it becomes clear this is an open collector
driver, of course there will be no signal because it is an open
circuit. I dug up a 330ohm resistor to put across the connector, J13, and
still nothing. So I changed to scope mode and the signal is there. But
since there is a current limiting resistor and I was measuring between
the current limiting resistor and the 330ohm, the signal did not return
to zero, actually a little over 1V. So the logic analyzer portion of
the Digilent wont work, as one would expect.
Well after a day and half of this, I verified that it all works. It actually always worked, I just did not know it. Next step is to get all 4 motor ports working in forward and reverse and then write a driver for the PWM portion.
Here is a quick video of the PWM signal incrementing from 5 to 100%, in 1% steps. The PWM frequency is 20KHz, not sure it needs to be that high. LEGO seems to use 1150 Hz, but I am afraid that will generate unwanted audio tones. But that is easily changeable and have setup constants that will do all the necessary arithmetic. At 20KHz there are 2000 steps with this PIC32, much more resolution that we will ever need.
No comments:
Post a Comment