|
|
View previous topic :: View next topic |
Author |
Message |
ads
Joined: 09 May 2020 Posts: 11
|
12F1822 PWM problem |
Posted: Sat May 09, 2020 5:00 pm |
|
|
Hi I am having a problem with defining this only :
Code: | #include <12F1822.h>
#fuses NOMCLR INTRC_IO PLL_SW
#use delay(clock=32000000)
#use fast_io(A)
#use pwm (PWM1, FREQUENCY = 38KHz, DUTY = 25, PWM_OFF) |
Which says
***Error 44 "main.c" Line 10(5,52): Internal Error - Contact CCS PPUSE
Line 10 is this line:
Code: | #use pwm (PWM1, FREQUENCY = 38KHz, DUTY = 25, PWM_OFF) |
Does anyone has any idea what should be done to fix this. What is wrong with definition of pwm. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat May 09, 2020 6:00 pm |
|
|
It compiled OK for me. I'm using CCS vs. 5.093.
Quote: |
Compiling C:\...\pcm_test on 09-May-20 at 16:58
More info: PWM period: 26.38 us, Frequency: 37.915 kHz, Resolution: 10.00 bits
Memory usage: ROM=1% RAM=4% - 12%
0 Errors, 0 Warnings.
Build Successful.
Loaded C:\...\pcm_test.cof.
BUILD SUCCEEDED: Sat May 09 16:58:35 2020
|
|
|
|
ads
Joined: 09 May 2020 Posts: 11
|
|
Posted: Sun May 10, 2020 6:12 am |
|
|
PCM programmer wrote: | It compiled OK for me. I'm using CCS vs. 5.093.
Quote: |
Compiling C:\...\pcm_test on 09-May-20 at 16:58
More info: PWM period: 26.38 us, Frequency: 37.915 kHz, Resolution: 10.00 bits
Memory usage: ROM=1% RAM=4% - 12%
0 Errors, 0 Warnings.
Build Successful.
Loaded C:\...\pcm_test.cof.
BUILD SUCCEEDED: Sat May 09 16:58:35 2020
|
|
Then it is because of my compiler. Do you think can I define my own use pwm function. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sun May 10, 2020 6:33 am |
|
|
You should post your compiler version. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 10, 2020 6:58 am |
|
|
ads wrote: | Do you think can I define my own use pwm function ? |
Use the normal method, as shown below. This works with CCS vs. 5.093:
Code: | #include <12F1822.h>
#use delay(internal=4M)
//========================
void main()
{
// This puts PWM on Pin A2.
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 255, 1);
set_pwm1_duty(128); // 50% duty cycle
while(TRUE);
} |
If it doesn't work, then post your CCS compiler version. |
|
|
ads
Joined: 09 May 2020 Posts: 11
|
|
Posted: Sun May 24, 2020 12:30 pm |
|
|
Hi. Sorry for late reply. My compiler version is 5.008 and I found it if I write the code as
Code: | #use pwm (PWM1, FREQUENCY = 38KHz, DUTY = 25) |
(by deleting last command which is PWM_OFF then it compiles. But I don't know if it will work? Do you have any idea the whole code is:
Code: | // Extended NEC protocol IR remote control transmitter CCS C code
#include <12F1822.h>
#fuses NOMCLR INTRC_IO PLL_SW
#use delay(clock=32000000)
#use fast_io(A)
#use pwm (PWM1, FREQUENCY = 38KHz, DUTY = 25, PWM_OFF)
void send_signal(unsigned int32 number){
int8 i;
// Send 9ms burst
pwm_on();
delay_ms(9);
// Send 4.5ms space
pwm_off();
delay_us(4500);
// Send data
for(i = 0; i < 32; i++){
// If bit is 1 send 560us pulse and 1680us space
if(bit_test(number, 31 - i)){
pwm_on();
delay_us(560);
pwm_off();
delay_us(1680);
}
// If bit is 0 send 560us pulse and 560us space
else{
pwm_on();
delay_us(560);
pwm_off();
delay_us(560);
}
}
// Send end bit
pwm_on();
delay_us(560);
pwm_off();
delay_us(560);
}
void main() {
setup_oscillator(OSC_8MHZ | OSC_PLL_ON); // Set internal oscillator to 32MHz (8MHz and PLL)
output_a(0);
set_tris_a(0x3B); // Configure RA2 pin as output and others as inputs
port_a_pullups(0x3B); // Enable internal pull-ups for pins RA0,RA1,RA3,RA4 & RA5
while(TRUE){
while(!input(PIN_A0)){
send_signal(0x40BF00FF);
delay_ms(500);
}
while(!input(PIN_A1)){
send_signal(0x40BF807F);
delay_ms(500);
}
while(!input(PIN_A3)){
send_signal(0x40BF40BF);
delay_ms(500);
}
while(!input(PIN_A4)){
send_signal(0x40BF20DF);
delay_ms(500);
}
while(!input(PIN_A5)){
send_signal(0x40BFA05F);
delay_ms(500);
}
}
} |
from https://simple-circuit.com/ir-remote-control-transmitter-receiver-ccs-c/ |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19505
|
|
Posted: Mon May 25, 2020 2:48 am |
|
|
The only person who can really tell is you. Try it.
However, comments:
Just use the standard format as shown by PCM. This is the older
'traditional' way of controlling the PWM.
For pwm_off, just use:
set_pwm1_duty(0L); // Turn output off
For pwm_on, use:
set_pwm1_duty(52); // On, 25% duty. (for your 38KHz)
Your compiler was at best a 'beta' V5 compiler. I didn't even keep the
compiler versions at this point, since they had so many problems.
However far more of the older V4 commands are likely to work than
the V5 ones. This is why using the older PWM syntax is much more
likely to be successful.
So for close to 38KHz:
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 209, 1);
set_pwm1_duty(0); // pwm_off
This gives 38.095KHz, which if the closest the PWM can actually 'do' from
4MHz. Obviously 'no output', since I am turning the pwm off at this
point. |
|
|
ads
Joined: 09 May 2020 Posts: 11
|
|
Posted: Mon May 25, 2020 5:22 pm |
|
|
Thanks a lot for all your comments. It works with 'traditional' way . |
|
|
Denny9167
Joined: 15 Feb 2021 Posts: 49
|
|
Posted: Mon Mar 08, 2021 8:52 am |
|
|
ads wrote: | Hi. Sorry for late reply. My compiler version is 5.008 and I found it if I write the code as
Code: | #use pwm (PWM1, FREQUENCY = 38KHz, DUTY = 25) |
(by deleting last command which is PWM_OFF then it compiles. But I don't know if it will work? Do you have any idea the whole code is:
Code: | // Extended NEC protocol IR remote control transmitter CCS C code
#include <12F1822.h>
#fuses NOMCLR INTRC_IO PLL_SW
#use delay(clock=32000000)
#use fast_io(A)
#use pwm (PWM1, FREQUENCY = 38KHz, DUTY = 25, PWM_OFF)
void send_signal(unsigned int32 number){
int8 i;
// Send 9ms burst
pwm_on();
delay_ms(9);
// Send 4.5ms space
pwm_off();
delay_us(4500);
// Send data
for(i = 0; i < 32; i++){
// If bit is 1 send 560us pulse and 1680us space
if(bit_test(number, 31 - i)){
pwm_on();
delay_us(560);
pwm_off();
delay_us(1680);
}
// If bit is 0 send 560us pulse and 560us space
else{
pwm_on();
delay_us(560);
pwm_off();
delay_us(560);
}
}
// Send end bit
pwm_on();
delay_us(560);
pwm_off();
delay_us(560);
}
void main() {
setup_oscillator(OSC_8MHZ | OSC_PLL_ON); // Set internal oscillator to 32MHz (8MHz and PLL)
output_a(0);
set_tris_a(0x3B); // Configure RA2 pin as output and others as inputs
port_a_pullups(0x3B); // Enable internal pull-ups for pins RA0,RA1,RA3,RA4 & RA5
while(TRUE){
while(!input(PIN_A0)){
send_signal(0x40BF00FF);
delay_ms(500);
}
while(!input(PIN_A1)){
send_signal(0x40BF807F);
delay_ms(500);
}
while(!input(PIN_A3)){
send_signal(0x40BF40BF);
delay_ms(500);
}
while(!input(PIN_A4)){
send_signal(0x40BF20DF);
delay_ms(500);
}
while(!input(PIN_A5)){
send_signal(0x40BFA05F);
delay_ms(500);
}
}
} |
from https://simple-circuit.com/ir-remote-control-transmitter-receiver-ccs-c/ |
I’m having same problem with code as-is,
It may have worked using an older version of CCS, but not with newest, which I have. I’ll try some of the suggestions quoted here. Thanks
I’m a newby BtW so I’m still learning. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 08, 2021 6:29 pm |
|
|
I tested this in hardware with the code you posted and it's putting out
pulses on pin A2 (pin 5 on the DIP8 PIC package). That's correct.
I tested this on a Microchip Low Pin Count board with a 12F1822 and
CCS vs. 5.103.
To measure the frequency, I modified the main() by adding the two lines
shown in bold below. I got a freq of 37.91 on my scope with 25% duty
cycle. That's correct.
Quote: | void main() {
setup_oscillator(OSC_8MHZ | OSC_PLL_ON);
output_a(0);
set_tris_a(0x3B);
port_a_pullups(0x3B);
pwm_on();
while(TRUE);
|
I don't have an NEC TV to test it with. If you look at his while() loop,
he has buttons on pins A0, A1, A3, A4, A5. These buttons connect ground
to the PIC pins if they are pressed. The pullups are provided by the PIC
as shown in his code above.
You will need this button circuit on each of the 5 pins listed above:
Code: |
___ Pushbutton Switch
To _|_|_
PIC ------o o------
pin |
--- GND
-
|
|
|
|
Denny9167
Joined: 15 Feb 2021 Posts: 49
|
|
Posted: Mon Mar 08, 2021 10:38 pm |
|
|
PCM programmer wrote: | I tested this in hardware with the code you posted and it's putting out
pulses on pin A2 (pin 5 on the DIP8 PIC package). That's correct.
I tested this on a Microchip Low Pin Count board with a 12F1822 and
CCS vs. 5.103.
To measure the frequency, I modified the main() by adding the two lines
shown in bold below. I got a freq of 37.91 on my scope with 25% duty
cycle. That's correct.
Quote: | void main() {
setup_oscillator(OSC_8MHZ | OSC_PLL_ON);
output_a(0);
set_tris_a(0x3B);
port_a_pullups(0x3B);
pwm_on();
while(TRUE);
|
I don't have an NEC TV to test it with. If you look at his while() loop,
he has buttons on pins A0, A1, A3, A4, A5. These buttons connect ground
to the PIC pins if they are pressed. The pullups are provided by the PIC
as shown in his code above.
You will need this button circuit on each of the 5 pins listed above:
Code: |
___ Pushbutton Switch
To _|_|_
PIC ------o o------
pin |
--- GND
-
|
|
Thanks, I followed some of your suggestions, by adding them to the MAIN:
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,209,1);
Got a successful build, 0=errors,0=warnings
I’ll program tomorrow and try it out. I’m also working on the RX as well.
I build audio equipment for a living and I’m wanting to build a remote system for a preamplifier, I thought this would be a good solution. |
|
|
Denny9167
Joined: 15 Feb 2021 Posts: 49
|
|
Posted: Mon Mar 08, 2021 10:42 pm |
|
|
PCM programmer wrote: | I tested this in hardware with the code you posted and it's putting out
pulses on pin A2 (pin 5 on the DIP8 PIC package). That's correct.
I tested this on a Microchip Low Pin Count board with a 12F1822 and
CCS vs. 5.103.
To measure the frequency, I modified the main() by adding the two lines
shown in bold below. I got a freq of 37.91 on my scope with 25% duty
cycle. That's correct.
Quote: | void main() {
setup_oscillator(OSC_8MHZ | OSC_PLL_ON);
output_a(0);
set_tris_a(0x3B);
port_a_pullups(0x3B);
pwm_on();
while(TRUE);
|
I don't have an NEC TV to test it with. If you look at his while() loop,
he has buttons on pins A0, A1, A3, A4, A5. These buttons connect ground
to the PIC pins if they are pressed. The pullups are provided by the PIC
as shown in his code above.
You will need this button circuit on each of the 5 pins listed above:
Code: |
___ Pushbutton Switch
To _|_|_
PIC ------o o------
pin |
--- GND
-
|
|
Do you use the low or high power IR emitters? just curious. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 09, 2021 12:43 am |
|
|
Denny9167 wrote: |
I’m having same problem with code as-is,
It may have worked using an older version of CCS, but not
with newest, which I have.
I followed some of your suggestions, by adding them to the MAIN:
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,209,1);
Got a successful build, 0=errors,0=warnings
|
If you had to add those two lines to get a successful build, then you don't
have the newest version of the compiler, which is vs. 5.103. You can see
the version that you have by looking at the top of the .LST file.
Code: |
CCS PCM C Compiler, Version 5.103, xxxxx 08-Mar-21 22:42
Filename: C:\...\Projects\PCM_Test\PCM_TEST.lst
ROM used: 295 words (14%)
Largest free fragment is 1753
RAM used: 6 (5%) at main() level
23 (18%) worst case
Stack used: 2 locations
Stack size: 16 |
I didn't change anything in the code you posted, and it compiled fine with
vs. 5.103. Here is a link to your post:
http://www.ccsinfo.com/forum/viewtopic.php?t=58717&start=8 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 09, 2021 12:44 am |
|
|
Denny9167 wrote: |
Do you use the low or high power IR emitters? just curious. |
I have not assembled a board. I am just helping you with the code, and
the PWM operation of the PIC. I don't know which IR emitter is best. |
|
|
Denny9167
Joined: 15 Feb 2021 Posts: 49
|
|
Posted: Tue Mar 09, 2021 5:59 am |
|
|
PCM programmer wrote: | Denny9167 wrote: |
Do you use the low or high power IR emitters? just curious. |
I have not assembled a board. I am just helping you with the code, and
the PWM operation of the PIC. I don't know which IR emitter is best. |
Appreciate it very much! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|