Parallax Propeller AN001 - Propeller Counters v1.0 Schematic font ?
{{
This program demonstrates the use of the counter in POS detector with feedback to perform ADC
calculations using the following circuit:
3.3V
1nF 150kΩ
adcpin ─────┳──╋─────────── Analog In
100kΩ 1nF
fbpin ─────┘
Vss
The two capacitors and the 100kΩ resistor must be placed within 1" of the Propeller for stable
operation of the circuit and any excess leads must be cut away. This circuit will not work by
placing it on the Demoboard's breadboard.
The 150kΩ resistor may need slight adjustment of it's value in order to obtain as close to full
scale without clipping either end. This can be tested by tieing the Analog In to 3.3V and Vss and
noting the value produced, these values should be as near to 2^(sample bits)-1 (255 for bits=8)
and 0 without actually being either of these numbers (otherwise clipping occurs and a range of
voltages cannot be measured). These final numbers are used to compute what the full-on and
full-off (3.3V and 0V) values are.
Use of the circuit and program is sufficient for obtaining the voltage of a node between
0 and 3.3V. To obtain a current value, place a small ohm (<1Ω[noparse];)[/noparse] resistor (called a current sense
resistor) in the current path and use two ADC circuits to measure the voltage on both sides of
the resistor. Use Ohm's law to calculate the current flowing through the resistor.
The code shown below can be expanded to use both counters on the cog (CNTB in addition to the
CNTA as shown below) to better utilize each cog's resources. Doing this doubling up will yeild a
maximum of 16 ADC circuits, however 14 ADC circuits will be the highest practical implementation
since at least 1 cog will be needed to process the data.
}}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
' At 80MHz the ADC/DAC sample resolutions and rates are as follows:
'
' sample sample
' bits rate
'
' 5 2.5 MHz
' 6 1.25 MHz
' 7 625 KHz
' 8 313 KHz
' 9 156 KHz
' 10 78 KHz
' 11 39 KHz
' 12 19.5 KHz
' 13 9.77 KHz
' 14 4.88 KHz
bits = 12 'try different values from table here
'these are the pins used for the above circuit, rename these values to reassign the pins
'for best results use two pins which are not consecutive (ie not 0&1, 2&3 etc), since crosstalk
'can occur and cause fluctuations of the computed ADC value.
fbpin = 2
adcpin = 7
OBJ
txt1 : "VGA_Text"
VAR long value
PUB go
txt1.start(16)
cognew(@asm_entry, @value) 'launch assembly program into a COG
txt1.out($00)
repeat
waitcnt(40_000_000 + cnt)
txt1.out($00)
txt1.dec(value)
DAT
'
'
' Assembly program
'
org
asm_entry mov dira,asm_dira 'make pins 8 (ADC) and 0 (DAC) outputs
movs ctra,#adcpin 'POS W/FEEDBACK mode for CTRA
movd ctra,#fbpin
movi ctra,#%01001_000
mov frqa,#1
mov asm_cnt,cnt 'prepare for WAITCNT loop
add asm_cnt,asm_cycles
:loop waitcnt asm_cnt,asm_cycles 'wait for next CNT value (timing is determinant after WAITCNT)
mov asm_sample,phsa 'capture PHSA and get difference
sub asm_sample,asm_old
add asm_old,asm_sample
wrlong asm_sample, par
jmp #:loop 'wait for next sample period
'
'
' Data
'
asm_cycles long |< bits - 1 'sample time
asm_dira long |< fbpin 'output mask
asm_cnt res 1
asm_old res 1
asm_sample res 1
This program demonstrates the use of the counter in POS detector with feedback to perform ADC
calculations using the following circuit:
3.3V
1nF 150kΩ
adcpin ─────┳──╋─────────── Analog In
100kΩ 1nF
fbpin ─────┘
Vss
The two capacitors and the 100kΩ resistor must be placed within 1" of the Propeller for stable
operation of the circuit and any excess leads must be cut away. This circuit will not work by
placing it on the Demoboard's breadboard.
The 150kΩ resistor may need slight adjustment of it's value in order to obtain as close to full
scale without clipping either end. This can be tested by tieing the Analog In to 3.3V and Vss and
noting the value produced, these values should be as near to 2^(sample bits)-1 (255 for bits=8)
and 0 without actually being either of these numbers (otherwise clipping occurs and a range of
voltages cannot be measured). These final numbers are used to compute what the full-on and
full-off (3.3V and 0V) values are.
Use of the circuit and program is sufficient for obtaining the voltage of a node between
0 and 3.3V. To obtain a current value, place a small ohm (<1Ω[noparse];)[/noparse] resistor (called a current sense
resistor) in the current path and use two ADC circuits to measure the voltage on both sides of
the resistor. Use Ohm's law to calculate the current flowing through the resistor.
The code shown below can be expanded to use both counters on the cog (CNTB in addition to the
CNTA as shown below) to better utilize each cog's resources. Doing this doubling up will yeild a
maximum of 16 ADC circuits, however 14 ADC circuits will be the highest practical implementation
since at least 1 cog will be needed to process the data.
}}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
' At 80MHz the ADC/DAC sample resolutions and rates are as follows:
'
' sample sample
' bits rate
'
' 5 2.5 MHz
' 6 1.25 MHz
' 7 625 KHz
' 8 313 KHz
' 9 156 KHz
' 10 78 KHz
' 11 39 KHz
' 12 19.5 KHz
' 13 9.77 KHz
' 14 4.88 KHz
bits = 12 'try different values from table here
'these are the pins used for the above circuit, rename these values to reassign the pins
'for best results use two pins which are not consecutive (ie not 0&1, 2&3 etc), since crosstalk
'can occur and cause fluctuations of the computed ADC value.
fbpin = 2
adcpin = 7
OBJ
txt1 : "VGA_Text"
VAR long value
PUB go
txt1.start(16)
cognew(@asm_entry, @value) 'launch assembly program into a COG
txt1.out($00)
repeat
waitcnt(40_000_000 + cnt)
txt1.out($00)
txt1.dec(value)
DAT
'
'
' Assembly program
'
org
asm_entry mov dira,asm_dira 'make pins 8 (ADC) and 0 (DAC) outputs
movs ctra,#adcpin 'POS W/FEEDBACK mode for CTRA
movd ctra,#fbpin
movi ctra,#%01001_000
mov frqa,#1
mov asm_cnt,cnt 'prepare for WAITCNT loop
add asm_cnt,asm_cycles
:loop waitcnt asm_cnt,asm_cycles 'wait for next CNT value (timing is determinant after WAITCNT)
mov asm_sample,phsa 'capture PHSA and get difference
sub asm_sample,asm_old
add asm_old,asm_sample
wrlong asm_sample, par
jmp #:loop 'wait for next sample period
'
'
' Data
'
asm_cycles long |< bits - 1 'sample time
asm_dira long |< fbpin 'output mask
asm_cnt res 1
asm_old res 1
asm_sample res 1
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
-Phil
Thanks for the replys. I want to post same code to test NCO and DUTY Cycle mode on two LEDS.
Here is my first post: http://forums.parallax.com/showthread.php?p=665823
Best regards,