Darrel's SPWM and LCDOUT


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Feb 2007
    Posts
    37

    Default Darrel's SPWM and LCDOUT

    Hi to all, and in specific mode to Darrel.

    Using a Darrel's SPWM with a 16F877, to generate 5 SPWM at 100 Hz, and duty cycle of max 64 steps, the PWM works perfectly, but writing on the LCD I can see improper/wrong character on the display.

    I suppose there are timing problema genrate by the SPWM. This ipothesy can be confirmed?

    Exist a way to write in reliable way to the LCD when SPM is running?

    Please take note that I have used 4 bit mode for the data transfer to the LCD.

    Ciao

    Leo

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code?
    And maybe, maybe not. If your LCDs are slow and don't respond quick enough, then you might not be able to fit 10ms of display data inside of a 100Hz PWM loop without the code jumping out of the LCD portion, into the SSPWM portion, and back.

  3. #3
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Based on interrupt so jumps in out much more

    Quote Originally Posted by skimask View Post
    Code?
    And maybe, maybe not. If your LCDs are slow and don't respond quick enough, then you might not be able to fit 10ms of display data inside of a 100Hz PWM loop without the code jumping out of the LCD portion, into the SSPWM portion, and back.

    Although 10ms is the cycle duration still for software PWM of 64 steps it does enters the ISR at least 64 times in that 10ms. Correct me if I am wrong.

    However that should not be much problem since it is interrupt based. What happens when all the PWM channels have the same duty cycle.
    Regards

    Sougata

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I would suspect an R-M-W problem.

    What pins are the LCD on?
    And, which pins are the SPWM on?
    <br>
    DT

  5. #5
    Join Date
    Feb 2007
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I would suspect an R-M-W problem.

    What pins are the LCD on?
    And, which pins are the SPWM on?
    <br>
    Hi Taylor, what means R-M-W ?
    Follow the LCD pins setting:

    Define LCD_DREG PORTD 'set LCD data bus port
    Define LCD_DBIT 4 'set data bus start
    Define LCD_RSREG PORTD 'set LCD Register Select port
    Define LCD_RSBIT 2 'set RS bit
    Define LCD_EREG PORTD 'set LCD Enalble port
    Define LCD_EBIT 3 'set Enable bit
    Define LCD_BITS 4 'set LCD bus size
    Define LCD_LINES 4 'set number of lines of LCD
    DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
    DEFINE LCD_DATAUS 70 ' Set data delay time in us

    and for the SPWM

    ASM
    SPWM_LIST macro ; Define PIN's to use for SPWM
    SPWM_PIN PORTB, 5, _DutyVar1 ; RED
    SPWM_PIN PORTB, 4, _DutyVar2 ; GREEN
    SPWM_PIN PORTB, 3, _DutyVar3 ; BLU
    SPWM_PIN PORTB, 2, _DutyVar4 ; WHITE
    SPWM_PIN PORTB, 1, _DutyVar5 ; SYNK
    endm
    SPWM_INIT SPWM_LIST ; Initialize the Pins
    ERRORLEVEL -306 ; Avoid Crossing page boundary "Message[306]"
    ENDASM

    and this is the main loop that work correctly for tree or four seconds, then seems that the display go out of sink and I see scrambled data as for the attached images.

    Forever:
    Lcdout $fe, $80, "MMMMMMMMMMMMMMMMMMM" ' move cursor to beginning of firt line
    Lcdout $fe, $c0, "VVVVVVVVVVVVVVVVVVV" ' move cursor to beginning of second line
    Lcdout $fe, $94, "HHHHHHHHHHHHHHHHHHH" ' move cursor to beginning third line
    Lcdout $fe, $d4, "YYYYYYYYYYYYYYYYYYY" ' move cursor to beginning of fourth line
    hSerout ["|"]
    pause 400

    Lcdout $fe, $80, "1111111111111111111" ' move cursor to beginning of firt line
    Lcdout $fe, $c0, "2222222222222222222" ' move cursor to beginning of second line
    Lcdout $fe, $94, "3333333333333333333" ' move cursor to beginning third line
    Lcdout $fe, $d4, "4444444444444444444" ' move cursor to beginning of fourth line
    pause 400
    GOTO Forever


    Also I have connected to ground the unused 4 input bit of the Optrex DMC20481 display and added a capacitor between VSS and VDD of the LCD, without visibile effect.

    Also consider that I have changed the display with other different brand and the symptom remain the same.

    Ciao

    Leo
    Attached Images Attached Images   

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    R-M-W is "Read-Modify-Write". It's the way PIC chips set an individual pin by reading the entire port, changing the 1 bit for the desired pin, then writing the whole port again. It can cause problems from time to time, but that is not the problem here. If the LCD and SPWM pins were on the same port it could have been. But I hadn't seen any code at the time, so I was guessing.

    And to keep from guessing again, could you post the whole program?

    I've run LCD's with SPWM before, so I don't think there's a common cause that I could point to. Hoping there's something else going on.
    <br>
    DT

  7. #7
    Join Date
    Feb 2007
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Darrel's SPWM - stop/start SPWM

    Hi to all.

    I never stop to thaks Darrel for he very useful SPWM.

    Using it, I have found the necessity to stop and then later start or restart restart the SPWM having the same value for each SPWM channel.

    During the stop period all the channels/pin should be set high or low a desidered.

    Could you please suggest the best way to stop and start the SPWM.

    Ciao

    Leo

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I think you just need to start/stop Timer1
    Code:
    TMR1ON=0    ' Stop Timer1
    TMR1ON=1    ' Start Timer1
    OR, you disable/enable the TMR1 interrupt
    Code:
    @   INT_DISABLE TMR1_INT 
    @   INT_ENABLE  TMR1_INT
    and then, you set your pin the way you want.
    Last edited by mister_e; - 20th April 2008 at 11:56.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Talking

    Hi,

    Having a look to the listing ...

    line 2 : CLEAR ' Clear all variables to 0LED


    ... OLEDS are far slower than classical LCDs ...

    I think we already had this discussion on the Forum ...


    Cool ... this is not an OLED Display !!! .........LoL !


    May be DEFINE LCD_DATAUS could be a little bit raised ( 44 > 50 i.e. )

    Alain
    Last edited by Acetronics2; - 20th April 2008 at 13:22.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Wirecut View Post
    I never stop to thaks Darrel for he very useful SPWM.
    You are very Welcome Leo. Glad you could use it.

    Using it, I have found the necessity to stop and then later start or restart restart the SPWM having the same value for each SPWM channel.

    During the stop period all the channels/pin should be set high or low a desidered.

    Could you please suggest the best way to stop and start the SPWM.
    Well,
    Just stopping the Timer or Disabling the interrupt will leave everything in mid-cycle.
    Then turning the Timer back on later will cause all channels to finish the cycle it was in the middle of, and continue with the dutycycle last assigned.

    I think the best way is to set all the DutyCycles to either 0 or the Max Res +1. Which will give an orderly "Stop" at the end of the Cycle.

    If the DutyCycle variables are grouped in an array like shown in my original examples, then you can just do a FOR loop, to assign them all to the same value.

    Code:
    For i = 0 to 4
        DutyVars[i] = 0
    Next i
    <br>
    DT

  11. #11
    Join Date
    Feb 2007
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    many thanks for your suggestion.

    I will try to implement both solution either 0 or the Max Res +1.

    Ciao

    Leo

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