What am I doing wrong ?


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    malc-c's Avatar
    malc-c Guest

    Default What am I doing wrong ?

    I have the need to pulsate an LED rather than just turn it on or off. I've modified the code I used for my model train detection project that used a 16F628A and have a working example on my bread board. Although its not rocket science I used the PWM command and a for next loop to increase the on time of the LED and thus its brighness. However given that this is just my second project with PBP I'm well chuffed that it worked with very few attempts.

    However, I really want to use a 12F675 so I copied and pasted the code, substituting PORTB.4 for GPIO.0 and compiled the code once the chip was selected in Microcode IDE. However it fails to work with the 12F675. Ive included the setting to make ports digital (I think) but it still fails, and I would really like some guidance here.

    This is the code for the 12F675

    Code:
    GPIO.0 = 0
    CMCON = 7 ' PortA Digital inputs
    VRCON = 0        ' Voltage reference disabled
    OPTION_REG.7 =    0
    
    
    @RC_OSC_NOCLKOUT 
    @WDT_ON
    @PWRT_ON
    @MCLR_OFF
    @BOD_ON
    @LVP_OFF
    @CPD_OFF
    @PROTECT_OFF
    
    led var GPIO.0
    
    i var byte 
    
    Main:
    For i = 0 to 255                                                 
    Pwm GPIO.0,i,1
    next i
    if i = 255 then goto down
    
    down:
    for i = 255 to 1 step -1
    pwm GPIO.0,i,1
    next i
    If i = 0 then goto main
    Is the software command PWM supported on all chips ? I thought it simply pulses the pin for a duration and cycle.

    Hope to hear from you guys soon

    Cheers

    Malcolm

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    Hi Malcolm,
    The 12F675 has comparators, which you correctly turned off with CMCON and VRCON but it also has an A/D and the the pin needs to be set to digital (I think).

    Try setting the ANSEL register and set the port to output with the TRISIO register.

    Code:
    TRISIO.0 = 0   'Set GPIO.0 to output.
    ANSEL.0 = 0    'Set GPIO.0 to digital.
    I think that is your problem.

    /Henrik Olsson.

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply.

    I've added those two lines to the code and I still get nothing out from the PIC.

    The top section of the code is:
    Code:
    TRISIO.0 = 0   'Set GPIO.0 to output.
    ANSEL.0 = 0    'Set GPIO.0 to digital		
    GPIO.0 = 0
    CMCON = 7 ' PortA Digital inputs
    VRCON = 0        ' Voltage reference disabled
    OPTION_REG.7 = 0
    I've double checked the hardware and the PIC is receiving 5v, but all pins other than GP5 remain low (0.1v, with GP5 +2.6v) - could it be something to do with the internal OSC setting ?? - I want to use the built in 4 Mhz OSC

    Malcolm

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Try these settings instead of yours especially for "RC_OSC_NOCLKOUT" ;

    Code:
    @ DEVICE PIC12F675, INTRC_OSC, WDT_OFF, MCLR_OFF,PROTECT_ON
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer
    Try these settings instead of yours especially for "RC_OSC_NOCLKOUT" ;

    Code:
    @ DEVICE PIC12F675, INTRC_OSC, WDT_OFF, MCLR_OFF,PROTECT_ON
    Thanks for the suggestion, but I now get a warning when I try to compile (using MPSAM) - it states "Found lable [DEVICE]" and "Illegal Opcode [12F675]"

  6. #6
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c
    Thanks for the suggestion, but I now get a warning when I try to compile (using MPSAM) - it states "Found lable [DEVICE]" and "Illegal Opcode [12F675]"

    In your code, put a space between '@' and "DEVICE"


    --------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  7. #7
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    change this

    if i = 255 then goto down

    to this

    if i = 0 then goto down

    and all should be well .....

    or better yet delete the line (it adds no value) and replace the last line of the program shown with this

    goto main

    (instead of the if-then, which adds no value)

    Paul Borgmeier
    Salt Lake City, Utah
    USA
    Last edited by paul borgmeier; - 9th June 2006 at 08:46.

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


    Did you find this post helpful? Yes | No

    Talking Simple !!! ... do it simple !!!

    Hi, Malc

    Don't you think a simple triangle slow wave generator based upon a 555 or a twin AOP could perfectly do the job ???

    Note a simple bulb lamp could also do all the job itsef ... with a rectangular wave input.

    mmmmh, back to the original idea ... you'll have to seriously slow down the PWM change rate ...

    May be intended for some stop light for road/rail crossing, I presume ???

    Alain

    PS : and why not use a lookup table, just to reproduce exactly the truth ( exponential rise and fall of enlightment ) ???
    just a " particular shape " wave generator ...in fact.
    Last edited by Acetronics2; - 9th June 2006 at 09:05.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  9. #9
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics
    Hi, Malc

    Don't you think a simple triangle slow wave generator based upon a 555 or a twin AOP could perfectly do the job ???

    Note a simple bulb lamp could also do all the job itsef ... with a rectangular wave input.
    Quite possibly, however that wouldn't improve my understanding of PBP

    Quote Originally Posted by Acetronics
    May be intended for some stop light for road/rail crossing, I presume ???
    Errr.. actually you don't want to know... Oh well all right..

    A friend wants to model the Tardis from the BBC series Dr Who... and it has a slow pulsing light on top..... me and my big mouth offered to help, and like I said it works fine on a 16F628a, but I just need to port it to a 12F675

    Malc

Similar Threads

  1. LCD Showes Some Wrong Letters
    By sbobowski in forum General
    Replies: 2
    Last Post: - 23rd September 2008, 19:15
  2. Anyone know whats wrong with this code
    By Bonxy in forum Serial
    Replies: 10
    Last Post: - 9th March 2007, 16:29
  3. ADCIN - AD settings are wrong
    By teverett in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th December 2006, 16:32
  4. What am I doing wrong?
    By mankan in forum General
    Replies: 1
    Last Post: - 23rd June 2006, 19:03
  5. HDD IDE ATA 2 interface problems. code wrong?
    By rastan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th March 2005, 16:01

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