Interrupt and PWM PIC12F615

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

Moderators: Benj, Mods

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

Interrupt and PWM PIC12F615

Post by oookey »

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/ ... ah02x3.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 491 times
12F615_PWM.fcf
(9 KiB) Downloaded 573 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: Interrupt and PWM PIC12F615

Post by medelec35 »

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 553 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: Interrupt and PWM PIC12F615

Post by medelec35 »

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 521 times
Martin

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

Re: Interrupt and PWM PIC12F615

Post by oookey »

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/ ... ah02x3.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/ ... /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

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: Interrupt and PWM PIC12F615

Post by medelec35 »

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
(109.22 KiB) Downloaded 7068 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
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: Interrupt and PWM PIC12F615

Post by medelec35 »

I have got a fix for 12F615 IOC.
The fix will enable you to select individual IOC pins:
12F615_IOC Fixed.png
(144.09 KiB) Downloaded 7060 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.61 KiB) Downloaded 524 times
12F615_IOC.fcf
(13.5 KiB) Downloaded 494 times
Martin

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

Re: Interrupt and PWM PIC12F615

Post by jamesf10 »

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

Post Reply