PIC16f688 interupt on rising edge

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
gangusgreen
Posts: 26
Joined: Wed Mar 20, 2013 2:59 pm
Has thanked: 6 times

PIC16f688 interupt on rising edge

Post by gangusgreen »

OK I have the program written for a 60 hz signal that will come in on pin 4 and I want to trigger an interrupt here on the rising edge but only have the option of both edges. Is there a way to eliminate the falling edge? I am looking to trigger scr's on both swings of the sign wave at 180 deg firing of each other. But I am perplexed on how to go about just the rising edge of the signal. Thanks in advance ,everyone here is so helpful an I absolutely love this software. :D

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: PIC16f688 interupt on rising edge

Post by medelec35 »

Hi Bill,
If you select INT interrupt (Pin RA2) then you will have the choice to select either rising edge or falling edge,
If you select port interrupt (Pins RA0 to RA5), then interrupt macro will be triggered on both rising and falling edges (Depends on what target device your using) as you have correctly stated.
So what you will do is within the interrupt macro read the pin that has triggered interrupt. If high, then take action since port has gone from low to high.
If low then do nothing and allow macro to exit straight away

If you're still stuck then can you post your flowchart please.


Martin
Martin

gangusgreen
Posts: 26
Joined: Wed Mar 20, 2013 2:59 pm
Has thanked: 6 times

Re: PIC16f688 interupt on rising edge

Post by gangusgreen »

OK , I see what you mean but how do I tell it what pin to look for this on?

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: PIC16f688 interupt on rising edge

Post by medelec35 »

gangusgreen wrote:OK , I see what you mean but how do I tell it what pin to look for this on?
I was editing that post with the information at the same time you was replying.
Addition information is within the brackets of above post.

You can also look at the datasheet page 2:
http://ww1.microchip.com/downloads/en/D ... 41203E.pdf
Pin Functions.png
(81.12 KiB) Downloaded 7597 times
Martin

gangusgreen
Posts: 26
Joined: Wed Mar 20, 2013 2:59 pm
Has thanked: 6 times

Re: PIC16f688 interupt on rising edge

Post by gangusgreen »

The pin that the board has the signal coming into is pin #4 which is the RA3/MCLR/VPP .If you have a better idea than using an interrupt on this pin to trigger the macro I am willing to try another way.
Attachments
Bills_leel.fcf
(17.5 KiB) Downloaded 495 times

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: PIC16f688 interupt on rising edge

Post by medelec35 »

What about this?

Martin
Attachments
Bills_leel V1.1.fcf
(20.79 KiB) Downloaded 426 times
Martin

gangusgreen
Posts: 26
Joined: Wed Mar 20, 2013 2:59 pm
Has thanked: 6 times

Re: PIC16f688 interupt on rising edge

Post by gangusgreen »

medelec35 wrote:What about this?

Martin
I can give this on a try as well. What I am trying to achieve is a scr firing at a low swing range that would amount to a .2 amp charge at the low end of a battery type rectifier to a full wave that would allow a 20 amp charge . The controller that this board attaches to looks for a .2 amp or better charge to start controlling the current. When it has achieved this requirement it starts to send out a signal that is 0v - 5v to force the scr's to firer minimally or full range . So that is why it is important to hit the leading edge so that I can control more of the sign wave in the cycle. I am using the variable resistor to simulate the controllers signal and the red and blue LED's to signal the scr's . I slowed it down to visually see if the program works but I need to burn the device and try it in the lab to see if it truly works for the current board that we have . I can then put a scope on it and see it vs the AC. I hope this explanation helps a little bit more with what I am doing.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: PIC16f688 interupt on rising edge

Post by medelec35 »

One thing I should mention.
If you are using any other inputs (RA0 to RA5) then there needs to be a further check to determine if RA3 has actually changed state as well is high in value.

Edit: Posted this while you was typing a reply, so this post is not a reply from your latest post.
Martin

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: PIC16f688 interupt on rising edge

Post by medelec35 »

Hi Bill,
I have modified flowchart to allow for other switches to be used and not falsely access phase macro.

With the previous flowchart, if a3 goes high, so phase macro was accessed then while A3 is still high if any switch connected from A0 to A2 or A4 to A5 was triggered then phase macro will again be accessed when it should not be.

One issue you have is you have got:

Code: Select all

timing = timing * input_read
This means the timing variable will keep getting larger on every single pass.
E.g If pot is reading (input_read) say 100 bytes .
1st time with timing is 33
timing = timing * input_read
timing = 33 * 100 = 3300
next pass since now timing variable is retained:
timing = 3300 * 100 = 330000
Now there is a new issue which is very important!
You MUST NOT allow a signed integer to exceed 32767 otherwise it will rollover and will be either a negative number or unexpected positive number.
If you would like to state the delay values when pot is a 0% and 100%, I can help you with the calculations then that will be V1.3

In my opinion, when creating a flowchart Its best to take a step at a time, until you get use to them.
Then your wonder how you managed in the past without Flowcode :P
Attachments
Bills_leel V1.2.fcf
(21.06 KiB) Downloaded 641 times
Martin

gangusgreen
Posts: 26
Joined: Wed Mar 20, 2013 2:59 pm
Has thanked: 6 times

Re: PIC16f688 interupt on rising edge

Post by gangusgreen »

"In my opinion, when creating a flowchart Its best to take a step at a time, until you get use to them.
Then your wonder how you managed in the past without Flowcode :P"

I could not agree with you more. But unfortunatly in this case I need to have it almost finished to check it out because of the availiblity of the lab. :cry:

on the timing issue it will be a small change in math. Every 1/2 cycle of power in the us (60 Hz) is 8.3 milli seconds long and if you take 8200 micro second and subtract the incoming 0-5 v signal it will move the pulse from the back end of the wave to the front end there by giving you more of the sign wave to rectify with. Then to complete the other half of the wave to make it a full wave rectifier you add a 8200 micro second delay and it will fire on the negivitve side of the cycle at the same timing spot as the positive end. :D

I love this flow code way better than "C" I am so glad someone had the thought to creat it.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: PIC16f688 interupt on rising edge

Post by medelec35 »

Hi gangusgreen,
Pot value will either be 0 to 255 (0 to 5V) if read as Byte
Or
0 to 1023 if read as Int

These will be used to generate required delay.

so what do you want delay to be is ADC is reading 0V?
What delay to be is ADC is reading 5V?

If you can state both delays then a formula can be derived to create a delay within correct range.
So if pot is reading 2.5V for example the delay will be 1/2 way between the two extremes.
Martin

gangusgreen
Posts: 26
Joined: Wed Mar 20, 2013 2:59 pm
Has thanked: 6 times

Re: PIC16f688 interupt on rising edge

Post by gangusgreen »

medelec35 wrote:Hi gangusgreen,
Pot value will either be 0 to 255 (0 to 5V) if read as Byte
Or
0 to 1023 if read as Int

These will be used to generate required delay.

so what do you want delay to be is ADC is reading 0V?
What delay to be is ADC is reading 5V?

If you can state both delays then a formula can be derived to create a delay within correct range.
So if pot is reading 2.5V for example the delay will be 1/2 way between the two extremes.
That is true , that is why I broke the increment into 32 micro second intervals .The math should be 8200 micro seconds - (32ms * ADC) that that would be when the 1st SCR should fire on the positive swing of teh signal and then delay 8200 micro seconds to fir the 2nd one at the same spot on the negative side of the swing. :mrgreen:

gangusgreen
Posts: 26
Joined: Wed Mar 20, 2013 2:59 pm
Has thanked: 6 times

Re: PIC16f688 interupt on rising edge

Post by gangusgreen »

LOL, I was looking over my original version and I forgot to declare that delay=8200 :?
Now I see how I am confusing everyone. My bad, LOL.

Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times

Re: PIC16f688 interupt on rising edge

Post by Steve001 »

Martin,

Could you please modify

http://www.matrixmultimedia.com/mmforum ... p?id=11425

so I can open it in V4 ? and look to see what's happening and how and why :)

Steve

The chip doesn't matter just wanted an example
Success always occurs in private and failure in full view.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: PIC16f688 interupt on rising edge

Post by medelec35 »

Hi Steve,
To demonstrate port IOC, I have modified flowchart so it sould only flash LED's at the start for 3 loops, then LED's should only flash once when RB4 goes from low to high (Leading edge)
If RB4 is already high, and different i/p triggers IOC e.g RB5
then LEDs should not flash.

Martin
Attachments
IOC test FC4.fcf
(9.5 KiB) Downloaded 382 times
Martin

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: PIC16f688 interupt on rising edge

Post by medelec35 »

gangusgreen wrote:8200 micro seconds - (32ms * ADC)
So delay is range is from 40us to 8200us?
Martin

gangusgreen
Posts: 26
Joined: Wed Mar 20, 2013 2:59 pm
Has thanked: 6 times

Re: PIC16f688 interupt on rising edge

Post by gangusgreen »

medelec35 wrote:
gangusgreen wrote:8200 micro seconds - (32ms * ADC)
So delay is range is from 40us to 8200us?
No the full range would be 8300 us but you have to allow for the start in our rectifier .In our circumstance we need at least a .2 amp draw to the SCRs so the controller will start the recipe of the charging. I am generating a 40us pulse to the gates of the SCRs to trigger them and then we move threw the range at about 33us per step of the ADC input which is a 0-5v dc signal.

Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times

Re: PIC16f688 interupt on rising edge

Post by Steve001 »

thanks martin will try and have a look at this at the weekend :)

steve
Success always occurs in private and failure in full view.

gangusgreen
Posts: 26
Joined: Wed Mar 20, 2013 2:59 pm
Has thanked: 6 times

Re: PIC16f688 interupt on rising edge

Post by gangusgreen »

Well I got to run my version last night and after banging my head for a while finally got the control word right and it started as expected . Once threw start up it went into phase but it would not trigger at the right spot. other than that it did what it needed to do with the 2 40us SCR triggers. Now the next time I get a chance I will try V1.2 and see how that works. I really wish that the interrupt icon in flowcode allowed you to set leading edge on the graphical representation of the chip .It is there in color code but I have not been able to figure out how to use it. I did change the math a little and went with an integer as my read in which changed the steps for the phasing at 7 us per digit of read on ADC. FWIW it was fun playing with the real world after doing it in flowcode. :) Bill

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: PIC16f688 interupt on rising edge

Post by medelec35 »

gangusgreen wrote: I really wish that the interrupt icon in flowcode allowed you to set leading edge on the graphical representation of the chip .It is there in color code but I have not been able to figure out how to use it.
That's because that function is not available on the chip your currently using.
A chip I know has that function is 16F1827.
IOC on those can be set to rising or falling edge, by clicking on the pins (interrupt properties, select pins)
You could have a play with that target device within Flowcode.

Have you thought of controlling current with a FET instead of SCR?

Martin
Martin

gangusgreen
Posts: 26
Joined: Wed Mar 20, 2013 2:59 pm
Has thanked: 6 times

Re: PIC16f688 interupt on rising edge

Post by gangusgreen »

medelec35 wrote:
gangusgreen wrote: I really wish that the interrupt icon in flowcode allowed you to set leading edge on the graphical representation of the chip .It is there in color code but I have not been able to figure out how to use it.
That's because that function is not available on the chip your currently using.
A chip I know has that function is 16F1827.
IOC on those can be set to rising or falling edge, by clicking on the pins (interrupt properties, select pins)
You could have a play with that target device within Flowcode.

Have you thought of controlling current with a FET instead of SCR?

Martin
It is an existing design that we have for charging raw batteries. What this board that was designed to do is puts out 2 small latching signals to fire the SCRs. The old board was an analog design and sent out a firing signal threw out the whole range of the swing of AC and a 2nd signal to put that latch on to the SCRs . It was very inefficient and drew more current than was necessary. So a former co-worker came up with this design to solve the problem and save some power consumption (about that with the analog board of a 75 watt lamp x about 12000 rectifiers), but he has since passed away and took the "c" program with him. I am trying to recreate it to learn Flowcode (it is better to have a goal to learn :wink: ) and if it works the way I want to do it will allow more control of the wave form. The current software we only use about 75% of the wave I would like to push it out to 95% for some better control of the rectifier ,ie. make my repair time less (we have about 26k rectifiers of different types and all of them are OLD (I've got some that I work on that has a computer controller (8085) from the early '80s and the rectifier is from the mid 70's , to more "modern" rectifiers from the mid 90's. Nothing like keeping up with the times, LOL . There are some newer models out there that use IGBT controls that are nice but they are more suited for the plating industries that battery manufactures. We do have some bigger rectifiers in the plate forming areas in some of the plants they are usually 250 amp to 1500 amp varieties. So basically I am doing this for my own knowledge and ease of my work load. I have a home project that I want to build that will work in my greenhouse but it seems better to learn on something specific before tackling something new. It will be a Ph/conductivity controller for my hydroponic greenhouse that still is not up and running. :roll: maybe I need to get a life- LOL
Bill

Post Reply