Reputation: 1638
I have an pic 18f87j50. At one of my digital I/O's let's say RH7, I want to use it to give me an 0-3,3V signal. I configure it as an output and produce a PWM so I read 2V on my oscilloscope. Then I try to "release" the port to make it floating there, at this 2V level. When "releasing" I make the port as an input and make sure the intern pull-up is disabled.
But I really don't succeed with this, it looks like it float back very fast to 3.3V almost as the pull-up would still be enabled. I have no load on the port.
Next step is to place a OP-amp there to make an 0-10V signal.
Am I doing this right? -> Port output, pwm signal to desired level, disable internal pull-up, make port input so floating may start.
Upvotes: 0
Views: 274
Reputation: 1638
Actually, when I first wrote this question I forgot to mention that I had a special circuit directly connected to the ports output. When the pwm where realesed, it contained that circuit hold the specific voltage level for some seconds.
The first circuit was poorly designed causing it not to work properly and made the voltage level to drop as soon as the pwm was killed.
Now it works. When pwming who creates a 2 voltage output within a loop for 1ms, release and then continue on with rest of my program, the circuit holds the last known voltage for a couple of seconds without droping.
The special circuit is just made from some capacitators and an OP.
So... It was a hardware fault! Sorry for that.
Upvotes: 0
Reputation: 18349
If you want to maintain the 2V level generated by the PWM, you can't turn off the PWM.
I'm not sure what you are trying to achieve by "releasing" the port.
I can't help too much with the hardware stuff ...
Update after the comment:
If you can, use a pin where you have hardware support for the PWM doing what you want. If you can't change the layout, you probably need to keep doing it in software. I don't know what hardware support you have for RH7 to do that on your chip, the assignment to the PWM varies with the processor pin count.
This is some code I use to configure PWM in a product based on the PIC18F87J60. Once this is set up, there is no further software involvement.
/*
* Configure the powersupply to the external serial port. To do this,
* we configure a PWM to control the isolated 3V power supply.
*/
TRISC1 = 1;
TRISC2 = 1;
PR2 = 0xFF;
CCP1CON = 0x0c; /* PWM mode, active high, single output */
CCP2CON = 0x0e; /* PWM mode, active low, single output */
CCPR1L = 0x80; /* 50% duty cycle */
CCPR2L = 0x80; /* 50% duty cycle */
ECCP1AS = 0; /* auto shutdown off */
ECCP2AS = 0; /* auto shutdown off */
PIR1bits.TMR2IF = 0;
T2CON = 0x04; /* Enable T2 timer, prescale and postscale 1:1 */
while (!PIR1bits.TMR2IF)
;
TRISC1 = 0;
TRISC2 = 0;
Upvotes: 1
Reputation: 272667
If you set the pin to be an input, it will not sit at any particular voltage. This approach will not work.
If you want a controllable voltage level, your only option (without using extra hardware) is to use the CVREF pin, which can be controlled as described in chapter 24 of the data-sheet.
Incidentally, I'm not sure how you could be seeing 2V on a digital output (assuming your supply is 3.3V).
Upvotes: 1