In SX Microcontrollers, SX/B Compiler and SX-Key Tool, RS_Jim wrote: Frankly I am baffled, when I run the following piece of code on an SXTECH board with the sxkey, it works perfectly. The scope shows the pwm width changing at the appropriate times. When I program the chip with the same key remove the key and install a 20_000_000 resonator it will generate a pulse, narrower than normal and rarely get past one loop of the speed increase. ' ========================================================================= ' ' File......AMotorrun.SXB ' Purpose...TEST PWM under local osc. ' Author.... Jim Meek ' E-mail.... ' Started... June 30, 2009 ' Updated... ' ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' Conditional Compilation Symbols ' ------------------------------------------------------------------------- 'none ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- ID "MOTTEST" DEVICE SX28, OSCXT2, BOR42 '{$IFDEF HIGHSPEED} FREQ 50_000_000 '{$ELSE} FREQ 20_000_000 '{$ENDIF} STACK 16 ' ------------------------------------------------------------------------- ' I/O Pins ' ------------------------------------------------------------------------- acclx PIN RB.7 INPUT PULLUP TAC PIN RB.4 INPUT pullup LED1 PIN RB.0 OUTPUT LED2 PIN RC.4 OUTPUT NOPULLUP M1Ctrl PIN Rc.0 OUTPUT NOPULLUP M1Dir PIN Rc.1 OUTPUT NOPULLUP trigger PIN RA.3 OUTPUT NOPULLUP TX PIN RA.0 OUTPUT NOPULLUP ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- Tdone_mask CON %00000010 Adonex_mask CON %00010000 TBad_mask CON %00000100 ABad_mask CON %00100000 PB01 CON %11111101 'low to hi PB10 CON %00000010 'hi to low PB31 CON %11111111 PB30 CON %11110111 PB3Msk CON %00001000 isOn CON 1 isOff CON 0 Yes CON 1 NO CON 0 CompEn CON 0 cmp CON $08 'comparator enable mode WkedB CON $0A 'Edge detect WKpndb CON $09 'wake pending '{$IFFREQ =50_000_000} motorFreq Con 230 'establishes base motor frequency '{$ELSE} motorFreq Con 55 'establishes base motor frequency '{$ENDIF} pwid Con 50 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- Flags VAR Byte Indx VAR Byte tmpW1 VAR Word tmpW2 VAR Word tmpW3 VAR Word AccResult VAR Word PWMWID VAR Word TacResult VAR Word AccDelta VAR Word TacDelta VAR Word 'indxa VAR Byte tmpB1 VAR Byte @tmpW1_lsb tmpB2 VAR Byte @tmpW1_msb tmpB3 VAR Byte @tmpW2_lsb tmpB4 VAR Byte @tmpW2_msb tmpB5 VAR Byte @tmpW3_lsb tmpB6 VAR Byte @tmpW3_msb 'flags1 Var Byte TState VAR Flags.0 TDone VAR Flags.1 TSkip VAR Flags.2 AStatex VAR Flags.4 ADonex VAR Flags.5 Tinhib VAR Flags.3 AccRun VAR Flags.6 Sign Var Flags.7 MtrArray VAR Byte(8) m1ACC VAR Byte @ MtrArray(0) 'accumulator for pwm m1portb VAR Byte @ MtrArray(1) 'byte to send to port to run motor PwmPin Var m1portb.0 'how we turn pwm on/off Motoron VAR m1portb.1 'motor is running or not m1Speed VAR Byte @ MtrArray(2) 'motor speed M1Phase VAR Byte @MtrArray(3) 'pwm phase for motor isr M1Delay VAR Byte @MtrArray(4) 'motor delay for pwm frequency Speed VAR Word @MtrArray (5) 'motor speed ' ========================================================================= '{$IFFREQ <50_000_000} INTERRUPT NOPRESERVE 100_000 '{$ELSE} INTERRUPT NOPRESERVE 230_400 '{$ENDIF} ' ========================================================================= ISR_Start: ASM Bank mtrArray 'the motorctl stuff is here sb motoron 'The motor has not been enabled clrb m1ctrl 'turn the motor off jnb motoron,motor_done 'if off exit mov W,#motorfreq ' djnz m1Delay,motor_done dec m1Delay SZ jmp motor_done mov m1Delay,w setb Trigger 'Set oscilloscope trigger setb PwmPin 'Set PWM bit in advance csb M1Acc,M1Speed ' If PWM value reached, clrb PwmPin ' clear PWM bit inc m1Acc ' Increment current value mov w, #100 'Test if PwmAcc = 100 mov w,m1acc -W snz 'if so, clr m1Acc 'clear PwmAcc mov rc, m1portb 'Output port data clrb Trigger 'Clear oscilloscope trigger BANK 0 endasm motor_done: ISR_Exit: BANK 0 RETURNINT ' {cycles} ' ========================================================================= ' Subroutine / Function / Task Declarations ' ========================================================================= DELAY_MS SUB 1, 2 ' ========================================================================= PROGRAM Start ' ========================================================================= Start: PLP_A = %0000_0000 PLP_B = %0001_0001 PLP_C = %0000_0000 BANK @ MTRARRAY \SETB motorOn BANK __DEFAULT Main: m1Speed = 10 BANK @MTRARRAY do while m1Speed < 100 BANK @MTRARRAY m1Speed = m1speed + 5 ' BANK __default Delay_MS 2000 Loop put @m1speed,0 DELAY_MS 500 goto main '---------------------------------------------------------- ' DELAY_MS encapsulates pause into a subroutine ' enter with pause duration in __wparam12 '---------------------------------------------------------- SUB DELAY_MS msDuration VAR __WPARAM12 \ SB __PARAMCNT.1 ' skip if word \ CLR msDuration_MSB ' else clear for byte PAUSE msDuration ENDSUB ' ------------------------------------------------------------------------- ' ========================================================================= ' User Data ' ========================================================================= I use CTL D if I want to Debug and I use CTLP when I want to program. I remove the power and the SXKEY after programing and insert the 20 Meg resonator. I have to admit, I have been running all of my stuff so far under SXKEY in DEBUG mode this is my first shot at running standalone. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=365722 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)