Newbie question re outputting square wave.
pmulvey
Posts: 24
in Propeller 1
I have the following code:
'' Max output frequency = 2.7KHz PUB Main dira[0]~~ repeat outa[0] := 1 ' waitcnt(clkfreq/32000 + cnt) does not change output waitcnt(clkfreq/31000 + cnt) outa[0] := 0 waitcnt(clkfreq/31000 + cnt)The output will not toggle at frequencies greater than 2.7KHz. I have just received the P1 yesterday, but no crystal. The internal RC is certainly very temperature dependent. I have tried some serial comms but to no avail, probably pointless until I get the crystal. My goal is to set up the P1 as a multi-function I/O device (Servo, PWM, Sound, Pulse Counter etc.) for an educational board based on the ESP8266 that I have designed. I plan on using the P1 as an I2C slave, would anyone advise serial comms instead? I have more questions but I need to invest some time in reading the fine manual.
Comments
Attached is my serial object for RC fast communication. You need to press the space-key two times at begin. The waitForKey methode will then do an autobaud measurement with the timing of that space keys.
Test code:
Andy
On PWM... if you only need one or two PWM outputs, you can use the cog counters and get much higher output frequency, even when using Spin; in that case, the counter generates the high pulse (based on duty cycle), and the Spin loop controls the period. Each cog has two counters. In Spin, you can get up to about 35kHz output on both (I've done this for DC motor controllers). If you move everything to PASM, You can get even high frequencies.
Don't forget to read the intro to Tachyon document and remember that it's a bit like a piano, you can look at it and study it all you like but there's nothing stopping from playing that first note, and so on. Playing is much more fun.
I have received the 5MHz crystal and did a quick "Hello World" check using Simple IDE and the C program so my TX and RX is working OK. When I load the Tachyon.bin I notice that Xin is set at 10,000,000. The download seems to progress with my TX LED showing activity. After 5 seconds I get a message "Write failure on COM".
Paul.
As for the "Write failure on COM" I'm guessing since you have cobbled together a Prop chip and a crystal that maybe your hardware is to blame. Do you have decoupling capacitors properly connected? Do you have a clear photo of your setup?
Try creating a really large test program (just put something like into your Spin test program) and see if that uploads fine
I was getting a "Write failure on COM4" with any number of data items over 4000. I'm attaching the Object Info dialogue using the following code:
I tried out my second P1 and the same applies.
a) What kind of chip is your USB serial dongle using? If it came from Aliexpress, probably not a FT232 (maybe an illicit clone though ) (that being the "known good" one)
b) try changing your serial port's buffer size to something else (the configuration for this is buried somewhere in device manager. Since this is like the 3rd time this is coming up for me, I made a handy PNG that hopefully illustrates how to find it. In German, because changing Windows' language is a mess). In my experience, the lowest value is best. Also try fiddling with some of the other settings in this dialog if that doesn't help.
1) Decoupling capacitors are normally 0.1uF ceramic due to their low esr at higher frequencies and they should be connected as close and as directly to the Vdd/Vss pins on each side as possible. Using high value caps or tantalums will be ineffective.
2) Where is the 3.3V coming from? All the way over there on the breadboard? How is it decoupled?
btw - don't use any 3.3V "supply" from the FTDI chip, it is not meant for this kind of thing and is insufficient.
3) If that is strip board then make sure the crystal does not have a long "antenna" strip of copper. Keep it very tight and nowhere else.
The P1 may appear to work with a poor layout and decoupling but as soon as it starts drawing heavier current and especially if it switches to the crystal, then it could very well fail.
Anyway, if you really want to be able to use the P1 properly, you really need a EEPROM. Use 24LC256 at least but you I would recommend the 64kB(yte) or 128kB devices.
The caps are actually 0.1uF ceramics that look like tantalums.
The crystal tracks are cut beside it.
Hooked in external 3V3 and commoned the ground, same result.
Thanks Wuerfel, I tried different buffer sizes all the down to the minimum, same result.
It will load longs up to what appears to be almost exactly half of the 32K RAM, I wonder is there any significance in half being a limit.
I have ordered 32k EEPROMS as I didn't see how anymore could be useful since RAM is that size, unless of course a program could access the area above 32K in EEPROM for constant data, lookup tables etc.
Paul
Do you have decoupling caps on the 3.3V regulator? Where is it? If the regulator ain't stable, the circuit ain't stable. Do you have a shot of the underside?
It sounds as if your power supply is insufficient and it is drooping, that is, slowly decreasing in voltage as it starts to be used.
btw, the BOE pin on the P1 should normally be grounded but this will also reset the P1 once the voltage drops too far.
That definitely doesn't look like an FTDI chip though. Check your settings and make sure the IDE is not trying to switch to a higher baud rate - just in case.
EEPROM loading won't work if RAM loading doesn't work...
Do you have access to a different serial dongle?
Note - a tiny 3V watch battery will be 3V and power an unprogrammed P1 at reset, but droop and probably fail when you start loading up the P1 and loading up the supply. Watch the supply on a scope and I am sure you will see it droop and drop very badly.
This is the only information I can find about the module that says anything about "3V output". It says up to 120ma But normally the CH340 can't supply that without losing regulation or shutting down after a short period due to overheating.
Ahhh - found a reference, it says " it's a 3.3v LDO rated to 25mA " but in the same forum it is saying that the 3.3V is all over the place, even below 3V on some chips. Definitely DO NOT use this as your supply.
I tried the Silabs CP2102 module and the COM Port wasn't even recognised on a scan by Prop Tool. Same thing applied to a FTDI module. My Aliexpress CH340 works perfectly every time unless I am writing to the upper half of RAM or maybe that the download is taking longer than something can tolerate.
What is the Spin code to write a value to RAM and read it back. (I haven't had a chance to get into the language because of this issue). I want to see if Spin can actually access the upper half of RAM.
Any chance that there are 16K P1's out there that I might have bought?
Can you simplify this by compiling and loading the Tachyon5v7.spin file first off. If that works, then you can track down what's going on from there.
I don't know what O/S you are using but you should be able to detect the CP2102 and FTDI in device manager in Windows.
There is exactly one non-prototype, non-FPGA Prop1 variant, BTW. (And a RAM failure would result in a checksum error)
If you want to access arbitrary RAM/ROM in Spin, simply use LONG[address] (where "address" is any expression). (there's also BYTE and WORD)
Do those detect on your OS as COMxx ports ?
As mentioned above, a handshake line needs to be present to reset the Prop, but all serial ports should connect ok.
A simple loop-back check on any terminal can verify your USB-Serials.
Also maybe try a different PC if you have one laying around.
Maybe now is the time for a photo of the underside because maybe we will see something that you missed. This is simple hardware and usually when there is a problem, it is something very simple,