Loading ...
Sorry, an error occurred while loading the content.
 

JAL Program Design Help

Expand Messages
  • Andrew
    Hi there I am looking for someone who knows a bit about JAL and can help me figure the interrupts for this program. Basically what it is, the PIC begins in
    Message 1 of 10 , Jan 1, 2012
      Hi there

      I am looking for someone who knows a bit about JAL and can help me
      figure the interrupts for this program. Basically what it is, the PIC
      begins in sleep, when the either reed switch closes the input GP0 goes
      low causes a interrupt to wake the PIC and counts for 10 seconds after
      which
      begins the alarm procedure, unless the reed switch opens again, which
      would
      return the PIC to sleep. I am having a difficult time understanding how
      to
      use interrupts and cannot find any resources that I can use to help me
      understand. Any help would appreciated on any part of the code.

      Project Files
      <http://www.mediafire.com/?pn6q53d15nom9ac,h9hjcyx6fw1z16c>



      [Non-text portions of this message have been removed]
    • Matthew Schinkel
      Hello, Have a look at this sample & lib: http://jallib.googlecode.com/svn/trunk/sample/18f4620_interrupt_on_change.jal
      Message 2 of 10 , Jan 1, 2012
        Hello, Have a look at this sample & lib:

        http://jallib.googlecode.com/svn/trunk/sample/18f4620_interrupt_on_change.jal

        http://jallib.googlecode.com/svn/trunk/include/peripheral/interrupt_on_change/interrupt_on_change.jal

        Matt.

        --- In jallist@yahoogroups.com, "Andrew" <soundguy_025@...> wrote:
        >
        > Hi there
        >
        > I am looking for someone who knows a bit about JAL and can help me
        > figure the interrupts for this program. Basically what it is, the PIC
        > begins in sleep, when the either reed switch closes the input GP0 goes
        > low causes a interrupt to wake the PIC and counts for 10 seconds after
        > which
        > begins the alarm procedure, unless the reed switch opens again, which
        > would
        > return the PIC to sleep. I am having a difficult time understanding how
        > to
        > use interrupts and cannot find any resources that I can use to help me
        > understand. Any help would appreciated on any part of the code.
        >
        > Project Files
        > <http://www.mediafire.com/?pn6q53d15nom9ac,h9hjcyx6fw1z16c>
        >
        >
        >
        > [Non-text portions of this message have been removed]
        >
      • Andrew Howard
        Hey Matt Thank you for your reply. Would you just be able to tell me what I need for my project and then I can decipher that and then once I understand that I
        Message 3 of 10 , Jan 1, 2012
          Hey Matt

          Thank you for your reply. Would you just be able to tell me what I need for
          my project and then I can decipher that and then once I understand that I can move up to understand more complicated interrupts. 
          I understand what a interrupt is, just don't understand what all the
          other text means in the examples and how to apply it to my project.


          Andrew

          [Non-text portions of this message have been removed]
        • Matthew Schinkel
          Just use the 18f4620 file and put switches on pins b4 and b5 to switch each pin from high to low levels and LEDs on pins a0 and a1. You don t really need to
          Message 4 of 10 , Jan 2, 2012
            Just use the 18f4620 file and put switches on pins b4 and b5 to switch each pin from high to low levels and LEDs on pins a0 and a1. You don't really need to know anything in the lib.

            All required files are in the jallib-bee package at:
            http://code.google.com/p/jallib/downloads/list

            18f4620_interrupt_on_change.jal is in the sample dir.

            This sample should be what you need for your project. The datasheets explain interrupts more.

            I'm not sure how much JAL you have done so far, there are some tutorials on justanotherlanguage.org.

            Maybe start with writing a small program and when you run into trouble post it and we'll help :)

            Matt.

            --- In jallist@yahoogroups.com, Andrew Howard <soundguy_025@...> wrote:
            >
            > Hey Matt
            >
            > Thank you for your reply. Would you just be able to tell me what I need for
            > my project and then I can decipher that and then once I understand that I can move up to understand more complicated interrupts.�
            > I understand what a interrupt is, just don't understand what all the
            > other text means in the examples and how to apply it to my project.
            >
            >
            > Andrew
            >
            > [Non-text portions of this message have been removed]
            >
          • Eur van Andel
            ... A PIC getting an interrupt needs an interrupt service routine, which tells the PIC what to do when it receives said interrupt. grep for ... Reading the
            Message 5 of 10 , Jan 2, 2012
              On 1 Jan 2012, at 13:23 , Andrew wrote:

              > Hi there
              >
              > I am looking for someone who knows a bit about JAL and can help me
              > figure the interrupts for this program. Basically what it is, the PIC
              > begins in sleep, when the either reed switch closes the input GP0 goes
              > low causes a interrupt to wake the PIC and counts for 10 seconds after
              > which
              > begins the alarm procedure, unless the reed switch opens again, which
              > would
              > return the PIC to sleep. I am having a difficult time understanding
              > how
              > to
              > use interrupts and cannot find any resources that I can use to help me
              > understand. Any help would appreciated on any part of the code.

              A PIC getting an interrupt needs an interrupt service routine, which
              tells the PIC what to do when it receives said interrupt. grep for
              interrupt and see how it is done:

              > G5-fiwihex:~/jalv2/jallib eur$ cd sample/
              > G5-fiwihex:~/jalv2/jallib/sample eur$ grep interrupt *.jal

              Reading the datasheet helps too. Either clear GPIF or read/write from/
              to a GPIO pin.


              > Project Files
              > <http://www.mediafire.com/?pn6q53d15nom9ac,h9hjcyx6fw1z16c>

              This mediafire site opens up a lot of nasty windows with lots of
              advertising.

              If you can't state your problem in a single page email, try again.

              I assume the program works without an interrupt? You want to use the
              interrupt to save battery power?
              A fridge has 230V/110V AC inside, so a small transformer could power
              your PIC forever. This might be a lot less work than writing a decent
              ISR.


              ---
              ir EE van Andel eur@... http://www.fiwihex.nl
              Fiwihex B.V. Wierdensestraat 74, NL7604BK Almelo, Netherlands
              tel+31-546-491106 fax+31-546-491107




              [Non-text portions of this message have been removed]
            • bert
              Hi Andrew, ... Thanks for buying my book, and for your kind comments. ... If all you want to do is sound an alarm you do not need interrupts at all. In fact
              Message 6 of 10 , Jan 3, 2012
                Hi Andrew,

                > Love your book PIC Microcontrollers 50 Projects For Beginners
                > & Experts, I find it structured very well, so that I makes it
                > much easier to grasp JAL and PIC programming.

                Thanks for buying my book, and for your kind comments.

                > I am stuck on the interrupts as you may have seen.

                If all you want to do is sound an alarm you do not need interrupts at all. In fact project 4.1 should do nicely. Start with that project and modify it to your own needs. Compile and download your program regularly so you can see if it still does want you want it to do.

                If you do insist on using interrupts start with project 12.2 and modify that to your own needs. Note the way the interrupt procedure is setup, and the way it is called. So you will need the datasheet of the 12f675 to set the correct registers (look for "interrupt on change" for the setting, and do remember to switch the interrupts on (in INTCON probably). This is not going to be easy for a beginner, so perhaps you may want to try 4.1 first :-)

                Have fun,
                Bert

                www.vandam.tk
              • Andrew Howard
                Hi Bert ... all. In fact project 4.1 should do nicely. Start with that project and modify it to your own needs. Compile and download your program regularly so
                Message 7 of 10 , Jan 3, 2012
                  Hi Bert

                  >If all you want to do is sound an alarm you do not need interrupts at
                  all. In fact project 4.1 should do nicely. Start with that project and
                  modify it to your own needs. Compile and download your program regularly so you can see if it still does want you want it to do.

                  Yeah, that is what I have been doing. I have been trying the code on the PICKit2 Low Pin Count Demo Board, if I just input the alarm procedure on its own, it flashes the LED correctly but I can't seem to get it to respond to the on-board switch and call the procedure. I am thinking the problem may be when I put in the 12F675 to the board the switch is connected to pin 4, which is the GP3/MCLR/VPP pin. I have tried other pins and I get the same result though.


                  I only need a interrupt to wake the PIC from sleep, that's all. For power saving reasons. I don't want to put the board inside and run it off 240V, just because I would rather not open up our new fridge. I have been reading 12.2 in your book, do I need this part?....

                  -- the actual interrupt routine
                  procedure detect_a_pin is
                     pragma interrupt

                     if rbif then
                        if pin_b5 == 1 then
                           teller = teller + 1
                        end if
                        while pin_b5 loop
                        end loop
                        delay_1ms(1)

                        -- clear Rbif to re-enable port B interrupts
                        rbif = 0

                      end if
                  end procedure

                  Here is the code so far, sorry about the that download link guys :)
                  Thanks for the reply Bert...


                  -- JAL 2.0.4
                  include 12F675_bert

                  pin_a4_direction = output
                  pin_a3_direction = input

                  var bit buzzer is pin_a4
                  var bit switch is pin_a3

                  --OPTION_REG = 0b_0000_0000
                  --INTCON = 0b_1001_1000

                  if switch == 0 then
                        -- switch is closed
                        procedure alarm
                    else
                        buzzer = low
                        ---procedure sleep
                  end if



                  procedure alarm is
                    forever loop
                        buzzer = high
                        delay_100ms(5)
                        buzzer = low
                        delay_100ms(15)
                    end loop
                  end procedure

                  [Non-text portions of this message have been removed]
                • Bert van Dam
                  Hi Andrew, ... Check section 13.1 to find a free pin. Pin 4 is the MCLR pin so it is in use for other purposes. Why not use pin 3. ... Ok, check the datasheet:
                  Message 8 of 10 , Jan 3, 2012
                    Hi Andrew,

                    > I put in the 12F675 to the board the switch is connected to pin 4, which is the GP3/MCLR/VPP pin.

                    Check section 13.1 to find a free pin. Pin 4 is the MCLR pin so it is
                    in use for other purposes. Why not use pin 3.

                    > I only need a interrupt to wake the PIC from sleep, that's all. For power saving reasons.

                    Ok, check the datasheet: you need to set IOC.

                    >I have been reading 12.2 in your book, do I need this part?....
                    > -- the actual interrupt routine

                    Well, it says it's the actual interrupt routine, so yes, you need it!

                    Start over, seriously!, and use the program from 12.2 as template.
                    Read the text, it explains why the program is set up the way it is,
                    and why it works. Also read 12.1 for it explains how to set up
                    interrupt routines in general. Do not move procedures to other places,
                    and do not call the interrupt routine manually (not allowed, see 12.1,
                    so lose this part "if switch == 0 then". It's not in 12.2 so you don't
                    need it). Check the datasheet to see what registers you need to set or
                    the 12f675, and what you need to set the to. Also: your program only
                    runs once, 12.2 doesn't, you need to fix that as well.

                    It's unfortunate that you don't own a Wisp programmer. Otherwise you
                    could first port 12.2 to the 12f675, and once you've got that working
                    change it to your functionality. Now you're doing two things at the
                    same time. Anyway, it's not an easy task for a beginner, but if you
                    stick to the template of 12.2 and carefully read 12.1, 12,2 and the
                    datasheet I'm sure you can do this!

                    Have fun,
                    Bert

                    www.vandam.tk
                  • Andrew
                    How does this look? -- JAL 2.0.4 include 12f675_bert var bit switch is pin_a2 var bit buzzer is pin_a0 -- define pins pin_a2_direction = input pin_a0_direction
                    Message 9 of 10 , Jan 7, 2012
                      How does this look?

                      -- JAL 2.0.4
                      include 12f675_bert

                      var bit switch is pin_a2
                      var bit buzzer is pin_a0

                      -- define pins
                      pin_a2_direction = input
                      pin_a0_direction = output


                      option_reg = 0b_0000_0000 --enable falling edge int
                      intcon = 0b_1000_1000 --enable global and INTE int
                      wpu= 0b_00110010 -- enable weakpullups on GP1, GP4 & GP5

                      buzzer = off

                      procedure sleep

                      procedure alarm is
                      pragma interrupt

                      delay_1s(10)
                      forever loop
                      buzzer = high
                      delay_100ms(8)
                      buzzer = low
                      delay_100ms(15)
                      end loop

                      intf = 0

                      end procedure

                      Sorry for the noob questions :/
                      --- In jallist@yahoogroups.com, Bert van Dam <bymco.bv@...> wrote:
                      >
                      > Hi Andrew,
                      >
                      > > I put in the 12F675 to the board the switch is connected to pin 4, which is the GP3/MCLR/VPP pin.
                      >
                      > Check section 13.1 to find a free pin. Pin 4 is the MCLR pin so it is
                      > in use for other purposes. Why not use pin 3.
                      >
                      > > I only need a interrupt to wake the PIC from sleep, that's all. For power saving reasons.
                      >
                      > Ok, check the datasheet: you need to set IOC.
                      >
                      > >I have been reading 12.2 in your book, do I need this part?....
                      > > -- the actual interrupt routine
                      >
                      > Well, it says it's the actual interrupt routine, so yes, you need it!
                      >
                      > Start over, seriously!, and use the program from 12.2 as template.
                      > Read the text, it explains why the program is set up the way it is,
                      > and why it works. Also read 12.1 for it explains how to set up
                      > interrupt routines in general. Do not move procedures to other places,
                      > and do not call the interrupt routine manually (not allowed, see 12.1,
                      > so lose this part "if switch == 0 then". It's not in 12.2 so you don't
                      > need it). Check the datasheet to see what registers you need to set or
                      > the 12f675, and what you need to set the to. Also: your program only
                      > runs once, 12.2 doesn't, you need to fix that as well.
                      >
                      > It's unfortunate that you don't own a Wisp programmer. Otherwise you
                      > could first port 12.2 to the 12f675, and once you've got that working
                      > change it to your functionality. Now you're doing two things at the
                      > same time. Anyway, it's not an easy task for a beginner, but if you
                      > stick to the template of 12.2 and carefully read 12.1, 12,2 and the
                      > datasheet I'm sure you can do this!
                      >
                      > Have fun,
                      > Bert
                      >
                      > www.vandam.tk
                      >
                    • Bert van Dam
                      Hi Andrew, ... Much, much better. I can see you ve come a long way, but it doesn t work just yet. 1. The program will only run once because there is no main
                      Message 10 of 10 , Jan 8, 2012
                        Hi Andrew,

                        > How does this look?

                        Much, much better. I can see you've come a long way, but it doesn't
                        work just yet.

                        1. The program will only run once because there is no main forever
                        loop, and because of 5
                        2. You need to set IOC
                        3. You can put the PIC to sleep with the command "asm sleep"
                        4. The interrupt reset flag is gpif
                        5. The program will never exit the interrupt procedure because you
                        have a forever loop in there

                        Here's how I would solve it (with a LED):

                        include 12F675_bert
                        var bit switch is pin_a4
                        var bit led is pin_a2

                        -- define pins
                        pin_a4_direction = input
                        pin_a2_direction = output

                        -- variable
                        var bit flag

                        -- interrupt routine
                        procedure wakemeup is
                        pragma interrupt

                        if GPIF then
                        flag = 1
                        GPIF=0
                        end if
                        end procedure

                        IOC = 0b_0001_0000
                        INTCON = 0b_1000_1000

                        forever loop
                        if flag then
                        led=high
                        delay_1s(5)
                        led=low
                        flag=0
                        else
                        asm sleep
                        end if
                        end loop

                        Note that the main program loop simply waits for the flag to be set.
                        The only way this flag can be set is by the interrupt routine. Once
                        this flag is set the pin is made high for 5 seconds. I've done it this
                        way to keep the interrupt routine itself short, which is considered
                        good programming practice. If the flag is not set the PIC put's itself
                        to sleep. Also note that procedures must be placed before the main
                        program and not at the end.

                        With a 10k resistor over the switch and a 33k resistor on pin 4 the
                        power consumption while awake is about 1 mA, and asleep it is about
                        0,3 mA (obviously with the LED off).

                        Have fun,
                        Bert


                        www.vandam.tk
                      Your message has been successfully submitted and would be delivered to recipients shortly.