Interrupt and PWM PIC12F615

Forum for problems or queries regarding other Flowcode Components. Eg LEDs, Switches, LCD, Gfx LCD etc

Moderators: Benj, Mods

oookey
Posts: 42
Joined: Thu Mar 08, 2012 3:00 pm
Has thanked: 17 times
Contact:

Interrupt and PWM PIC12F615

Postby oookey » Fri May 04, 2012 2:24 pm

Hi Ben,

I have got my Flowcode alive, thanks. <img class="exp_link_class" title="Generated by Expresso" alt="Generated by Expresso" style="float:none;pointer;height:19px;width:25px;" src="http://dpxv6nn9fphpz.cloudfront.net/v5/expresso/emoticons/yeah02x3.gif">

I try to program the 12F615, but I don’t see port A nor port B, instead GP0 thru GP5, so how do I make GP1 as an input interrupt to trigger PWM signal output at GP2? I’m using FC3.

Attached my FC and portion of datasheet.

Thanks for your time.

oookey
Attachments
Datasheet-12f615.pdf
(75.5 KiB) Downloaded 220 times
12F615_PWM.fcf
(9 KiB) Downloaded 274 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8236
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2359 times
Been thanked: 3347 times
Contact:

Re: Interrupt and PWM PIC12F615

Postby medelec35 » Fri May 04, 2012 10:28 pm

Hi oookey
I have modifed your flowchart and it works well without any alterations with FC5.
However is does not work with FC3 or FC4.

So there is probably a bug in FC3 & FC4 that has been fixed in Flowcode5.

If I get a chance I will see if I can look at why there is an issue with FC3, no promises though.

I have also move this to V3 section where it is more relevant.

Martin
Attachments
12F615_PWM1.fcf
(9.5 KiB) Downloaded 250 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8236
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2359 times
Been thanked: 3347 times
Contact:

Re: Interrupt and PWM PIC12F615

Postby medelec35 » Fri May 04, 2012 11:24 pm

I found the problem.
The IOC is not being set with a value of 2, so all IOC's are disabled.
Attached flowchart has been tested on a 12F615 and works as intended.

Martin
Attachments
12F615_PWM1.fcf
(13.5 KiB) Downloaded 252 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

oookey
Posts: 42
Joined: Thu Mar 08, 2012 3:00 pm
Has thanked: 17 times
Contact:

Re: Interrupt and PWM PIC12F615

Postby oookey » Sat May 05, 2012 5:48 am

Hi Martin,

Thanks a lot your time. <img class="exp_link_class" title="Generated by Expresso" alt="Generated by Expresso" style="float:none;pointer;height:19px;width:25px;" src="http://dpxv6nn9fphpz.cloudfront.net/v5/expresso/emoticons/yeah02x3.gif">

I tried running both of your attached, however it just looping itself inside the while loop, even toggle ON/OFF A1, the interrupt unable to call out the subroutine, may be I'm stretching too far for FC3 using this chip. <img class="exp_link_class" title="Generated by Expresso" alt="Generated by Expresso" style="float:none;pointer;height:19px;width:25px;" src="http://dpxv6nn9fphpz.cloudfront.net/v5/expresso/emoticons/sadx3.gif">
But why is the “interrupt – enable port change” out of the while loop instead the “decision of change” is within the loop? Wouldn’t the chip work faster if only the “interrupt-enable port change” is within the while-loop, remove the “decision of change” routine out?

Thanks

oooky

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8236
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2359 times
Been thanked: 3347 times
Contact:

Re: Interrupt and PWM PIC12F615

Postby medelec35 » Sat May 05, 2012 9:48 am

Hi oooky,

The 1st flowchart I posted is suppose to work but it does not because of a bug in Flowcode V3 as explained.

One important thing I should have mentioned:
With 12F series the IOC will only simulate with Flowcode V5.
Since FC3 support is stopping soon (start of June) FC5 is a definitely a well worth investment.

So with Flowcode V3 and V4 if you activate the switch, nothing will happen. That's only a simulation fault.

I can guarantee 100% it does work with a real 12F615, as I have got the hardware set up on my Matrix protostation.

So If yours is not working you will need to look at the programming and hardware setup.

It looks like you have posted some images, but they are not showing up.

Just click the 'Upload attachment' tab, Click 'Choose File' browse to the image, click 'Open' then click 'Add the file'

The second flowchart I posted overcomes the bug.
oookey wrote:But why is the “interrupt – enable port change” out of the while loop instead the “decision of change” is within the loop? Wouldn’t the chip work faster if only the “interrupt-enable port change” is within the while-loop, remove the “decision of change” routine out?

No, interrupts are not used that way.

The interrupt is enabled only once. (unless you disable interrupt, then you will have to re-enable it!)
So the interrupts are only enabled at the beginning of the flowchart before the main loop.

Each time A1 changes state (either low to high, or high to low) then the interrupt macro is accessed.
There is a decision branch within the interrupt to ignore if switch has gone from high to low, otherwise count will increment twice each time switch is pressed then released.

The reason the decision branch is within main loop is because you can't place a PWM macro component in the interrupt and also within any other macro, including Main.
If you are not going to add any more PWM components then you can change your flowchart to this:
12F615.png
12F615.png (109.22 KiB) Viewed 5456 times

It will still work on hardware.

oookey wrote:may be I'm stretching too far for FC3 using this chip.

No it's not stretching FC3 at all!
However If your creating any flowcharts that involve IOC then you must use a C block with ioc=x;
Where x is the value for required GP pin.
Or if you find it eaiser use binary.
So for GP2 use:

Code: Select all

ioc=0b10;


For GP5 and GP2 for example use:

Code: Select all

ioc=0b10010;


Martin
These users thanked the author medelec35 for the post:
oookey (Sat May 05, 2012 10:27 am)
Rating: 5.88%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8236
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2359 times
Been thanked: 3347 times
Contact:

Re: Interrupt and PWM PIC12F615

Postby medelec35 » Sat May 05, 2012 1:30 pm

I have got a fix for 12F615 IOC.
The fix will enable you to select individual IOC pins:
12F615_IOC Fixed.png
12F615_IOC Fixed.png (144.1 KiB) Viewed 5448 times

Also this fix will enable you to select timer1 interrupt when required.
The C code

Code: Select all

ioc=2;
can now be removed.
To apply fix just find 12F615.fcd in C:\Program Files\Matrix Multimedia\Flowcode V3\fcd
If 32 bit windows
or
C:\Program Files (x86)\Matrix Multimedia\Flowcode V3\fcd\
If 64 bit windows
and replace with attached file.

The attached flowchart is the final working version, using IOC selectable function.

Note: Fix does not fix simulation!

Martn
Attachments
12F615.fcd
(6.83 KiB) Downloaded 229 times
12F615_IOC.fcf
(13.5 KiB) Downloaded 222 times
These users thanked the author medelec35 for the post (total 2):
oookey (Sat May 05, 2012 4:52 pm) • gtc (Wed Sep 09, 2015 1:22 pm)
Rating: 11.76%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

jamesf10
Posts: 1
Joined: Wed May 16, 2012 9:41 am
Contact:

Re: Interrupt and PWM PIC12F615

Postby jamesf10 » Fri May 18, 2012 12:03 pm

hi, i was wondering could you send me a picture of the schematic required for this PWM code using the PIC12F615? It would be appreciated,
thanks,
jamesf10