My code fails intermittently when the prop plug is plugged in for long periods of tim
turbosupra
Posts: 1,088
So I'm curious as to why I had this problem.
I have been told that I should have a COM cog and I'm in the process of converting my code to that and implementing it, but for my own learning and knowledge I was wondering why the behavior in the video was happening?
The code for the function is below, the cliffs are that when the pwm output frequency is high, the green LED is on, the yellow is off and when the square wave goes low, the green LED is off and the yellow is on. It also writes HIGH or LOW to the terminal when it is doing this. As seen in the video, it will oscillate around 20 times, then you'll see the prop plug LED illuminate 1 time and then both LED's will go out and it will hang for a few seconds, then the function will start again. It stopped doing that when I unplugged the prop plug. Is there a standard explanation for this?
http://youtu.be/vuuGCXm-PZ0
I have been told that I should have a COM cog and I'm in the process of converting my code to that and implementing it, but for my own learning and knowledge I was wondering why the behavior in the video was happening?
The code for the function is below, the cliffs are that when the pwm output frequency is high, the green LED is on, the yellow is off and when the square wave goes low, the green LED is off and the yellow is on. It also writes HIGH or LOW to the terminal when it is doing this. As seen in the video, it will oscillate around 20 times, then you'll see the prop plug LED illuminate 1 time and then both LED's will go out and it will hang for a few seconds, then the function will start again. It stopped doing that when I unplugged the prop plug. Is there a standard explanation for this?
http://youtu.be/vuuGCXm-PZ0
pub coolantPwmOut ' set pin states dira[O_TempGauge] := 1 ' Pin 16 ' output dira[O_CoolantPwmDebugLow] := 1 dira[O_CoolantPwmDebugHigh] := 1 ' set pin voltages outa[O_TempGauge] := 0 ' Pin 16 outa[O_CoolantPwmDebugLow] := 1 outa[O_CoolantPwmDebugHigh] := 0 ' initialize variables coolantPwmDebug := false coolantPwmDebugPause := cnt coolantPwmDebugPauseTime := clkFreqTimes2 coolantPwmLastDebugTime1 := 0 coolantPwmLastDebugTime2 := 0 coolantPwmLastDebugTime3 := 0 coolantPwmStateHigh := false coolantPwmOnTime := cnt coolantPwmOffTime := cnt adcTHWBlock := false waitcnt((clkfreq * 1) + cnt) repeat 'if (ina[I_KeyOn] == 1) if(keyOn == true) if (okToReadAdcTHW == 1) okToReadAdcTHW := 0 adcTHW := adcTHWTemp okToReadAdcTHW := 1 if (adcTHW <> 0) if (adcTHWBlock == false) adcTHWBlock := true onTime := ((pwmOutputHertzToClkCycles * getConstant) * 10) offTime := ((pwmOutputHertzToClkCycles * (100 - getConstant)) * 10) if (coolantPwmStateHigh == false) AND ((cnt - coolantPwmOffTime) > 0) ' if not high and time expired outa[O_TempGauge] := 1 ' output high coolantPwmOnTime := (onTime + cnt) ' stay high time coolantPwmStateHigh := true ' state is high outa[O_CoolantPwmDebugLow] := 0 ' yellow outa[O_CoolantPwmDebugHigh] := 1 ' green debug.str(string(" HIGH ")) debug.tx(13) if (coolantPwmStateHigh == true) AND ((cnt - coolantPwmOnTime) > 0) adcTHWBlock := false ' unblock next read outa[O_TempGauge] := 0 ' output low coolantPwmOffTime := (offTime + cnt) ' stay low time coolantPwmStateHigh := false ' state is low outa[O_CoolantPwmDebugHigh] := 0 ' green outa[O_CoolantPwmDebugLow] := 1 ' yellow debug.str(string(" LOW ")) debug.tx(13) debug.tx(13) else repeat 7 outa[O_Debug] := 1 waitcnt((clkfreq/15) + cnt) outa[O_Debug] := 0 waitcnt((clkfreq/15) + cnt) outa[O_TempGauge] := 0 ' Pin 16 adcTHWBlock := false okToReadAdcTHW := 1 coolantPwmStateHigh := false coolantPwmOnTime := cnt coolantPwmOffTime := cnt firstRunAfterKeyOffCoolantPwm := true debug.str(string(" *** Key is off (coolantPwm)")) debug.tx(13) waitcnt (clkFreqTimes3 + cnt)
Comments
I have had problems with prop's resetting intermittently when no USB cable us attached.
I believe it's something to do with parasite power issues with the FTDI chip.
I do have this code and it wasn't flashing, so I don't believe the prop was turning off, I believe it was just hanging.
I had a cable connected to the prop plug, but no computer.
I'd like to figure this out so that I don't have this issue when I switch everything over to a COM only method.
The first thing the FTDI chip does then is toggle the reset pin and cause the Prop to reset....
You may have to disable your serial cog if using FTDI chip not powered from a PC...
It came back on its own also. I tried to pull my phone out to time how long it would take in between when it stopped and when it started (as I was driving) and see if it was ~53 seconds, but it did not happen again after I had my stop watch application ready. I'm hoping I'll be able to catch it on the way home, and if not I will comment out the serial code after I get home.
Do you have a code example to test if rx is high?
Thanks
If ina[rxpin] == 1
'then the pin is high
I don't see anything that could be wrong except the last line:
waitcnt (clkFreqTimes3 + cnt)
Where is clkFreqTime3 defined?
-Phil
I've had an extremely hard time getting a consistent PWM signal, which to me seems like it should be extremely simple to get?
coolantPwmObject5 - Archive [Date 2015.01.08 Time 15.43].zip
Do you have any thoughts on how to isolate the prop from the automotive noise? I'd love to know more about the logging system you have. I was trying to do my best to do something similar with the LED's, but they don't make an audible noise of course, and I can't look at them all of the time while driving. I have not ever had any errors when bench testing, and I did that for quite some time.
Thanks, I will add this
-Phil
Phil, he mentions that he is using a Prop Plug. So he may not have an FTDI connected if I understand this right. I am not sure what the board is, but on some schematics that use the Prop Plug there is no pull up/down on the Reset input. However, that being said there is apparently no reset occurring based on the LED indicators that would suggest a real reset.
It would be helpful to see schematics and a photo of the installation.
Don't you have a display of some sort on this gadget? If so, how about add some debug text to it. For one, everytime you boot the device, have it read a stored value in the upper region of your eeprom that is used to store a counter. The counter can be a byte length. So, on boot, read the count, then display the count on your screen. Then increment the count and save it back to the same location. This way, you can pay have a running total of each boot up. Each time you manually boot the system up, take note of the most recent count, then check it periodically to see if it changed. Radio shack sells a piezo buzzer. Put in on a pin and get the Synth Freq object, set it to about 2k and have it buzz on bootups. It may not be very loud, so try changing the frequency starting at 1k up to 2k in increments of 100 to find the loudest volume it can produce.
JonnyMac has told me recently that I should have a dedicated comm method and I'm integrating that into my new code, but this object was written before that, but I'm migrating the debug code to its own cog and method. I'm sure there are more experienced (read as better) ways to do this, but this is the format I have so far with each object setting the debug value and then setting the Update variable to true after it has changed the value.
I have a schematic at home and I'll grab a photo of it as well and send it to you.
I think it has to be something wrong with the reset circuit, maybe getting noise somehow...
become this? I've never used anything but 80mhz before.
But looking at the manual, I see this is 12 MHz, not 20 MHz. I'm not sure if your code will work with such a slow clock or not...
You might have to reduce your serial terminal speed or something like that...
Changing the clkfreq caused a lot of things to hiccup.
The only affect that I see happening by hooking up a Prop Plug is that you are basically adding an antenna to your board...
If you don't have good capacitor bypassing of the power supplies or if you have long leads on your crystal, then maybe there could be problems...
I'd try adding ceramic capacitors between +3.3 V and GND with short leads to the Prop chip. If this is a DIP version, you need this on both sides of the chip.
Also, double check your crystal connections and keep the leads as short as possible.
I will try this, thank you very much.
Still, you have to remember to add some capacitors, or strange things will happen...
The one thing you can't do is put 5 V directly on any pin. This seems to always kill the PLL...