MPLAB SIM timing vs Real life


Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Feb 2006
    Posts
    21

    Default MPLAB SIM timing vs Real life

    Hello again.

    Still using PIC16F876A...

    This bit of code works quiet well: ie The PWM appears as expected on both channels.

    DEFINE OSC 20 ' use 20mhz xtal.
    DEFINE HPWM1_TMR 2 'Use timer 2 for both channels
    DEFINE HPWM2_TMR 2
    DEFINE CCP1_REG PORTC ' Hpwm 1 pin port
    DEFINE CCP1_BIT 2 ' Hpwm 1 pin bit
    DEFINE CCP2_REG PORTC ' Hpwm 2 pin port
    DEFINE CCP2_BIT 1 ' Hpwm 2 pin bit
    CVRCON = 0 ' DIS-ABLE REFERENCE MODULE
    CMCON = 7 ' Disable analog comparator
    ADCON1 = 7 ' Set Port to digital
    TRISA = 255 ' SET PORTA TO INPUTS
    TRISB = 0 ' SET PORTB TO OUTPUTS
    TRISC = 0 ' SET PORTC TO OUTPUTS
    MAIN:
    goto R_FWD ' Got here by doing the right thing.

    R_FWD:
    IF STEERY > (THROTL*2) THEN ' PREVENTS DECREASING PWM FROM GOING BELOW 0
    STEERY = (THROTL*2)
    ENDIF
    HPWM 1, THROTL, 2000
    HPWM 2, THROTL-(STEERY/2), 2000
    PORTC.7 = 0 'LEFT_BACKWARD OFF
    PORTC.6 = 1 'LEFT_FORWARD ON
    PORTB.5 = 1 'RIGHT_FORWARD ON
    PORTB.4 = 0 'RIGHT_BACKWARD OFF
    PORTB.6 = PORTB.5 & PORTC.1 'RIGHT_PWM_FORWARD
    PORTB.7 = 0 'RIGHT_PWM_BACKWARD OFF
    PORTC.4 = PORTC.6 & PORTC.2 'LEFT_PWM_FORWARD
    PORTC.5 = 0 'LEFT_PWM_BACKWARD OFF
    RETURN

    However; when I run the simulator, I see the PWM on PORTC.1 and PORTC.2 as expected but the output on PORTC.4 and PORTB.6 is slower by an order of magnitude.
    Is this the simulator or some kind of aliasing, or is this as fast as the chip can run?
    I've changed the frequency from as low as it can go 1221 to as high as 5000 without much change in the simulated outputs. If I set it much faster than that then the PORTB.6 and PORTC.4 outputs stay on all the time. Again I repeat... the PWM outputs look like they should.
    I was hoping the simulator would let me avoid having to build a hardware prototype.
    Anyone have much experience with MPLAB SIM?
    Attached Images Attached Images  
    The less you expect, the more you get.

Similar Threads

  1. MPLab SIM question
    By presario1425 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 3rd December 2007, 21:22
  2. Linker/COFF debugging in MPLAB SIM
    By RichardBowser in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th January 2007, 18:28
  3. Using MPLAB SIM
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th July 2006, 04:20
  4. Tracing code in MPLAB Sim
    By ErnieM in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th August 2005, 16:00
  5. pause loop lockup with mplab sim
    By power67 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th February 2005, 13:10

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts