View Full Version : Sqaure Wave Generator---doesn't

09-11-2007, 09:49 AM
Ref My pos of Aug 7 about the 'CRT.SPIN' code and my o'scope fumbling.

Anyway.· The next step was to put together a simplified assembly language (which I am attempting to learn) program that would run in a cog and do this while I'm doing other thing.· I couldn't get it to work because I was having problems with the way variables were stored and how PAR worked. Sorting the Varabiles by long, word, byte, really gave a headache for a while until I downloaded PASD_02 (Propeller Source·Assembler Debugger) ·from INSONIX.· Seems to be an excellent tool.· If you haven't tried it, I highly recommend you look at it seriously.· I got the variable passing down and know how PAR works,etc

One problem I have is that I declared a variable in assembly as a byte and did a rdByte from main memory and got a compiler error message that the "Variable Not A Long", while other variables declared as byte are work with RdByte work just fine.·· To get around it I just declared all variables as long and still used RdByte, worked well.·· If it works, I can delay fixing it but would like to know what caused the problem.

But I digress.··· The intent of the code is to produce two square waves offset by from each other by a fixed number of counts.· A zero (0) offset would be acceptable for the test but the code currently uses $4000_0000.· Basically it sets the initial PHSA count to the·zero(0) ·and the PHSB count $4000_0000·and uses CRTMODE $00100 for both counters.· To get the proper frequency I loaded FRQA and FRQB with $6c(108) which should produce a 2 Hz output.· As I understand the operation, with every clock Cycle FRQX will be added PHSX and bit 31 of PHSX will be output on PINA for that counter, (I'm using PROPRPM board and usng P16 and P17 as the output pins).· The Led bars attached to P16 and 17 light up and·do not toggle on or off.··Also the scope shows no high frequency toggling (Yes, I set the coupling properly http://forums.parallax.com/images/smilies/blush.gif )· When I set up used PSAD_02 I could see that CTRX was being properly set· up with the CRTMODE,and PINA: PHSX contained the proper initial·values, FRQX was set correct.· I could step through the code and see the system clock change BUT the PHSX value was never modified.· This is consistent with·observation that the LEDs did not toggle.· It could also be a bug in the the PASD but probably not.

Code attached (PASD commented out).·Any suggestion on why the program isn't toggling the LED would be greatly appreciated.· Since I'm a newbe working with this chip and assembly, it's probably a very simple fix but I've looked at it too long and had too many cups of coffee.

Thanks in advance for any help.

Post Edited (greybeard) : 9/11/2007 5:04:49 AM GMT

09-11-2007, 11:14 AM
If you go to the top right of your message you can add a subject. (use the pencil icon)

- Stephen

09-11-2007, 11:08 PM

the problem in your code is the MOVI instruction, where you want to start the counter. MOVI sets the bits 31..23 but CTRMODE is located at bit 30..26 and PLLDIV is located at bit 25..23. So you was only changing PLLDIV.

Your instruction should look like "movi ctra, #%00100_000" to start a counter.

Why you did not use the CTRMODE %00101? So you would need only one counter.


09-11-2007, 11:49 PM
Thanks.· I knew it was something simple that i was missing.· The reason I'm not using CRTMODE %00101 is that the second pulse train is 180 degrees out of phase with the first pulse train,·· I need two signals that have an programmable phase shift.·