Darrel's SPWM and LCDOUT


Closed Thread
Results 1 to 23 of 23
  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
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Maybe just a LCD clear... or PSU noise.. who know?

    LVP_NOT set to OFF.. huh... how bad things could go with it...
    Last edited by mister_e; - 2nd April 2008 at 00:30.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    What surprises me is that the entire line changes to a different character.

    If it was a timing problem from the interrupts, I'd think it would be more Random.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Looks like the PIC itself reset here and there... i still bet on some kind of noise... or UFO interferences... stack under/overflow?

    Fishing in the dark..
    Steve

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

  10. #10
    Join Date
    Mar 2008
    Location
    Gerogetown, Texas
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    Don't the DEFINES have to be in CAPs?

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


    Did you find this post helpful? Yes | No

    Default

    dEFINE, define or else variant will work, what's important it's on the right of it.
    Last edited by mister_e; - 2nd April 2008 at 01:36.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    I googled "Optrex DMC20481" and found a post on another forum suggesting that the LCD_COMMANDUS of 2000 was too low for that display. He said that 3000 worked for him.

    I pulled up the datasheet, and there doesn't seem to be any mention of the actual delays required. I guess if they're that bad, I wouldn't want to publish them either.

    Something to try.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default I had a different problem

    Hi,

    I once found that my LCD was spitting garbage and sometimes went blank. On inspection with the panel itself I found it would happen when a contactor picks up. My experiments.


    1. LCD changed with a different brand --> Reduced frequency of the problem but still exist
    2. LCD timing --> Reduced the missing display
    3. Remove shielding from the LCD mounting --> Problem almost gone

    4. Software measure taken:

    Use the Flag to re-initialize and clear the LCD after contactor pick up/drop.

    So what I mean to say is that in my case the LCD itself was picking up noise and not stable.
    Regards

    Sougata

  14. #14
    Join Date
    Feb 2007
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    I would make two things before posting the entire program.

    1- Change DEFINE LCD_COMMANDUS 2000 to 3000.

    2- If point 1 not fix the trouble, reduce the program to minimum in order to have the repeatability of the trouble with minimum statements.

    I will make this activity this evening (Italian time).

    Ciao

    Leo

  15. #15
    Join Date
    Feb 2007
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    Hi,

    the fail seems disappeared. I do not have made nothing!

    The only difference between yesterday and today in that yesterday was the first od April!!!

    Is almost tree hours that is running without any trouble on the LCD display.

    Attached there are the "failing" program.

    I leave running the program for the entire night.

    Ciao

    Leo
    Attached Files Attached Files

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


    Did you find this post helpful? Yes | No

    Default

    Steve

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

  17. #17
    Join Date
    Feb 2007
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    Ha ha ha ....

    seriously speaking, for the entire night have runned without display alterations or reset.

    .... mmmm ...

    Stange ... very strange. In the previous day I have loaded almost 20 .. 30 different version of the program and when it was running, after some minute the LCD show improper display, also using different brand of LCD.

    Also I have changed the PIC.

    Doule checking of the power supply and it is very good (7805 feeded with 12 Volt) and its stability is cecked wit a scope.

    I esclude some kind of reset because before entering into the LCD write loop, some other items is done and some writing is made on the serial port.

    I will inform you if the problem reappear.

    Ciao

    Leo

  18. #18
    Join Date
    Feb 2007
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    Hi,
    just to infom; no fail show up to date.
    Ciao

    Leo

  19. #19
    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

  20. #20
    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.

  21. #21
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    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 " !!!
    *****************************************

  22. #22
    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

  23. #23
    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 : 1

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