Adding these 2 lines should allow you to drive the pin.
ADCON1=15 'Set all A/D pins digital
CMCON=7 'Turn off comparators
Adding these 2 lines should allow you to drive the pin.
ADCON1=15 'Set all A/D pins digital
CMCON=7 'Turn off comparators
Shawn
If you look at section 19.5 of the datasheet for the 18F4620 you'll find this:So if you do a TOGGLE on a pin which has NOT be set to digital it will read '0', the bit will then flipped to '1' and written back to the port. Next time you do that TOGGLE it will again read the bit as '0' (even though it was previously set to '1'), flip that bit to '1' and write it to the port. Ie. it will never toggle it low because every time its told to toggle the bit it's read as low and gets toggled to high.When reading the Port register, all pins configured as analog input channels will read as cleared (a low level). Pins configured as digital inputs will convert as analog inputs. Analog levels on a digitally configured input will be accurately converted.
Page 224 in the same datasheet shows how to set ADCON1 up in order to configure the various pins as either analog or digital. And then there's the compartor as have been pointed out, see page 234. However for the 18F4620 the comparators are OFF by default so you strictly speaking you don't need to turn them off again. ALWAYS make a habit of checking IF you need to turn comparators off and/or enable digital mode on the pins you're using and HOW to do that - not all chips are the same.
/Henrik.
Yes, thanks all, Henrik is correct.
I can drive the pin low. I was losing confidence when TOGGLE did not blink. I just did not think about the need of TOGGLE to read the state of an analog pin to blink an LED.
The Olimex board came with LED hardwired to PORTA.0 I am doing ADC on 6 other A/E ports (replacing cadmium sulfide photoresistors with more durable phototransistors in eyes of solar dish trackers) (also replacing expensive pulse/I2C tilt accelerometers with cheaper analogs).
I can make the LED blink by adding 1 to a tracking bit and not use TOGGLE in this instance. I doubt the need for an LED on solar dish PC boards. PORTA.0 will be liberated. Thanks again -- Doug.
P.S. You can see progress -- Google -- matrix solar dish
Just ran into this on a 18F4431 trying to get a heartbeat to work inside a ISR using DT-INTS:
...Worked, while:Code:'**** TMR0 Int Handler ****** ToggleLED: HIGH PORTA.0 PAUSEUS 100 LOW PORTA.0 @INT_RETURN
Did not.Code:'**** TMR0 Int Handler ****** ToggleLED: TOGGLE PORTA.0 @INT_RETURN
Thanks for posting this. I don't know if I would have figured it out on my own.
Bo
Did you happen to try LATA.0 vs PORTA.0 ?
Like this
Code:'**** TMR0 Int Handler ****** ToggleLED: TOGGLE LATA.0 @INT_RETURN
Just tried it. Works wonderfully.
One benefit of "HIGH, PAUSEUS, LOW" way is that I can only get brief flash, which is nicer to look at for a heartbeat, but the other side of that, is that with the "TOGGLE LATx", you can save some time in the ISR by eliminating the pause.
Thanks for the heads up.
Mark
Bookmarks