Draft for Review - PE Kit Lab - Fundamentals: Counter Modules and Circuit Appli
Andy Lindsay (Parallax)
Posts: 1,919
Attached is the·1.0 version of the·sixth in the Propeller Education Kit lab series·- Counter Modules and Circuit Applications.
Updates and additional material·added since·v0.81:
·- Uses Parallax Serial Terminal instead of HyperTerminal. It's easier to use, and free.
·- Parallax Serial Terminal is included in the .zip.
·- A section on writing an object that launches a cog that uses counter modules.
·- Questions/Exercises/Projects and solutions.
·- Corrected error in infrared object detection schematics
Please send corrections to editor@parallax.com, and post suggestions and recommendations to this thread.
PE Kit Labs that have already gone through the review process are available for download from the Propeller Education Kit page.· You can also find discussions for each lab along with the latest drafts on the Propeller Education Kit Labs thread.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
Post Edited (Andy Lindsay (Parallax)) : 10/23/2008 1:35:18 AM GMT
Updates and additional material·added since·v0.81:
·- Uses Parallax Serial Terminal instead of HyperTerminal. It's easier to use, and free.
·- Parallax Serial Terminal is included in the .zip.
·- A section on writing an object that launches a cog that uses counter modules.
·- Questions/Exercises/Projects and solutions.
·- Corrected error in infrared object detection schematics
Please send corrections to editor@parallax.com, and post suggestions and recommendations to this thread.
PE Kit Labs that have already gone through the review process are available for download from the Propeller Education Kit page.· You can also find discussions for each lab along with the latest drafts on the Propeller Education Kit Labs thread.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
Post Edited (Andy Lindsay (Parallax)) : 10/23/2008 1:35:18 AM GMT
Comments
What I have found:
Also if the Propeller won't be damaged by a short circuit of a output-pin, I dont find the circuit
in Figure 2 convincing, because if the Poti stays at 0 Ohm, then :
1) the Capacitor will not be charged, and the POS detector measure 0 until the resistance of
the poti is high enough. That gives a leap in the linearity.
2) there will be a current-spike on the 3.3V Supply when the propeller tries to charge the C. That can
disturb other parts of the circuit.
3) if the Poti stands near the minimum (0 Ohm) a relatively high current flows
thru the little remaining resistance, that can damage the Poti !
My suggestion is to use a little Series-Resistor (100 Ohm?) to the Poti, that only gives a offset,
but not affect the linearity of the measured value.
Andi
/John
Good question. Yes, at the 9th addition, the the carry bit will have been set for 4/9 of the time, but by the time you get to 16, the bit will have been set 6/16 = 3/8 of the time. Also, as the cycle repeats, the average of the time the carry bit will have been set remains close to 3/8. For D/A conversion an RC circuit (or our eyes in the case of the LED example) smooths all that out.
Andy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
crta[noparse][[/noparse]26..30] := %00100
over
ctra := %00100 << 26
but, I understand both now.
I think the problem is that there's a typo in the three bit example on page 14. The seventh iteration is wrong - it should be 011 + 010 = 101. Then the eighth iteration would be 011 + 101 = 000, setting the carry bit for the third time and starting the sequence over.
It took me a while to realize it was just a typo, but in the process I've come to understand the mathematics of setting duty cycle inside and out!
/John
Nice catch and thanks for the heads-up. The arithmatic error is now corrected, and the zip and PDF are now v0.81.
http://forums.parallax.com/attachment.php?attachmentid=0
Andy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
All of the PE Kit Labs are great, but this one is fabulous... so good (in fact) that Parallax might consider selling advertising space in the modules.
What I personally find most exciting is that I have looked at electronics over the years but never really found a compelling way to studyit...
Now that I feel Prop-erly compelled...it is amazing how many misconceptions that I managed to accumulate.
I find it amazing that the Education Kit is so complete... and the modules are so clear.
What's next?
How about an upgrade kit?... a second Prop and a really nice module on multi-prop implementations!!!!
Thanks.
Rich
Wow, thank you very much! That is high praise indeed.
Sorry for having missed this post; I was on vacation last week.
What's next?...
Gee Whiz Object Examples
The overall goal is to find and adapt several of the many interesting Propeller chip applications that already exist to the PE Kit without requiring extra hardware. For example, Chip Gracey wrote some code that makes a speaker do a nice job of pronouncing "seven" in a variety of tones. I don't know if that can be reproduced with a piezospeaker, but I'm going to try. ·If all goes well, this lab will·adapt four or five novel applications in this manner.
Sine Waves with ROM Tables
Demonstrates the mechanics of reading the Propeller Chip's ROM tables and using them to generate sine waves.
Programming and Operators
Lots of code examples for getting familiar with the Spin language and syntax, mostly terminal applications with entered inputs and displayed outputs.
Assembly Language
If time permits, I'll throw my hat in with the rest of the folks attempting to introduce Propeller Assembly language. The goals will be to: (1) provide a few program examples that port some of the simpler Spin language examples from earlier labs, (2) explain the DAT, ORG, labels, etc… (3) Provide examples of the use and application of the Propeller Manual's Assembly Language Elements section, (4) demonstrate how to use PAR to provide a shared memory interface between the ASM and Spin code.
After that…
We are considering kits that focus on a particular interest (motors, actuators, sensors, ...). Another thing we are looking into is making breadboard adaptors for certain things that aren't breadboard friendly.
Andy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
Post Edited (Andy Lindsay (Parallax)) : 5/31/2007 1:26:07 AM GMT
they ae very helpfull for me as a newbe.
everytime I have a question someone already has an answer
on this forum usually before· I even ask.
Thanks
Jim
Agreed about the high quality and thoroughness of these lab kits. Top notch. Also earlier ones. I was just looking at the Memsic documentation and the material in Smart Sensors. This is all great stuff.
About Sine waves with ROM tables. I made a start on a tutorial...
http://forums.parallax.com/showthread.php?p=606978
That includes both spin and asm versions. You at one time referred me to Chip's own Sound.spin, an asm object that generates two PWM sine waves of variable frequency, phase and amplitude. One thing I still have on my fun todo list is a Propeller spirograph, that would couple the waves together for x-y display on an oscilloscope. That requires quadrature SIN-COS at two frequencies, added in x and y components.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Counter Modules and Circuit Application has been a big help. Please write more soon! One thing I would like to see is Assembly examples included. I'm trying to teach myself Assembly and there seems to be a very limited amount of beginner's material.
Here is an Example Object of the "Test RC Decay Time" that I wrote.·I looks simple now but it took me soom time before I got it right, at least I hope it's·right.·Hopefully·some other asm beginner's will find this usefull.
Thanks·Again Andy, write more soon!
·{{
TestRcDecayAsm
Measuring RC Decay with Positive Detector Mode
Does the same thing as TestRcDecay.spin but with some assembly language
}}
CON
··
· _clkmode = xtal1 + pll16x···························· ' System clock → 80 MHz
· _xinfreq = 5_000_000
··
OBJ
··
· Debug: "FullDuplexSerialPlus"························· ' Use with HyperTerminal to display values
VAR
· long· Cog············································ ······ ' Holds the number of the Cog in use
· long· Time············································· ···· ' Holds the time of RC decay
·
PUB Start : Okay
· Okay := Cog := cognew(@entry, @Time) + 1···· ' Start a Cog to run Asm code and set pointer to
····························································· · ·· ' @Time Variable in hub ram
· Init····················································· ······ ' Jump to Init method
·
PUB Stop
· if cog
··· cogstop(cog~ -1)································· ···· ' Stop cog
PUB Init
· 'Start serial communication, and wait 2 s for user to connect to HyperTerminal.
· Debug.Start(31, 30, 0, 57600)
· waitcnt(clkfreq * 2 + cnt)
·
· repeat
··· Debug.str(String(10, 10, 13, "working on other tasks"))
···· repeat 10
······ Debug.tx(".")
······ waitcnt(clkfreq/30 + cnt)
···· ' Display Result·································
···· Debug.Str(String(10, 13, "time = "))
···· Debug.Dec(time)
···· waitcnt(clkfreq/2 + cnt)
DAT············ ' Start of Assembly Code
······················· org···· 0······································· · ' Start @ this address
entry·················mov···· Mem_Pointer,··· Par············ ·· ' Set Mem_Pointer to Time, This was
·········································································· ··'·· passed to the Asm cog at cognew
·········································································· · '·· by @Time.
·············· ' Configure counter module.
······················· mov···· ctra,·········· Cntmode············ ' Setup Counter control register
······················· mov···· frqa,·········· #1··················· ·' Set frqa register to 1
············· ' Charge RC circuit.
:Loop················· mov···· · dira,·········· · Pin17··········· ·' Set pin 17 to output
························ mov···· · outa,········ ·· Pin17·············' Set pin 17 to High
························ mov······ Wt_Time,····· cnt············· · ' Set time to current clock cycles
······················· ·add······· Wt_Time,····· Delay··········· ·'·· and add Delay to time
······················ · waitcnt·· Wt_Time,····· Delay··········· ·' Wait for Capacitor to charge
············· ' Start RC decay measurement.
······················· mov···· ·· phsa,·········· #0·· wz····· ··· ·' Clear the phsa register and set Z flag to 1
······················· muxnz·····dira,········· ·· Pin17············ ·' Set pin 17 low, muxnz sets bit 23 to !Z
············· ' Get RC decay measurement and send it to Hub RAM via Mem_Pointer
······················· mov···· Wt_Time,······· cnt·········· ·· ·· ' Set time to current clock cycles
······················· add···· Wt_Time,······· Dly_Hlf_Sec···· ··'·· and add 1/2 second to Wt_time
······················· waitcnt Wt_Time,······· Dly_Hlf_Sec··· ··' Wait for Capacitor to discharge······················
······················· mov···· _time,········· phsa················ · ' Set _time to phsa
······················· wrlong· _time,········· Mem_Pointer····· · ·' Write _time in Cog RAM to Time in
········································································ ···· '·· in Hub RAM using Mem_Pointer to
········································································ ···· '·· show the way.
······················· jmp···· #:Loop························· ········ ' Jump to Loop··
·······················
·······················
······· ' Variables in Cog RAM
CntMode···· ·· long····· %01000 << 26 + 17······ ' Set Counter control register to POS detector and APIN to 17
Dly_Hlf_Sec· · long····· 40_000_000············· ·· ' Set to 1/2 second
Delay·········· ·long····· 80_000·················· ···· ' Set Delay to Clock cycles
Pin17·········· ·long····· |< 17······················ ·· ' Use Bitwise Decode to set var Pin17 long to pin 17 in Hub RAM
Mem_Pointer·· res······ 1···························· · ' Used to hold Memory pointer to var long Time in Hub RAM
Wt_Time····· · res······ 1····························· ·' Used to hold cnt wait time
_Time········· · res······ 1······························ ' Used to load phsa into then send to Time var in Hub RAM
Keep in mind that there's a difference between those two statements. The first only affects bits 26 to 30 of ctra--all its other bits are left as-is. The second statement sets all of ctra's other bits to zero.
Also, the order of the numbers in the brackets is significant. In your example, it doesn't matter, because the value is symmetrical. But if you wanted to set the counter to DUTY mode, ctra[noparse][[/noparse]26..30] := %00110 would be incorrect. Instead, you'd need to write ctra[noparse][[/noparse]30..26] := %00110.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
However, if I switch the anode and cathode on the IR LED, I get a nice range of values from 13 to 256. It's just that the meaning is reversed--256 when something is close and 13 when no object is detected.
Has anyone else run into this?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
Nice summary on the bit addressing vs. left shift.· We'll see about adding that as an i-box.
I saw that symptom when I was playing with variations of the IR code and circuit.··Please try TestIrDutyDistanceDetector.spin in the attached.· Are the symptoms still the same, or does it work as advertized?
Regarding IrObjectDetectionBeep.spin:··A couple commands to set up·counter B·for tones, and then use the IR input to control the speaker I/O pin direction.· When the I/O pin is an input, no beep.· When IR is detected, the I/O pin becomes an output and the beep starts.· Very nice...· May I add that to the exercises at the end of the chapter?·
Andy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
Try the second IR LED in the PE Kit.
Is the notch in the round part of the plastic case above the shorter (cathode) pin on both IR LEDs?
Andy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
I am all excited about Christof's mod of the metal detector... but I'm having a problem. I went back and tried to actually to run CalibrateMetalDetector... and I'm having a dufus level problem.
My terminal program... I double checked the settings... seems to be set up right,
The objects are in the same folder...
My terminal program shows "Starting Frequency:"
but won't accept my keyboard input. I'm usinga Dell XPS.
What am I doing wrong?
Rich
Sorry,
Rich
Or at least is there an introduction to making audio stuff with the PE kit? I mean more than just a square wave? Because I made a 5-key 'piano' with pushbuttons that is only able to play one note at the time, but I would really like to make it play chords, and I guess the only way to do this is with sine waves with PWM and RC-filters...
Is there a way to run Chip's audio program's (in the object exchange) with the PE kit rather than the demo board? (I have a speaker which makes a better sound than the piezos)
Anyways thank you very much for your awesome labs! It makes everything so much simpler!!
Alberto
I guess now I can find out!
Here is what I noticed:
On Page 27 in Figure 11 The IR Led is connected between P1 and VSS but the text on the following page says:
The IR LED’s shorter cathode pin is connected to the left vertical ground rail (black, 4).
two minor text errors:
page 23
Load the HyperTerminalFrquencies object into the Propeller chip.
("e" missing in HyperTerminalFrequencies"
page 26
Load TwoTonesWithObject into the Propeller chip and verify that it behaves the same as the TwoTones object.
must be:
Load TwoTonesWithSquareWave into the Propeller chip and verify that it behaves the same as the TwoTones object.
-Stephanie Lindsay
Editor, Parallax Inc.
I understand basic binary math, but I spent an hour or two going over the NcoFrqReg method of HyperTerminalFrequencies and still do not understand how it works.
The code in question is as follows:
[code]
PUB NcoFrqReg(frequency) : frqReg
{{
Returns frqReg = frequency
Think of two numbers, say frequency = 40 MHz and clkfreq = 80 MHz
You want to divide frequency by clkfreq and call the result frqreg .
Start with frqreg = 0
You see it works a little bit as in school division, Your result should be:
$80_00_00_00 which is 1/2
O.k. you say, but that isn't 1/2 it's 231!
Well in fact that is all right. When you look at the assignment again, we just WANTED to calculate
frequency
http://forums.parallax.com/showthread.php?p=648967
Changes and Additional Material:
·- Uses Parallax Serial Terminal instead of HyperTerminal. It's easier to use, and free.
·- Parallax Serial Terminal is included in the .zip.
·- A section on writing an object that launches a cog that uses counter modules.
·- Questions/Exercises/Projects and solutions.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.