PIC16F84A using pulsout and TMR0


Closed Thread
Results 1 to 33 of 33

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Posts
    33


    Did you find this post helpful? Yes | No

    Post

    Thanks to the reply.
    Solar PV also called photovoltaic cell (direct absord sunlight and generate electricity).

    ***LCDOUT $fe,$1, #solarvoltage*****

    Thus, the LCD only can display the value not above 5 volt,am I right??
    If this is the case, if I want to display value above 5v on the LCD then is that possible.

    If I'm using 4 Mhz crystal, do I need to have this sentences ***DEFINE ADC_CLOCK 3****?????


    Thanks and please advice.
    Last edited by DragonBall_6; - 13th December 2006 at 00:40.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Maybe I am right . . .

    Quote Originally Posted by DragonBall_6
    Thanks to the reply.


    Thus, the LCD only can display the value not above 5 volt,am I right??
    If this is the case, if I want to display value above 5v on the LCD then is that possible.

    .
    Hi DragonBall_6,
    What the voltage divider does is input voltage based upon the resistors ratio into the pic pin and hopefully limit it's input voltage to TTL levels. You have to write the code to do the math and then output the voltage numbers to suit your purpose. If you store the ADC value in a byte variable then ( and I am going out on a limb here as I am as new to pic programming as you are ) you should be able to express that as a number from 0 to 255. So if 5 v = 255 (input pin at 5 v when solar panel is at 15 volts) then 255 = 15 volts.So with a given voltage divider you can express 15 volts incremented in 255 steps. Anyone out there who is more knowledgable please ring in!
    JS

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Just as Joe says, the two resistors forms a voltage divider that "divides" the voltage fed to it by the ratio between the two resistors. The upper one is 2.2 times larger than the lower one so will loose 2.2 times as many volts over that one than over the lower one. Or if you wish to put ohms law to the test:

    The total resistance is 3.2k, with a voltage of 15V there will be a current of (I = U / R) 4.6875mA flowing thru the two resistors. Now that current will produce a voltage over the lower resistor of (U = I*R) 4.6875V.

    Since the PIC's AD pin is connected in parallel with the lower resistor the PIC will "see" a voltage between 0 and 4.6875V when the voltage from the solar PV is between 0 and 15V.

    Now, in the code I showed you we set the ADCON1 register in a way that the ADC uses the PIC's powersupply as a reference voltage. What that means is that whatever the powersupply voltage is at the moment will produce the max reading from the ADC, so for the above to work it's important that the powersupply is stable at 5.0V.

    We also said
    Code:
    DEFINE ADC_BITS 10
    What that does is set the ADC code to give you a resolution of 10bits, or put another way, the result from the ADC will be between 0 - 1023. That is 0V on the input will give you 0 in SolarVoltage and 5V in will give you 1023 in SolarVoltage. The display will show that value, not the voltage.

    To get the display to show actuall volts you need to scale the value. With a powersupply of 5.0V each bit in the ADC result is 0.00488V (5/1024) so if the display shows 958 the voltage at the PIC pin is ~4.67V which in turn corresponds to ~15V from the solar PV. (See the voltage divider)

    Are you going to display the "real" voltage or just using the value to decide when to start the motor? If the later then you don't need to scale it at all, just use it as it is.

    The DEFINE ADC_CLOCK 3 tells the ADC module inside the PIC what clock source to use. It has nothing to do with the Xtal you are using to drive the PIC.

    /Henrik Olsson.

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


    Did you find this post helpful? Yes | No

    Default Just a simple add-on

    and '3' comes from the datasheet in the ADCON1 register setting (register 11-2, page 128) ADCS2 table
    Steve

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

  5. #5
    Join Date
    Nov 2006
    Posts
    33


    Did you find this post helpful? Yes | No

    Post A/D input

    Thanks to all the reply.
    I really appreciated it. I will try it at lab.
    Actually, I would like to receive A/D input from solar PV and after that there are 2 things to be done.
    First, IF the A/D input is less that 2 volt then stop the motor ELSE the motor activated.
    Secondly, at the same time A/D input from the solar pv is sent to the computer for processing and collected the data for every 15 minute. The result will be calculated and show in graph.
    It would need some knowledge of the visual basic as database and link between vb and ms excel.

    Somebody can guide me thru this?? Thank and please give advice.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Just compare the value you get from the ADC with the value that corresponds to 2V, if higher then run the motor, if lower then stop it, you can figure that out. You may need to introduce some hysteresis around the threshold.

    Then send the value to the PC using the PBP's SEROUT command, or even better use the USART, a MAX232 level shifter and the HSEROUT command, see the manual. There's many examples on the forum.

    For the PC/VB side have a look here: http://www.rentron.com/VisualBasic.htm
    Just send the raw value from the PIC and use VB to scale it to volts if you like.

    /Henrik Olsson.

  7. #7
    Join Date
    Nov 2006
    Posts
    33


    Did you find this post helpful? Yes | No

    Post Problem

    I had try the program that you gave me. It is work.Thank.
    Some problem has finding out....



    ***********'Produce squarewave on PortB.0 period~4.32s, 50% dutycycle.

    Loop var Word

    Main:
    High PortB.0
    For Loop = 0 to 2160 'Loop here for ~2.16s, tweak to match.
    PauseUs 1000
    Next
    Low PortB.0
    For Loop = 0 to 2160 'Loop here for ~2.16s, tweak to match.
    PauseUs 1000
    Next
    Goto Main**********

    The above is the code that you posted to me. Thanks to you again.
    I had modify it like the code below:-

    ********'Produce squarewave on PortB.0 period~4.32s, 50% dutycycle.

    Loop var Word
    SolarVoltage var word
    ADCON1 = %10001110

    Main:

    High PortB.0
    For Loop = 0 to 2160 'Loop here for ~2.16s, tweak to match.
    PauseUs 1000
    ADCIN 0,SolarVoltage
    LCDOUT $FE,$1,#SolarVoltage
    If SolarVoltage = 300 then
    high motor ' motor stop
    ELSE
    low motor ' motor run
    ENDIF
    If update = 1 then
    LCDOUT $FE,$C0,DEC2 Hour,":",DEC2 Minute,":",DEC2 Second
    ENDIF
    Next
    Low PortB.0
    For Loop = 0 to 2160 'Loop here for ~2.16s, tweak to match.
    PauseUs 1000
    ADCIN 0,SolarVoltage
    LCDOUT $FE,$1,#SolarVoltage
    If SolarVoltage = 300 then
    high motor ' motor stop
    ELSE
    low motor ' motor run
    ENDIF

    If update = 1 then
    LCDOUT $FE,$C0,DEC2 Hour,":",DEC2 Minute,":",DEC2 Second
    ENDIF
    Next
    Goto Main

    ON INTERRUPT
    '
    'Time calculation
    '
    '
    Update = 1 'update diaplay after 1 second*************


    The display: ****************
    0 ' when increase the A/D input, the value
    00:00:00 'increase to 0 then 1 then 2 then
    **************** 'maximum is 3

Similar Threads

  1. Pin won't stay high during Repeat...Until loop??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th August 2009, 23:57
  2. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  3. Battery powered applications
    By NavMicroSystems in forum Off Topic
    Replies: 7
    Last Post: - 22nd June 2009, 07:12
  4. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  5. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35

Members who have read this thread : 0

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