Author Topic: PWM with oshonsoft pic basic  (Read 8992 times)

0 Members and 1 Guest are viewing this topic.

Offline oldandwiseTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
PWM with oshonsoft pic basic
« on: March 28, 2008, 02:57:41 AM »
I have been using Oshonsoft Basic and picsimulator suite, all of which I find generally very fast and useful, however I cant seem to get an answer from Oshonsoft as to why the basic will not accept the Pwmon x,x command. Basic reports that PWM is not available for this device (Pic16f684).
 I have tried setting up the PWM the longerway, following other peoples ideas in Assembler etc. But I cannot get the pWM out put to function.
Can anyone out there suggest a basic routine that will acieve PWM on the PIC16F684 PLEASE?

Thank you for your interest, Brian

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: PWM with oshonsoft pic basic
« Reply #1 on: March 28, 2008, 01:50:48 PM »
Just use the initialisation sequence in the datasheet to init the pwm level.
(Set up timer2, set up module for pwm operation, set up PR2, set duty cycle).

Oshonsoft basic is nice, but it's very limiting. Plus, it has absolutely no code optimisation. You should try out other compilers, too.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline oldandwiseTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: PWM with oshonsoft pic basic
« Reply #2 on: April 30, 2008, 09:14:21 AM »
Thanks Izua,

I guess I will have to do it that way, but that is a lot of typing when basic can set it up in one or two lines. I have managed to set up the PWM in assembler, but that was hard work. Im not lazy, but when one has to spend so much time proving a routine before one can get on with a project, it takes one away from the project ideas one may have.
Anyway thanks again , Brian

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: PWM with oshonsoft pic basic
« Reply #3 on: May 03, 2008, 02:08:24 PM »
10 lines aren't such a hardwork. You just have to follow the datasheet.
This is for both PWM channels for oshonsoft

Code: [Select]
PR2 = 62
TRISB.3 = 0
T2CON.TMR2ON = 1
CCP1CON.3 = 1
CCP1CON.2 = 1
TRISB.2 = 0
CCP2CON.3 = 1
CCP2CON.2 = 1
PWMduty 1, 0
PWMduty 2, 0
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline oldandwiseTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: PWM with oshonsoft pic basic
« Reply #4 on: May 04, 2008, 02:48:35 AM »
THanks for your suggestion IZuA,

But this is exactly the problem, too much experimenting with lines that do not work with Oschonsoft basic!

This is the setup recommended in the handbook for the PIC16f 684

11.3.7 SETUP FOR PWM OPERATION
(The following steps should be taken when configuring
the CCP module for PWM operation:
1. Disable the PWM pin (CCP1) output driver by
setting the associated TRIS bit.
2. Set the PWM period by loading the PR2 register.
3. Configure the CCP module for the PWM mode
by loading the CCP1CON register with the
appropriate values.
4. Set the PWM duty cycle by loading the CCPR1L
register and CCP1 bits of the CCP1CON register.
5. Configure and start Timer2:
• Clear the TMR2IF interrupt flag bit of the
PIR1 register.
• Set the Timer2 prescale value by loading the
T2CKPS bits of the T2CON register.
• Enable Timer2 by setting the TMR2ON bit of
the T2CON register.
6. Enable PWM output after a new PWM cycle has
started:
• Wait until Timer2 overflows (TMR2IF bit of
the PIR1 register is set).
• Enable the CCP1 pin output driver by clearing
the associated TRIS bit.

 So I used your scheme with alterations to  suit Pic16F684 which has registers A and C only.

Config PORTC = Output
PR2 = 62
TRISC.3 = 0
T2CON.TMR2ON = 1
CCP1CON.3 = 1
CCP1CON.2 = 1
TRISC.2 = 0
T2CON.3 = 1
T2CON.2 = 1
PWMduty 1, 0
PWMduty 2, 0

The result of trying to compile is always the same as follows:
(as the Oschion basic doesnt understand PWMon or PWMduty! at least for this chip!)


Error in line 11: PWM module(s) not available for the selected device.


So you see I,m a little tired of trying setups that do not work on this chip, as I said before, I have prorammed the chip in assembler and with GCow basic, and Mikrobasic, and proved that the chip has indeed PWM that the Oschionsoft says it has not!
 Incidentally I will buy the Mikro full version basic now after trying the free limited edition (limited to 1K assembly),as it seems to be comprehensive and very straightforward to use.l

Thanks again, its always a pleasure to discuss our problems, greetings Brian

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: PWM with oshonsoft pic basic
« Reply #5 on: May 04, 2008, 08:37:00 AM »
That was my problem for too long,too. Oshonsoft doesn't know this, can't do that. Just use 16F877. Best chip around in the 16F family, and Oshonsoft seems to support it. If you will risk yourself (backup, backup, backup), try altering the configuration files for that chip.

However, if you want to use a more powerful, cheaper, and with a free IDE and compiler (not just any compiler, it's a gcc port), just switch to AVR. I've been playing with PICs for long, but when I came over AVRs I just can't drop them from my hands :D
Check out my homepage for in depth tutorials on microcontrollers and electronics.

 


Get Your Ad Here

data_list