PDA

View Full Version : Serial LCD on 12F675



anj
- 31st March 2004, 00:57
Gday all
I have been using a 12F675 to do a 10bit ADC then output a corresponding 28Hz PWM signal ( manually generated ), to control a small DC motor.
If ADC is > 512 first pin held low and second pin outputs pulses.
If ADC is < 512 first pin outputs pulses and second pin held low.
Thus i get speed and direction from a single pot.

To validate my ADC readings i hooked up a serial LCD to output the values and all i got was garbage.
When i stopped generating the PWM it all worked again.

I then tried just turning on two leds, ie
one on if ADC > 512 and
other for ADC < 512.
LCD still gave garbage
As such, it appears that turning on other pins can affect what goes out on the SEROUT pin hence resulting in my LCD losing the plot ????
Setup is ADC on GP0
LCD on GP1
LEDs/outputs on GP4/GP5
config bit set to 21EC ie internal oscillator
Power supply is good and i have current limiting resistors on the LEDS. ( Total power draw is within specs for chip )
Any ideas on if the 12F675 suffers crosstalk, resets itself internally between operations??
I have tried pulldown resistors on GP1 and that didnt help.
Andrew

Melanie
- 31st March 2004, 06:41
Since you are running on internal oscillator, what speed (baud rate) are you sending to your Serial LCD? It is quite possible that with additional loading on the 5v line there is a small effect on the internal oscillator (which is only approximately 4MHz at best) and is sufficient for it to introduce significant errors at higher baud rates. Drop your baud rate down to 2400 or less.

Melanie

anj
- 31st March 2004, 11:54
Gday Melanie
Thks for the reponse but I think the problem is a bit deeper.
Ps i am running at 2400baud

My serial LCD controller has a switchable data inverter and i was using my Pic in True mode to match what it was set at.
In this mode it worked until i tried to set another pin on the Pic, in which case it started to fail again. This was intermittent, but i have now traced it back to if there is a pause after the pin is set.
I swapped the LCD mode and then drove inverted from the Pic and it worked perfectly under all circumstances.
Next i stuck a CRO on the serout pin to see what was happening.
When just doing a serout, in True mode, the trace defaults to high and pulls low on data.
In Inverted mode it defaults to low and pulls high on data.
After any other pin is set, and then followed by a pause, the serout pin is actively pulled low during the pause time.
This occurs in both modes, hence resulting in the LCD going haywire in true mode, as it should be pulled high in this case.
I then thought i'd be sneaky, and if in true mode, manually force the serout pin high just before i set the other pins, to keep it high until the next serout. ie
GPIO.1 = 1 <- serout pin
GPIO.4 = 0
GPIO.5 = 0
to my dismay, after the last line, GPIO.1 appears to have been pulled low again, and it fails as per usual
then i tried
GPIO.4 = 0
GPIO.5 = 0
GPIO.1 = 1
and this works like a charm, with GPIO.1 staying high
I now know how to fix it but i think there is some wrong logic going on somewhere when the serout mode is true.

Andrew

test program used as per below
failure is when pot is roughly centred, comes good each side of centre
--------------------------------------------------------------------------------------------
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
serpin con 1 ' lcd output pin
sermode con 0 ' output mode driven true, fails after any pin is set???
'sermode con 4 ' output mode driven inverted

XVal var word
ADCON0 = %10000001 ' Configure and turn on A/D Module:
' Right justify result, use Vdd pin, channel 0
TRISIO = %00000001 '

init: 'initialise LCD
pause 1000 ' wait for lcd to start
SerOut serpin, sermode, [ $FE, 1 ] 'clear screen 2x to setup
pause 100
SerOut serpin, sermode, [ $FE, 1 ]
pause 100
start:
ADCIN 0, XVal
pause 250
loopret:
if ( XVal > 470 ) and ( XVal < 550 ) then
GPIO.1 = 1 ' if this is uncommented it fails
GPIO.4 = 0
GPIO.5 = 0
' GPIO.1 = 1 ' if this is uncommented it works
endif
pause 750
SerOut serpin, sermode, [ $FE, 2, #Xval, " " ] 'Display the decimal value
goto start
end

Melanie
- 31st March 2004, 12:22
I'll see if I can find a few minutes at the end of the day and try to replicate your problem.

anj
- 1st April 2004, 00:11
Gday Melanie
I have continued mucking around with this and have eliminated the LCD and ADC, and now have a very basic example that fails
on demand.
To allow me to get a decent CRO result i have also reset the pause time.
'set CRO timebase to 2mS for best results
-----------------------------------
serpin con 1 ' serial output pin
sermode con 0 ' output mode driven true, fails after any pin is set???
ANSEL = 0
TRISIO = %00000000 '
start:
SerOut serpin, sermode, [ "T" ]
1) GPIO.1 = 1 <-serout pin
2) GPIO.4 = 0
3) GPIO.1 = 1 <-serout pin
pause 6
goto start
end
-----------------------------------
results i get are
Pulse OK with idle time HIGH ( Ie std serout no other ops )
1), 2) and 3) commented out. ( std serout )
1) only commented out.

Pulse OK with idle time LOW ( Ie incorrect )
3) only commented out.
1) and 3) commented out.

over to you.
Andrew

Dont worry, ive got it. I found an FAQ on the MEL american site re the 16F675 defaulting its comparator to ON. I have been using a 16F88 up till now and that defaults to off, hence i didnt even think to check it.
Interestingly enough, my serout was on the -ve comparator input, so not sure why it behaved that way.
Anyway, i add CMCON = 7 at the top and she appears to be happy. Sorry for wasting yr time.
Andrew