Thanks for your replies.
I will need to do some extensive reading on the first option as it might be more efficient but I tried option 2 (the long way) and it works.

Now I have something that is almost working and I am not sure if I have an issue with my code or the hardware.
Basically I am using a pot to control the speed of a small DC motor using PWM (since I don't have the motor/transistor yet I am using LED1)
and I have a set of 3 jumpers to control time on and time off.

In my example let's say I adjust the pot to have the LED at half its intensity and I have all jumpers off (0V) I should get 1 sec ON + 14 sec Off and this cycle should loop forever.
The results I am getting now is:
LED at half intensity for 1 sec
LED off for 14 sec
LED at half intensity for 1 sec
LED on (full intensity) 14 for sec

Somehow after a while the proper sequence starts happening which is why I think it might be hardware issue as it is unstable.

Here is my code and schematic:
Code:
@ __config _INTOSC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CPD_OFF & _CP_OFF
clear

TRISA = 255         'All pins are input.
TRISB = 0           'All pins are output.

'=====Timer2 settings - 8Bit ====================
T2CON = %00000000   ' Required for accurate timing for RPM.
INTCON.7 = 0        ' Disable interrupts.

'===================PWM Part===============
CMCON = 7           ' PortA = digital I/O
VRCON = 0           ' Disable A/D Voltage reference.
PR2 = 255           ' PWM frequency.
CCP1CON = %00001100 ' PWM Mode selected.
T2CON = 0           ' Timer2 OFF + 1:1 prescale
CCPR1L = 0          ' Set PWM Duty-Cycle

SW1 var PortA.2
SW2 var PortA.3
SW3 var PortA.4
SWconfig var byte
PotPin VAR PORTB.0
TimeOn var word
TimeOff var word

swconfig =  0
timeon = 0
timeoff = 0

Begin:

' get the switches value and assign to SWconfig
swconfig.2 = sw1
swconfig.1 = sw2
swconfig.0 = sw3

select case swconfig

case 0 
    timeon = 1000
    timeoff=14000
    
case 1 
    timeon = 2000
    timeoff=13000
    
case 2 
    timeon = 3000
    timeoff=12000
    
case 3 
    timeon = 4000
    timeoff=11000
    
case 4 
    timeon = 5000
    timeoff=10000
    
case 5 
    timeon = 6000
    timeoff= 9000

case 6 
    timeon = 7000
    timeoff= 8000

case 7 
    timeon = 8000
    timeoff= 7000

end select

    POT PotPin , 255, CCPR1L ' Get POT value
    T2CON.2 = 1'start PWM
    pause timeon
    T2CON.2 = 0'stop PWM
    pause timeoff


goto begin


END
Name:  pico.PNG
Views: 688
Size:  71.4 KB

Thanks for your help

Mike