Idiot, trying to be a programmer!


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2009
    Posts
    18

    Default Idiot, trying to be a programmer!

    '************************************************* ***************
    '* Name : New_PWM.bas *
    '* Author : Roddy Wayne *
    '* Notice : Copyright (c) 2008 *
    '* : All Rights Reserved *
    '* Date : 08/09/2008 *
    '* Version : 1.0 *
    '* Notes: *
    '* *
    '* A PWM for running a Hydrogen Generator *
    '************************************************* ***************


    CLEAR ;always start with clear
    DEFINE OSC 4 ;define oscillator speed
    DEFINE ADC_BITS 8 ; Sets number of bits in result
    DEFINE ADC_CLOCK 3 ; Sets clock source (3=rc)
    DEFINE ADC_SAMPLEUS 50 ; Sets sampling time in uS
    define DEBUG_REG PORTC
    DEFINE DEBUG_BIT 6
    define DEBUG_BAUD 2400
    DEFINE DEBUG_MODE 0
    DEFINE DEBUG_PACING 1000
    Low PORTE.2 ;makes low for write only
    TRISA = %00001111 ;sets 0, 1, 2, and 3 as porta inputs (A to D's & ref's)
    TRISB = %00111111 ;sets bits 6 & 7 portb pins as outputs, 0 thru 5 as inputs
    TRISC = %10111111 ;sets port c.6 for serial output
    TRISD = %00000011 ;sets PORTD 0,1, lines to inputs, rest to outputs
    TRISE = %00000000 ;sets all PORTE lines to outputs
    potpos var BYTE ;potpos is 8 bit
    cellamps VAR BYTE ;cellamps is 8 bit
    A2D_V VAR BYTE ;Created A2D_V Value to store result
    A2D_V2 Var BYTE ;Created A2D_V2 Value to store result
    ;ADCON1=%10000011 ;Sets the Analog to Digital control register to 4 Channels
    ;with Vref+ and Ground
    ;ADCON1=%10000010 ;Sets the Analog to Digital control register to 5 Channels
    ;with +5 VDC and Ground as the references!


    Start:


    If portc.0 = 0 then portb.6 = 0 'If pin 15 is low, make pin 39 low
    If Portc.0 = 1 then portb.6 = 1 'If pin 15 is high, make pin 39 high
    'When Pin 39 goes high, this turns the
    'pump on! I'm using a Darlington pair
    'to do this (Part # TIP120) It also turns
    'on the "Pump On" LED.
    If portc.3 = 0 then portb.7 = 0 'If pin 18 is low, make pin 40 low
    If portc.3 = 1 then portb.7 = 1 'If pin 18 is high, make pin 40 high
    'When Pin 40 goes high, the "Low Tank
    'Water" LED is turned on!

    ADCON1=%10000010 '?? Setup to read analog inputs
    ADCIN 0, A2D_V 'Read channel 0 to A2D_Value
    Pause 50
    ;DEBUG 14, 1, BIN8 A2D_V *
    ;Pause 1000 *
    potpos= 1+(((255-1)*A2D_V)/255) ;*
    Debug 14, 1, "Pot Position =", 32, DEC3 potpos, 13 ;*
    Pause 50 ;*

    ************************************************** **********************************************

    I wrote the above code a long time ago and then, lost my hard drive
    without having it backed up! I'm not sure if the code above ever ran
    properly but, it is the only code that was saved.

    The problem I'm having with it is that "potpos" should be a Byte wide
    but I'm only getting changes in the 0 & 1 bits of the Byte while varying
    the input between 0 and + 5 VDC.

    Can anyone help this "Idiot, trying to be a programmer"?

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Which chip are you using?

    I do not see the need for the math
    potpos= 1+(((255-1)*A2D_V)/255)

    The same is
    potpos = A2D_V

    ???
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Apr 2009
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    Thanks for replying!

    The PIC is a 16F877

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    IF A2DV = 0 THEN Potpos = 1

    a small scale translating attempt to avoid value "0" ... probably !


    ... I know ... he could have written

    POTPOS = A2DV MAX 1 ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Just a guess...
    This makes the ADC right justified
    Code:
    ADCON1=%10000010 '?? Setup to read analog inputs
    This will make it left justified. Left justified is "normal"for 8 bit.
    Code:
    ADCON1=%00000010
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Apr 2009
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    Thanks Guys!

    I've made it work. I changed ADCON1=%10000010 to ADCON1=%00000010 and this fixed the problem. So, your guess was exactly correct!

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Well, it was an educated guess....
    That is why I asked about the chip being used so I could look at the correct data sheet
    Have FUN!!!
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Melabs U2 Programmer Command Line Options
    By Robert Wells in forum General
    Replies: 5
    Last Post: - 3rd July 2009, 02:11
  2. problems with USB programmer
    By malc-c in forum General
    Replies: 7
    Last Post: - 10th May 2007, 20:14
  3. USB programmer problems
    By uiucee2003 in forum USB
    Replies: 2
    Last Post: - 15th August 2006, 23:47
  4. Melabs USB Programmer
    By tmurph in forum General
    Replies: 1
    Last Post: - 25th December 2005, 03:25
  5. General Programmer Questions
    By mslaney in forum General
    Replies: 1
    Last Post: - 17th December 2004, 18:16

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