PIC10F202 Variable trouble


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Sure, all it does is dims a light down after 20 minutes of being on.

    @ device pic10F202, mclr_off, protect_off, wdt_off

    TRISIO = %1100

    triac VAR GPIO.2
    trigger VAR GPIO.3

    dim VAR WORD
    Time VAR WORD
    Time2 VAR BYTE
    b0 VAR BYTE

    Clear
    GPIO = 0
    dim = 100


    Start:

    time = time + 1 'increment timer in 1/50 seconds

    IF time > 30000 Then 'make a 10 min increment
    time = 0
    time2 = time2 + 1
    EndIF

    b0 = b0 + 1 'increment for every 4 phase cycles
    IF b0 >= 3 Then b0 = 0

    IF time2 >= 2 AND b0 = 2 Then dim = dim + 1 'if over 20 min then start dimming dim period 4 cycles = 10 mins

    IF dim > 7500 Then dim = 7500 'down to dim level - 9000 = off, 7500 approx 15%

    if time2 > 72 then 'turn off after 12 hours
    dim = 9000
    time2 = 73 'prevent from cycling
    endif

    LowSide: 'look for trigger points and trigger triac

    IF trigger = 1 Then lowside 'wait for phase to go low
    GPIO.5 = 0 'weight input to sense zero crossing
    PauseUs dim 'wait for dim period
    Output triac 'fire triac
    triac = 0
    PauseUs 400
    Input triac

    HighSide:

    IF trigger = 0 Then HighSide
    GPIO.5 = 1
    PauseUs dim
    Output triac
    triac = 0
    PauseUs 400
    Input triac

    GoTo start

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


    Did you find this post helpful? Yes | No

    Default

    It's the down side of those nifty 10Fs with most compiler. The use of assembler is handy in this case... but i'll have a look at this one to see what i can do...
    Last edited by mister_e; - 9th October 2006 at 03:58.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Not tested but assuming you're not using any Gosubs... it could work.

    Inspiration taken bellow
    http://www.picbasic.co.uk/forum/show...light=modifier

    Sure it could be dangerous.... compile O.K
    Code:
    @ device pic10F202, mclr_off, protect_off, wdt_off
    
    TRISIO = %1100
    
    asm
    dim=SOFT_STACK  		
    Time=SOFT_STACK + 2
    Time2=SOFT_STACK_PTR
    endasm
    dim   VAR WORD ext
    Time  VAR WORD ext   
    Time2 VAR BYTE ext
    b0    VAR BYTE 
    
    Clear
    GPIO = 0
    dim = 100
    
    
    Start:
        time = time + 1 'increment timer in 1/50 seconds
        
        IF time > 30000 Then 'make a 10 min increment
            time = 0
            time2 = time2 + 1
            EndIF
        
        b0 = b0 + 1 'increment for every 4 phase cycles
        IF b0 >= 3 Then b0 = 0
        
        IF (time2 >= 2) then 
           if b0 = 2 Then dim = dim + 1 'if over 20 min then start dimming dim period 4 cycles = 10 mins
           endif
    
        IF dim > 7500 Then dim = 7500 'down to dim level - 9000 = off, 7500 approx 15%
        
        if time2 > 72 then 'turn off after 12 hours
            dim = 9000
            time2 = 73 'prevent from cycling
            endif
    
    LowSide: 'look for GPIO.3 points and GPIO.3 GPIO.2
        IF GPIO.3 = 1 Then lowside 'wait for phase to go low
        GPIO.5 = 0 'weight input to sense zero crossing
        PauseUs dim 'wait for dim period
        TRISIO.2=0 'fire GPIO.2
        GPIO.2 = 0
        PauseUs 400
        TRISIO.2=1
    
    HighSide:
        IF GPIO.3 = 0 Then HighSide
        GPIO.5 = 1
        PauseUs dim
        TRISIO.2=0
        GPIO.2 = 0
        PauseUs 400
        TRISIO.2=1
        GoTo start
    Good luck!
    Steve

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

  4. #4
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Hey steve - that looks like some funky stuff yr doing there - tho it's still saying that it's unable to fit variable b0. Any easy way to solve it? Else I'm gonna move to a 12F - seems such a waste tho as I'm only using 2 I/Os. I'm trying to design it for a production run - so I did like the cost and form of the 10F.

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


    Did you find this post helpful? Yes | No

    Default

    be sure you copy past the whole thing above. It compile ok to me. I did few minors change to the one you posted before.

    I guess about a IF (condition a) AND (condition b) then... line... right?
    Steve

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

  6. #6
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Unhappy

    Hey - copied it all across and it compiled thanks - however - it won't program :s

    "ROM programming error at address 0x0000
    Good 0x0025
    Bad 0x0FE7"

    Any ideas on what that could mean?

    Thanks
    Brendon

  7. #7
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    One thing that strikes me as odd is that when you look at the hex file im my programmer it's in groups of 3 instead of groups of 4 - any clues why?

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 00:06
  2. problem with variable on PIC10f202
    By Samoele in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th October 2009, 17:29
  3. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  4. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  5. Trouble with Serin2 and variable size
    By Ryan7777 in forum Serial
    Replies: 6
    Last Post: - 5th October 2006, 16:40

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