What am I doing wrong ?


Closed Thread
Results 1 to 21 of 21
  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
    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.

  6. #6
    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 " !!!
    *****************************************

  7. #7
    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]"

  8. #8
    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

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


    Did you find this post helpful? Yes | No

    Talking the Tardis from Dr Who ???

    Hi, Malc

    That's a bit more complicated ... as Dr Who is completely unknown here !!!

    May be some more info about that light timing and appearance ( flash, slow rise and fall, Pulsing light ....) could help us to help you ...

    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 " !!!
    *****************************************

  10. #10
    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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer
    In your code, put a space between '@' and "DEVICE"


    --------------
    Yup, have done (I copied and pasted the line in your post) and still fails to compile.

    Malc

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics
    Hi, Malc

    May be some more info about that light timing and appearance ( flash, slow rise and fall, Pulsing light ....) could help us to help you ...

    Alain
    I was going to attach a short avi (DVIX codec) of the result I have with the 16F628a chip, which is exactly what my friend wants..., but even zipped its slightly more than the max 200K limit we're allowed to upload. If I can't get the 12F675 working I'll just mail him the '628 chip and save all the headache !

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


    Did you find this post helpful? Yes | No

    Default

    if you use MPASM, DEVICE is not the right command, the the FAQ thread about the config fuse.
    Code:
        @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
             ' Internal Oscillator
             ' Enable watch dog timer
             ' Enable power up timer
             ' Disable MCLR pin
             ' Enable brown out detect
    Or you may set them manually in your device programmer software.

    HTH
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Steve,

    Looks like I might have to set them manually or use the 16F628 as I still get an error when I copy and past the line of code from your mail.

    This time I get:

    Error 118: overwriting previous address contents 2007

    What the hell that means I have no idea ?

    I think I need to go back to basics and get a LED flashing on a PIN and then impliment my code for the PWM

    Thanks guys for your continuing help, its this support that makes PBP my preferred programming language

    Malc

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


    Did you find this post helpful? Yes | No

    Default

    so it seems you didn't read the FAQ
    pay attention to post #5 of the link bellow
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    Steve

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

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


    Did you find this post helpful? Yes | No

    Talking Datasheet !!!!

    Hi, Steve

    somewhat tired in the end of that week ...

    Alain
    Last edited by Acetronics2; - 9th June 2006 at 18:08.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default Mmiiippp Bad Answer Dude!!!

    Alain, try it and uncomment the default config fuses.. what do you get?

    Maudit francais

    Steve who laught a big time right now!
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    so it seems you didn't read the FAQ
    pay attention to post #5 of the link bellow
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    Thanks for the link, and whist I did look at the FAQ's.. I must admit that I didn't scroll down much further than the original post - Sorry !

    However the good news is that the LED is now pulsing away on GPIO 0

    However I really want to learn from this and I'm a tad confused (easy to do). Whats the difference between having the line in the program code and the INC file. ?

    I found that if I removed the line
    Code:
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
    from the programing code and left the INC file intact the program compiled but the LED did nothing. - Reming out the line in the INC file and adding it to the code file, resulted in the code compiling without errors and the LED is pulsing away fine !

    Should (or is that could) I use the INC file and have some statement in the programming code to call this file (something like include 12F675.inc)

    Also, will I have to modify every INC file for every PIC that I use so i don't get this problem again ?

    Cheers

    Malc

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


    Did you find this post helpful? Yes | No

    Red face oops!

    Although technically correct, after some sleep and a few cups of coffee I can see that my suggestions would not have helped you. (#5 in this thread)

    good luck,

    Paul

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


    Did you find this post helpful? Yes | No

    Default

    Yeah it's pain dude, you'll have to modify all .INC for all PIC you have in stock. The MPAM 'errorlevel -' stuff can't work on that... it would be just too much convenient.

    I already think of doing an automatic application to comment out every .inc file... maybe i'll do it one day... maybe

    But i think that even if you get this Error message, your config fuse will be set as per your code. It will just be an error message like the one for Page Boundary, or Find directive in column x, or... ,.. wich can be ignored. It's just unplesant to see it in your face
    Last edited by mister_e; - 9th June 2006 at 22:53.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    I guess its all part of the learning curve ! As I stick to just two or three PICs I can't really moan about having to rem out the config line... I had a look at the 16F628a inc file and that too was remed out.. just don't remember doing it (like a lot of things these days... must be getting old !)

    Thanks for all the pointers and help

    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