16F876A Pulsin issues


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Mar 2010
    Posts
    52

    Default 16F876A Pulsin issues

    Hi All,

    After my successful Glow igniter project I have now moved onto trying to make an all in one setup / testing unit using a 16F876A and a Hitachi LCD module.

    I have been able to output standard strings to the LCD (Startup instructions, menu etc) however I am now looking to get started with the servo and Receiver side of the project.

    What I am looking to do is read in the pulsin value from the Rx and display it on the screen (sounds simple as I used this for the glow project), but this seems to not be working on the 16F.

    What I get on the screen with the code below (stripped out the menu structures for testing) is the word "Pulse" with the space and then a strange alphanumeric single character which varies depending on the stick position of the transmitter (Clearly its picking up something).

    My first though is that I'm using WORD to store the incoming value, however this has worked previously with the 12F PIC i used for the glow project.

    Code:
    @ DEVICE PIC16F876A,HS_OSC,LVP_OFF,WDT_OFF,PROTECT_OFF
    
    DEFINE OSC 20	'20 MHz Osc
    DEFINE LCD_COMMANDUS 2000
    TRISB = %00000001 'Set PortB.0 as input for Rx
    
    Rx	    Var	    PORTB.0  'Rx input
    servo   var     PORTB.1  'Servo output
    
    P       VAR     word    'Pulse Input
     
    pause 2000	' Allow LCD to init
    
    Main:
        PulsIn Rx,1,P                    'Read in Rx input
        pulsout servo, P                 'output to a servo connected on B.1
        Toggle PORTB.5
        LCDOUT $FE, 1, "Pulse"," ", P    'Output to LCD
        LCDOUT $FE, $C0," ", P           'Testing on the second line
    goto main:
    	
    End
    Any ideas why my "P" does not output the correct value to the LCD? I would expect something between 100-200 as a numeric value.

    Could it be that the 20Mhz crystal is too fast as this would give me a 2us resolution? (I noticed that the servo was moving in really tiny increments)

    Many Thanks
    Rob

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    P is a NUMBER not a displayable ASCII value.

    If you want to display the numeric value on the LCD, it needs to be converted. Prefix it with either a hash # in the form

    LCDOUT $FE, 1, "Pulse"," ", #P

    or with the word DEC in the form

    LCDOUT $FE, 1, "Pulse"," ", DEC P

    PS, you could of course include the extra SPACE on the end of your word "Pulse " like...

    LCDOUT $FE, 1, "Pulse ", DEC P
    Last edited by Melanie; - 30th March 2010 at 07:53.

  3. #3
    Join Date
    Mar 2010
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Hi Melanie,

    Firstly, wow, thank you, :-) all the reading up I was doing last night and I cant believe I missed that, :-), makes sense and I'm sure it will work (will have to wait till I get home from work to test it - note to self, bring board to work)

    Another probably small issue I have is the pic does not seem to be driving the servo correctly, in the 12F I could simply do a pulsin on one pin and pulsout to another pin which would control the servo no problem (Planing to use this as a failsafe - want to read in a switch channel and depending on the position I'll output either direct to the servo or via another pic or Arduino for navigation), however now with the 16F the servo moves in one direction but extremely slowly, like 1mm every 5 minutes, its almost as if the resolution is so high its moving in tiny steps, could this be caused by the 20Mhz osc?

    Thanks again
    Rob

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    The value of P (or other timing) may well reveal why.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi, Bobbo

    Try this

    Code:
    ...
    
    PAUSE 2000
    LCDOUT $FE, 1, "Pulse"," "
    
    Main:
        PulsIn Rx,1,P                    'Read in Rx input
        LOW servo
        pulsout servo, P                 'output to a servo connected on B.1
        Toggle PORTB.5
        LCDOUT $FE, $80+7,  # P    'Output to LCD
        LCDOUT $FE, $C0+1,# P           'Testing on the second line
    goto main:
    
    ...
    Servo will follow the input signal ...

    Alain
    Last edited by Acetronics2; - 30th March 2010 at 10:15.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  6. #6
    Join Date
    Mar 2010
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    I feel like such a rookie, :-) I should have look at more of my previous code, :-)

    Code:
    pulsin gr,1,g	
    pulsin rx,1,P          
    low throttle
    pulsout throttle, P
    Thanks exactly what I had in a previous project, :-)

    Can't wait to get home now, :-)

    Will post pics once I have it programed and working, hope to build up a nice multi function test unit - once thing im still investigating is how to measure the battery voltage of a 4 cell flight pack (nicad or nimh) with a 250ma load, im using the units 5.02V regulated supply as a reference but not quite sure if I could just give the flight pack's V to the ADC through a resistor and work from there? 4 Cell fully charged will give me 5.6V and I dont know what the ADC does when the voltage is higher than the reference V, also could the pic handle the extra .6V?

    On a side note I'm still hunting down a case for my LM35 project, finally got some ally tubing to house the sensor, just need to find a nice case for the PIC and water proof it, :-) (will post pics etc as well once complete)

    Kind Regards
    rob

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