PDA

View Full Version : Darrel's SPWM and LCDOUT



Wirecut
- 31st March 2008, 17:53
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

skimask
- 31st March 2008, 18:08
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.

sougata
- 1st April 2008, 00:46
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.

Darrel Taylor
- 1st April 2008, 01:03
I would suspect an R-M-W problem.

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

Wirecut
- 1st April 2008, 21:52
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

Darrel Taylor
- 1st April 2008, 23:04
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>

mister_e
- 1st April 2008, 23:20
Maybe just a LCD clear... or PSU noise.. who know?

LVP_NOT set to OFF.. huh... how bad things could go with it...

Darrel Taylor
- 2nd April 2008, 00:42
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>

mister_e
- 2nd April 2008, 00:44
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..

DaveC3
- 2nd April 2008, 01:19
Don't the DEFINES have to be in CAPs?

mister_e
- 2nd April 2008, 01:31
dEFINE, define or else variant will work, what's important it's on the right of it.

Darrel Taylor
- 2nd April 2008, 04:12
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>

sougata
- 2nd April 2008, 06:02
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.

Wirecut
- 2nd April 2008, 09:07
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

Wirecut
- 2nd April 2008, 22:57
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

mister_e
- 3rd April 2008, 00:25
http://www.freegraphics.com/images/specials/af-cigar.gifhttp://www.freegraphics.com/images/specials/aprilfools-happyday.gif

Wirecut
- 3rd April 2008, 07:59
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

Wirecut
- 20th April 2008, 09:54
Hi,
just to infom; no fail show up to date.
Ciao

Leo

Wirecut
- 20th April 2008, 10:27
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

mister_e
- 20th April 2008, 11:32
I think you just need to start/stop Timer1

TMR1ON=0 ' Stop Timer1
TMR1ON=1 ' Start Timer1

OR, you disable/enable the TMR1 interrupt

@ INT_DISABLE TMR1_INT
@ INT_ENABLE TMR1_INT
and then, you set your pin the way you want.

Acetronics2
- 20th April 2008, 13:12
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

Darrel Taylor
- 20th April 2008, 21:26
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.


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

Wirecut
- 23rd April 2008, 22:30
Hi Darrel,

many thanks for your suggestion.

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

Ciao

Leo