Replicating C code
Posted: Wed Jun 01, 2011 11:21 am
Please can you help with:
1) On the 16F690 datasheet it says RA2 is the interrupt pin, but when I use your Interrupt flowchart icon it lists RB0/INT as if RB0 is the interrupt one. My mistake or yours?
2) I am trying to develop a light dimmer using Microchip Application Note http://ww1.microchip.com/downloads/en/A ... 40171a.pdf with some changes like changing their 12C508 to a 16F690 and not using their large ButtonPress Macro.
They provide a crude flowchart and the C and ASM code. So using these I am trying to replicate it into Flowcode. As their version of C is a bit different to yours I can't just copy large blocks of their C into Flowcode and would not be able to easily modify that C to what I want as I don’t understand C well enough.
Basically they are converting the mains into a 0-5V 50Hz square wave and reading this into LineInput on Pin GP4, although I will use a different pin on the 690 and am not sure if I need an interrupt pin or not. When this changes from 0-1 or 1-0 it they know the zero crossing points of the mains.
They also seem (I am not completely clear on this) to be fine tuning the timing and start point of the TMR0 clock so it synchs itself with the external mains. They then fire the Triac relative to the TMR0 derived time rather than straight from the mains time/phase maybe because, due to electrical interference, the external zero crossing points could occasionally be missmeasured, but the internal clock will still be reasonably in synch. They fire the Triac at the right phase point controlled by the delay period (phase angle) value PercentOn. Dimming is altered by changing PercentOn.
My initial problem is their C lines that say:
for(Count = 0; Count < 60; Count++) //Allow power supply to stabilize
{
while(LineInput == 1);
while(LineInput == 0);
CLRWDT;
}
WREG = 0x85;
#asm ( OPTION); //1:64 tmr0 prescaler, pullups enabled
WREG = 0x1D;
while(LineInput == 1) //Synch to line phase
CLRWDT;
TMR0 = PercentOn; //Get Delay time
while(TMR0 >= 3 && LineInput == 0) //Delay to enter main at proper point
CLRWDT;
while(1) //Stay in this loop
I can’t see in Flowcode how to:
a) Preload TMR0 Module Register with the integer value PercentOn in their line TMR0 = PercentOn or whatever this line is doing. (TMR0 frequency is set at 61Hz by the 1:64 prescaler and 4MHz clock – which I need to alter to 50Hz for UK mains.)
b) Replicate the CLRWDT line and I am not clear what they are doing with this CLRWDT line.
The alternative is to give up on their code and do it myself from scratch using their general ideas. Am I being too ambitious to try to replicate their code into Flowcode?
1) On the 16F690 datasheet it says RA2 is the interrupt pin, but when I use your Interrupt flowchart icon it lists RB0/INT as if RB0 is the interrupt one. My mistake or yours?
2) I am trying to develop a light dimmer using Microchip Application Note http://ww1.microchip.com/downloads/en/A ... 40171a.pdf with some changes like changing their 12C508 to a 16F690 and not using their large ButtonPress Macro.
They provide a crude flowchart and the C and ASM code. So using these I am trying to replicate it into Flowcode. As their version of C is a bit different to yours I can't just copy large blocks of their C into Flowcode and would not be able to easily modify that C to what I want as I don’t understand C well enough.
Basically they are converting the mains into a 0-5V 50Hz square wave and reading this into LineInput on Pin GP4, although I will use a different pin on the 690 and am not sure if I need an interrupt pin or not. When this changes from 0-1 or 1-0 it they know the zero crossing points of the mains.
They also seem (I am not completely clear on this) to be fine tuning the timing and start point of the TMR0 clock so it synchs itself with the external mains. They then fire the Triac relative to the TMR0 derived time rather than straight from the mains time/phase maybe because, due to electrical interference, the external zero crossing points could occasionally be missmeasured, but the internal clock will still be reasonably in synch. They fire the Triac at the right phase point controlled by the delay period (phase angle) value PercentOn. Dimming is altered by changing PercentOn.
My initial problem is their C lines that say:
for(Count = 0; Count < 60; Count++) //Allow power supply to stabilize
{
while(LineInput == 1);
while(LineInput == 0);
CLRWDT;
}
WREG = 0x85;
#asm ( OPTION); //1:64 tmr0 prescaler, pullups enabled
WREG = 0x1D;
while(LineInput == 1) //Synch to line phase
CLRWDT;
TMR0 = PercentOn; //Get Delay time
while(TMR0 >= 3 && LineInput == 0) //Delay to enter main at proper point
CLRWDT;
while(1) //Stay in this loop
I can’t see in Flowcode how to:
a) Preload TMR0 Module Register with the integer value PercentOn in their line TMR0 = PercentOn or whatever this line is doing. (TMR0 frequency is set at 61Hz by the 1:64 prescaler and 4MHz clock – which I need to alter to 50Hz for UK mains.)
b) Replicate the CLRWDT line and I am not clear what they are doing with this CLRWDT line.
The alternative is to give up on their code and do it myself from scratch using their general ideas. Am I being too ambitious to try to replicate their code into Flowcode?