AN001 - Propeller Counters Examples using two leds.
Ramon
Posts: 484
Hello,
This code uses the same schematic as IO Timing Basics. It is a very visual example.
Perhaps it could be included on next revision of the document.
Best regards,
This code togles Led P6 at 0.596 Hz:
This code increases Led intensity on P6 using DUTY Cycle:
This code togles Led P6 and Led P7 at 0.596 Hz (Led P7 = ! Led P6):
This code increases Led intensity on P6, while decreases Led intensity on P7, using DUTY Cycle:
This code uses the same schematic as IO Timing Basics. It is a very visual example.
Perhaps it could be included on next revision of the document.
Best regards,
This code togles Led P6 at 0.596 Hz:
'' File: NCO_single_ended.spin '' '' Demostration of NCO single ended counter mode (%00100) '' '' Toggles Led P6. Same schematic as PE-IOTimingBasics-v1.0 '' '' F (Hz) = ( FRQA / 2^32 ) * System clock '' = ( 32 / 2^32 ) * 80_000_000 Hz = 0.596 Hz CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 PUB NCO_single_ended_mode ' mode PLL BPIN APIN ctra := %00100_000 << 23 + 1 << 9 + 6 'Establish NCO mode; APIN = 6 ; BPIN is ignored frqa := $0000_1000 'Set FRQA so PHSA[noparse][[/noparse]31] adds $20 every clock dira[noparse][[/noparse]6] := 1 'Set APIN to output repeat 'Infinite loop, so counter continues to run
This code increases Led intensity on P6 using DUTY Cycle:
'' File: DUTY_Cycle_single_ended '' '' Demostration of DUTY Cycle single ended counter mode (%00110) '' '' Increase light on led P6. Same schematic as PE-IOTimingBasics-v1.0 CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 PUB DUTY_Cycle_single_ended_mode ' mode PLL BPIN APIN ctra := %00110_000 << 23 + 1 << 9 + 6 'Set DUTY Cycle Mode; APIN = 6 ; BPIN ignored dira[noparse][[/noparse]6] := 1 'Set APIN to output repeat 'Infinite loop, so counter continues to run frqa := frqa + $0000_5000 'Increases FRQA (LED intensity)
This code togles Led P6 and Led P7 at 0.596 Hz (Led P7 = ! Led P6):
'' File: NCO_differential.spin '' '' Demostration of NCO differential counter mode (%00101) '' '' Toggles Led P6 and P7. Same schematic as PE-IOTimingBasics-v1.0 '' '' F (Hz) = ( FRQA / 2^32 ) * System clock '' = ( 32 / 2^32 ) * 80_000_000 Hz = 0.596 Hz CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 PUB NCO_differential_mode ' mode PLL BPIN APIN ctra := %00101_000 << 23 + 7 << 9 + 6 'Establish NCO mode; APIN = 6 ; BPIN = 7 frqa := $0000_0020 'Set FRQA so PHSA[noparse][[/noparse]31] adds $20 every clock dira[noparse][[/noparse]6] := 1 'Set APIN to output dira[noparse][[/noparse]7] := 1 'Set BPIB to output repeat 'Infinite loop, so counter continues to run
This code increases Led intensity on P6, while decreases Led intensity on P7, using DUTY Cycle:
'' File: DUTY_Cycle_differential '' '' Demostration of DUTY Cycle differential counter mode (%00111) '' '' Increase light on two leds (P6 and P7). Same schematic as PE-IOTimingBasics-v1.0 CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 PUB DUTY_Cycle_differential_mode ' mode PLL BPIN APIN ctra := %00111_000 << 23 + 7 << 9 + 6 'Set DUTY Cycle Mode; APIN = 6 ; BPIN = 7 dira[noparse][[/noparse]6] := 1 'Set APIN to output dira[noparse][[/noparse]7] := 1 'Set BPIN to output repeat 'Infinite loop, so counter continues to run frqa := frqa + $0000_5000 'Increases FRQA (LED intensity)